home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / util / misc / 018 / transmit.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1992-03-12  |  2.9 KB  |  124 lines

  1. {$B-}    {Boolean complete evaluation off}
  2. {$S-}    {Stack checking off}
  3. {$I-}    {I/O checking off}
  4. {$R-}    {Range checking off}
  5. {$M 4096,8192,8192}
  6.  
  7. program transmit;
  8.  
  9. {  This file transmission package by was written by Peter Summers.
  10.    The program (including source) may be distributed freely, but
  11.    copyright is retained by the Cardiology Department at Royal Melbourne
  12.    Hospital.    }
  13.  
  14. Uses
  15.   Dos,
  16.   Crt,
  17.   Mufasync;
  18.  
  19. const
  20.   default     = -1;
  21.   defportnum  = 1;
  22.   defbaudrate = 9600;
  23.  
  24. var
  25.   portnum,baudrate : word;
  26.   code,time        : integer;
  27.   ch,rcvd          : char;
  28.   infile           : text;
  29.   checking         : boolean;
  30.  
  31. begin
  32.  
  33.   checkbreak:=false;
  34.  
  35.   if paramcount=0 then
  36.     begin
  37.        writeln(^M+^J+'File transmission utility with echo-back error detection.'+^M+^J);
  38.        writeln('TRANSMIT <filename> [<port> [<speed> [nocheck]]]');
  39.        halt(1);
  40.     end
  41.   else
  42.     begin
  43.       assign(infile,paramstr(1));
  44.       reset(infile);
  45.       if IOresult<>0 then
  46.         begin
  47.           writeln(^M+^J+'Error opening file "'+paramstr(1),'".');
  48.           sound(100);
  49.           delay(1000);
  50.           nosound;
  51.           halt(1);
  52.         end;
  53.     end;
  54.  
  55.   if paramcount>1 then
  56.     val(paramstr(2),portnum,code)
  57.   else
  58.     portnum:=defportnum;
  59.  
  60.   Async_Init(default,default,default,default,default);
  61.   Async_Setup_Port(portnum,default,default,default);
  62.  
  63.   if paramcount>2 then
  64.     val(paramstr(3),baudrate,code)
  65.   else
  66.     baudrate:=defbaudrate;
  67.  
  68.   if not(Async_Open(portnum,baudrate,'N',8,1)) then
  69.     begin
  70.       write('Can''t find port number ',portnum,'.');
  71.       halt(1);
  72.     end;
  73.  
  74.   Async_Clear_Errors;
  75.  
  76.   checking:=(paramcount<3) and not
  77.     ((paramstr(4)='NOCHECK') or (paramstr(4)='nocheck'));
  78.  
  79.   while not eof(infile) do
  80.     begin
  81.       read(infile,ch);
  82.       if ord(ch) in [13,32..126] then
  83.         begin
  84.           Async_Send(ch);
  85.           time:=0;
  86.           repeat
  87.             if Async_Receive(rcvd) then
  88.               begin
  89.                 if ord(rcvd) in [10,13,32..126] then write(rcvd);
  90.                 if rcvd<>ch then time:=0;
  91.               end
  92.             else
  93.               begin
  94.                 delay(1);
  95.                 time:=time+1;
  96.               end;
  97.           until (rcvd=ch) or (time=10000);
  98.  
  99.           if keypressed and (readkey=chr(27)) then
  100.             begin
  101.               write(^M+^J+'Escape key pressed, transfer terminated.'+^M+^J);
  102.               close(infile);
  103.               Async_Close(false);
  104.               halt(2);
  105.             end;
  106.  
  107.           if (rcvd<>ch) and checking then
  108.             begin
  109.               write(^M+^J+'Incorrect echo-back, transfer terminated.'+^M+^J);
  110.               sound(100);
  111.               delay(1000);
  112.               nosound;
  113.               close(infile);
  114.               Async_Close(false);
  115.               halt(3);
  116.             end;
  117.  
  118.         end;
  119.     end;
  120.  
  121.   close(infile);
  122.   Async_Close(false);
  123. end.
  124.