home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc2 / dialv23.lzh / COMMLIB.INC next >
Text File  |  1985-09-04  |  7KB  |  266 lines

  1.  
  2. {********* This file is an "include" file to be used with DIAL.PAS. *********}
  3.  
  4.  
  5. Function __CallDOSIO(PortNumber : Byte; Command : __Subfunction;
  6.                      CharOut : Char;  BufferOut : Byte) : Boolean;
  7. {
  8. Do an MS-DOS Communications Driver Interrupt
  9. }
  10. Begin                         {First set up IO Control Packet}
  11.   With __IOCTLPacket Do
  12.     Begin
  13.       Fnction := Ord(Command);
  14.       Buffer := BufferOut;
  15.       Character := CharOut;
  16.     End;
  17.   With Regs Do
  18.     Begin
  19.       AH := $44;
  20.       AL := $02;
  21.       BX := PortNumber;
  22.       DS := Seg(__IOCTLPacket);
  23.       DX := Ofs(__IOCTLPacket);
  24.     End;
  25.   Intr($21,Regs);
  26.   If __IOCTLPacket.Func_retC = Successful
  27.     Then __CallDOSIO := True               {This returns whether or}
  28.       Else __CallDOSIO := False;           {not the function was}
  29.  End; {__CallDOSIO}
  30.  
  31.  
  32. Function SetSerial(PortNumber : Byte; BaudRate : Integer;
  33.                    StopBitsIn : Real; DataBitsIn : DataBitsType;
  34.                    ParityIn : ParityType; CharOut : Char) : Boolean;
  35. {
  36. Set serial parameters for a COM port
  37. }
  38. Begin
  39.   With Regs Do
  40.     Begin
  41.       AH := $44;
  42.       AL := 2;
  43.       BX := PortNumber;
  44.       DS := Seg(__SetSerialIO);
  45.       DX := Ofs(__SetSerialIO);
  46.     End;
  47.   __SetSerialIO.Fnction := Ord(ProgramDev);
  48.   __SetSerialIO.Buffer  := 1;
  49.   With __CCB Do
  50.     Begin
  51.       ModemCtrl := 1;
  52.       If StopBitsIn = 2 Then StopBits := 3
  53.         Else If StopBitsIn = 1.5 Then StopBits := 2
  54.                Else If StopBitsIn = 1 Then StopBits := 1
  55.                       Else StopBits := 0;
  56.       DataBits := Ord(DataBitsIn);
  57.       Parity := Ord(ParityIn);
  58.       Case BaudRate of
  59.         110:  RCVBaud := 3;
  60.         150:  RCVBaud := 5;
  61.         300:  RCVBaud := 7;
  62.         600:  RCVBaud := 8;
  63.         1200: RCVBaud := 9;
  64.         2400: RCVBaud := 12;
  65.         4800: RCVBaud := 14;
  66.         else RCVBaud := 16;      {Default to 9600 Baud}
  67.       End;                       {Case of baud rate}
  68.       XMTBaud  := RCVBaud;       {Transmit and Receive Rates are same}
  69.       XONChar  := 17;            {^Q}
  70.       XOFFChar := 19;            {^S}
  71.       RCVXON   := 2;             {Always set auto XON/XOFF on}
  72.       XMTXON   := 2;             {The manual says this will turn XON/XOFF}
  73.                                  {off.  It's wrong.  Try it if you want. }
  74.       AltBufSize := 512;         {Set up 512 byte buffer}
  75.       BuffAddrOffset := Ofs(__Buffer1);
  76.       BuffAddrSeg    := Seg(__Buffer1);
  77.     end;
  78.   Intr($21,Regs);
  79.   If __SetSerialIO.Func_retC = Successful
  80.     Then SetSerial := True
  81.       Else SetSerial := False;
  82. End; {SetSerial}
  83.  
  84.  
  85. Function ReadCurrentCommSettings : Boolean;
  86. {
  87. Read the current Comm Setup values
  88. }
  89. Begin
  90.   With Regs Do
  91.     Begin
  92.       AH := $44;
  93.       AL := 2;
  94.       BX := 3;
  95.       DS := Seg(__SetSerialIO);
  96.       DX := Ofs(__SetSerialIO);
  97.     end;
  98.   __SetSerialIO.Fnction := Ord(ReadDevSetup);
  99.   __SetSerialIO.Buffer  := 1;
  100.   Intr($21,Regs);
  101.   If __SetSerialIO.Func_retC = Successful Then
  102.     Begin
  103.       ReadCurrentCommSettings := True;
  104.       Case __CCB.RCVBaud Of
  105.         3: DefaultBaud := 110;
  106.         5: DefaultBaud := 150;
  107.         7: DefaultBaud := 300;
  108.         8: DefaultBaud := 600;
  109.         9: DefaultBaud := 1200;
  110.         12: DefaultBaud := 2400;
  111.         14: DefaultBaud := 4800;
  112.         16: DefaultBaud := 9600;
  113.       End; {Case of __CCB.RCVBaud}
  114.       DefaultDataBits := DataBitsType(__CCB.DataBits);
  115.       DefaultParity := ParityType(__CCB.Parity);
  116.       Case __CCB.StopBits Of
  117.         3: DefaultStopBits := 2;
  118.         2: DefaultStopBits := 1.5;
  119.         1: DefaultStopBits := 1;
  120.         0: DefaultStopBits := 0;
  121.       End; {Case statement}
  122.     End {if successful}
  123.   Else
  124.     ReadCurrentCommSettings := False;
  125. End; {Function ReadCurrentCommSettings}
  126.  
  127.  
  128. Function ReplaceDefault : Boolean;
  129. {
  130. Replace current comm settings with default values
  131. }
  132. Var
  133.   TempStatus : Boolean;
  134. Begin
  135.   {Disable Receiver Interrupts}
  136.   TempStatus := __CallDOSIO(3, DisableRecvIntr, Chr(0), 1);
  137.   {Next, Set device to use default buffer}
  138.   TempStatus := TempStatus And __CallDOSIO(3, SetDefBuf, Chr(0), 1);
  139.   {Last, program comm to default settings}
  140.   TempStatus := TempStatus And __CallDOSIO(3, ProgramDefault, Chr(0), 1);
  141.   {Now save final status}
  142.   ReplaceDefault := TempStatus;
  143. End; {ReplaceDefault}
  144.  
  145.  
  146. Function DisconnectModem : Boolean;
  147. {
  148. Turn off DSR modem signal and reset it
  149. }
  150. Begin
  151.   Port[2] := 4;
  152.   Delay(1000);
  153.   Port[2] := 138;
  154.   Delay(1500);
  155.   DisconnectModem := __CallDOSIO(3, SetModem, Chr(0), 1);
  156. End; {Function DisconnectModem}
  157.  
  158.  
  159. Function CheckInputStatus : Boolean;
  160. {
  161. Check the Input line Status of the comm port
  162. }
  163. Begin
  164.   CheckInputStatus := __CallDOSIO(3, ReadInStat, Chr(0), 1);
  165. End; {CheckInputStatus}
  166.  
  167.  
  168. Function ReadCommChar : Boolean;
  169. {
  170. Read a character in from the comm port
  171. }
  172. Begin
  173.   ReadCommChar := __CallDOSIO(3, ReadChar, Chr(0), 1);
  174.   {If any character is returned, save it and any data errors}
  175.   With CommIn Do
  176.     Begin
  177.       Char := __IOCTLPacket.Character;
  178.       Error := __IOCTLPacket.Char_Stat;
  179.       {I ignore the error byte.  If Error > 0 => an error occurred}
  180.     End;
  181. End; {ReadCommChar}
  182.                               
  183.  
  184. Procedure GetCommChar;
  185. {
  186. Go for a character from the comm port, don't come back til you get it .  This
  187. procedure is dangerous, just because it can wait forever for a character to
  188. come in.
  189. }
  190. Begin
  191.   DummyLogical := __CallDOSIO(3,GetChar, Chr(0), 1);
  192.   {When character is returned, save it and any data errors}
  193.   With CommIn Do
  194.     Begin
  195.       Char := __IOCTLPacket.Character;
  196.       Error := __IOCTLPacket.Char_Stat;
  197.     End;
  198. End;
  199.  
  200.  
  201. Function CheckOutputStatus : Boolean;
  202. {
  203. Check whether it's ok to send a character out the comm port
  204. }
  205. Begin
  206.   CheckOutputStatus := __CallDOSIO(3, ReadOutStat, Chr(0), 1);
  207. End; {Function CheckOutputStatus}
  208.  
  209.  
  210. Function WriteCommChar(OutChar : Char) : Boolean;
  211. {
  212. Write a char out the comm port
  213. }
  214. Begin
  215.   WriteCommChar := __CallDOSIO(3, WriteChar, OutChar, 1);
  216. End;  {Function WriteCommChar}
  217.  
  218.  
  219. Procedure WriteCommString(InString: STRINGLONG);
  220. {
  221. Send a string of characters out the comm port
  222. }
  223. Var
  224.   Counter : Byte;
  225. Begin
  226.   For Counter := 1 to Length(InString) Do
  227.     Begin
  228.       DummyLogical := WriteCommChar(InString[Counter]);
  229.       {Pause until you can send the next character out}
  230.       While Not CheckOutputStatus Do Delay(1);
  231.     End;  {Sending input keystroke}
  232. End; {Procedure WriteCommString}
  233.  
  234.  
  235. Function SendBreak : Boolean;
  236. {
  237. Send a break character out the comm port for standardized length of time
  238. }
  239. Var
  240.   TempStatus : Boolean;
  241. Begin
  242.   TempStatus :=  __CallDOSIO(3, XMTBreak, Chr(0), 1);
  243.   Delay(250);
  244.   TempStatus := TempStatus And __CallDOSIO(3, StopBreak, Chr(0), 1);
  245.   {Save total status}
  246.   SendBreak := TempStatus;
  247. End; {SendBreak}
  248.  
  249.  
  250. Function InitPort : Boolean;
  251. {
  252. Initialize communications port with default values
  253. }
  254. Var
  255.   TempStatus : Boolean;
  256. Begin
  257.   {First, we'll program the device with our default values.}
  258.   TempStatus := SetSerial(3,2400,1,DB7S,none,Chr(0));
  259.   {Next, Enable Receiver Interrupts}
  260.   TempStatus := TempStatus And __CallDOSIO(3,EnableRecvIntr,Chr(0),1);
  261.   {Now, we'll tell it to set up the modem port for DTR, RTS & SRTS}
  262.   TempStatus := TempStatus And __CallDOSIO(3,SetModem,Chr(14),1);
  263.   {Save total status}
  264.   InitPort := TempStatus;
  265. End; {InitPort}
  266.