home *** CD-ROM | disk | FTP | other *** search
/ Computerworld 1996 March / Computerworld_1996-03_cd.bin / idg_cd3 / aplikace / komunika / odywin2 / ody2wevj.lzh / TESTFAX.SCR < prev    next >
Encoding:
Text File  |  1995-01-22  |  7.5 KB  |  217 lines

  1.  
  2. SCRIPT TestFAX; (* demonstrate script access to FAX server *)
  3.  
  4. VAR fax_server : Number;
  5.     NumberToDial : String;
  6.  
  7. (*.................................................*)
  8.  
  9. FUNC SendLiteralMessage(hDLL:Number; msg,cmd:String; num:Number):Number;
  10. BEGIN
  11.      RETURN SendMessage(fax_server,msg,cmd,num);
  12. END;
  13.  
  14. (*.................................................*)
  15.  
  16. PROC test1();
  17.  /* demonstrates changing one of the FAX server variables. SAVE-SETTINGS
  18.     makes the change permanent, otherwise it would be lost when you send
  19.     the END-SESSION message.
  20.  */
  21. BEGIN
  22.      SendLiteralMessage(fax_server,"SET-OREF","my reference",0);
  23.      SendLiteralMessage(fax_server,"SAVE-SETTINGS","",0);
  24. END;
  25.  
  26. (*.................................................*)
  27.  
  28. PROC test2(cover_sheet:Flag; Fn:String; Phone:String);
  29.  /* demonstrates actually sending a FAX.
  30.  */
  31. VAR imported_name:String;
  32.     rslt:Number;
  33.  
  34. BEGIN
  35.      /* the source file must be converted to FAX image first. This isn't
  36.       * done transparantly by SEND because conversion is a relatively
  37.       * slow task, and if you want to send the same FAX to multiple
  38.       * destinations a lot of time can be saved doing it this way.
  39.       * The IMPORT message takes care of the conversion.
  40.       */
  41.  
  42.      /* SET-DETAIL and SET-REFORMAT control variables used in the conversion
  43.       * process, so these messages must be sent before using the IMPORT
  44.       * command, if you don't want to use the options set up in the FAX
  45.       * server menu.
  46.       */
  47.      /* assume normal resolution FAX */
  48.      SendLiteralMessage(fax_server, "SET-DETAIL", "", 0);
  49.      /* assume no text reformatting */
  50.      SendLiteralMessage(fax_server, "SET-REFORMAT", "", 0);
  51.  
  52.      imported_name := Fn;
  53.      IF SendMessage(fax_server, "IMPORT", imported_name, 0)<>0 THEN
  54.          /* note that IMPORT returns the name of the newly created FAX
  55.           * file in the string argument of the message.
  56.           */
  57.          RETURN;
  58.      END;
  59.  
  60.      /* tell the FAX server which file to send, and which number to dial. */
  61.      SendMessage(fax_server, "SET-FILETOSEND", imported_name, 0);
  62.      SendMessage(fax_server, "SET-NUMBER", Phone, 0);
  63.  
  64.      /* Ok, now that the FAX conversion is done, do we want to include
  65.       * a cover sheet? Supply the FAX server with the details if so.
  66.       */
  67.      IF cover_sheet THEN /* if the user wants a cover sheet added */
  68.          /* in real life, you could read cover sheet info from a file */
  69.          SendLiteralMessage(fax_server, "SET-COVERSHEET", "", 1);
  70.          SendLiteralMessage(fax_server, "SET-FROM", "me", 0);
  71.          SendLiteralMessage(fax_server, "SET-TO",   "your company", 0);
  72.          SendLiteralMessage(fax_server, "SET-ATTN", "you", 0);
  73.          SendLiteralMessage(fax_server, "SET-OREF", "our reference", 0);
  74.          SendLiteralMessage(fax_server, "SET-YREF", "your reference", 0);
  75.          SendLiteralMessage(fax_server, "SET-SUBJECT", "testing the FAX server!", 0);
  76.        ELSE
  77.          /* tell FAX server to disable cover sheet generation. */
  78.          SendLiteralMessage(fax_server, "SET-COVERSHEET", "", 0);
  79.      END;
  80.  
  81.      /* Ok, we've converted the input file to FAX format, we've generated
  82.       * the cover sheet... anything left to do?  Ah yes - better send the
  83.       * FAX!
  84.       */
  85.      rslt := SendLiteralMessage(fax_server, "SEND", "", 0);
  86.  
  87.      IF rslt=0 THEN
  88.          Write("FAX was sent OK.|");
  89.        ELSE
  90.          Write("FAX server reported error ",rslt,".|");
  91.      END;
  92. END;
  93.  
  94. (*.................................................*)
  95.  
  96. PROC test3(fax_name:String);
  97.  /* demonstrates printing a received FAX.
  98.  */
  99. BEGIN
  100.      /* print pages 1-99 */
  101.      SendLiteralMessage(fax_server, "PRINT", fax_name+" 1-99", 0);
  102. END;
  103.  
  104. (*.................................................*)
  105.  
  106. PROC test4();
  107.  /* demonstrates receiving a FAX.
  108.  */
  109. VAR ring:Number;
  110.     fax_name:String;
  111.     rslt:Number;
  112.     Done:Flag;
  113.  
  114. BEGIN
  115.      /* It is up to the receiving script to recognise when there might be
  116.       * an incoming call. It is NOT normal for you to enable auto-answer
  117.       * mode to handle this. Instead you should look for the "RING"
  118.       * response sent by Hayes compatible modems. Normally you would use
  119.       * the script WatchFor() feature for that, polling Received()
  120.       * for it throughout your script. For the purpose of this demo
  121.       * it is all handled here in a tight loop.
  122.       */
  123.  
  124.      Done := FALSE;
  125.      Write("Waiting for a call...");
  126.      ring := WatchFor("RING");
  127.      REPEAT
  128.            IF Received(ring) THEN
  129.                Write("|");
  130.                /* ok, phone is ringing - better answer it! */
  131.                rslt := SendMessage(fax_server, "RECEIVE", fax_name, 0);
  132.                Done := TRUE;
  133.                WatchAgain(ring); /* reset received flag */
  134.            END;
  135.      UNTIL Done; /* this demo stops after receiving one FAX. */
  136.  
  137.      ClrWatch(ring); /* for the demo, we won't need this WatchFor again. */
  138.  
  139.      /* if a fax is received, its name will have been placed in the
  140.       * "fax_name" string argument to the RECEIVE message. If the FAX is
  141.       * ok then why not print it now?
  142.       */
  143.      IF rslt=0 THEN /* if FAX ok */
  144.          Write("FAX ",fax_name," received OK.|");
  145.          test3(fax_name); /* print fax */
  146.        ELSE
  147.          Write("FAX receive error ",rslt,".|");
  148.      END;
  149. END;
  150.  
  151. (*.................................................*)
  152.  
  153. PROC test5(fax_name,img_name:String);
  154.  /* demonstrates exporting a FAX to TIFF or PCX format. The output format
  155.   * is controlled by the extension used in img_name (ie. .PCX for PCX
  156.   * files, .TIF for TIFF files).
  157.   */
  158. BEGIN
  159.      /* export pages 1-99 */
  160.      SendLiteralMessage(fax_server, "EXPORT",
  161.         fax_name+" "+img_name+" 1-99",
  162.         0);
  163. END;
  164.  
  165. (*.................................................*)
  166.  
  167. BEGIN
  168.      /* the FAX Server .DLL is the biggest Odyssey DLL so far, so in order
  169.       * to give it plenty of room you should unload any fancy terminal
  170.       * emulations etc. You don't need them for FAXing anyway.
  171.       */
  172.      Emulate("TTY");      /* load the simplest terminal possible */
  173.  
  174.      /* Now load the FAX server DLL - if it exists!
  175.       */
  176.      fax_server := LoadDLL("FAXSERV.DLL");
  177.      IF fax_server<16 THEN
  178.          Write("Could not find FAXSERV.DLL in the Odyssey directory!|");
  179.          Write("Error code was: ",fax_server,"|");
  180.        ELSE
  181.          SendLiteralMessage(fax_server,"INIT","",0); (* always do this *)
  182.  
  183.          /* uncomment one of the tests below */
  184.  
  185.          /*
  186.          Test1(); /* setting a FAX server variable */
  187.          */
  188.  
  189.          NumberToDial := "0123-456789";
  190.          IF NumberToDial="0123-456789" THEN
  191.              (* user hasn't modified the phone number *)
  192.              Write("|The TESTFAX script has a statement on line 189 which sets the FAX number|");
  193.              Write("to dial for this test. Please modify that line before trying this script|");
  194.              Write("again.||");
  195.            ELSE
  196.              Test2(TRUE, "testfax.scr", NumberToDial); /* sending a fax */
  197.          END;
  198.  
  199.          /*
  200.          Test3("faxrecv\test.fax"); /* printing a FAX */
  201.          */
  202.  
  203.          /*
  204.          Test4(); /* receive a fax */
  205.          */
  206.  
  207.          /*
  208.          Test5("faxrecv\test.fax","test.tif"); /* export to .TIF */
  209.          Test5("faxrecv\test.fax","test.pcx"); /*   .....or .PCX */
  210.          */
  211.  
  212.          SendLiteralMessage(fax_server,"END-SESSION","",0); (* always do this *)
  213.          fax_server := UnLoadDLL(fax_server); (* and this too *)
  214.      END;
  215. END;
  216.  
  217.