home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / QCOM.ZIP / QCOM.DOC < prev    next >
Text File  |  1989-08-23  |  8KB  |  175 lines

  1. {Version 0.2 - Requires Turbo Pascal version 5.5}
  2.  
  3. { Copyright (C) 1989 by Alpac Systems
  4.                         Finn J. R. Nielsen
  5.                         1741 W. Orchid Lane
  6.                         Phoenix, AZ 85021 }
  7.  
  8.  
  9. Unit QCom; Interface uses Dos;
  10.  
  11. Type
  12.  
  13.   String255    = string[255];
  14.   BaudRates    = (B110, B150, B300, B600, B1200, B2400,
  15.                   B4800, B9600, B19200, B38400);
  16.   ParityBit    = (NoParity, Odd, reserved1, Even,
  17.                   reserved2, Mark, reserved3, Space);
  18.   DataBits     = 5..8;
  19.   StopBits     = (One, One_Half, Two);
  20.   ProtocolType = (NoProtocol, XoffProtocol, DsrProtocol);
  21.   CommPortPtr  = ^CommPort;
  22.   TimeOutCmd   = (Continue, Terminate);
  23.   TimeOutHdlr  = Function (Var Msg: string255): TimeOutCmd;
  24.   TimeOutPtr   = ^TimeOutHdlr;
  25.  
  26.   commConfig = record                           { configuration record format }
  27.                  Baud:        BaudRates;
  28.                  Parity:      ParityBit;
  29.                  Bits:        DataBits;
  30.                  Stop:        StopBits;
  31.                  Protocol:    ProtocolType;
  32.                  ReadTime:    word; { read timeout value (0 = no checking)    }
  33.                  EndOfString: char; { char signalling end of input string     }
  34.                  InTreshold,        { Xoff or DTR to suspend when this input
  35.                                       queue treshold is reached               }
  36.                  Resume:      byte; { Xon or DTR resumption at this threshold }
  37.                end; { Thresholds as integer percentages of the queue size     }
  38.  
  39. { -------------------------------------------------------------------------- }
  40. { The CommPort object is here to allow the application to examine data values
  41.   in the object. The application may examine "Count" values to determine if
  42.   any characters are ready in either of the two queues. The "CommFlags" also
  43.   contains useful information about the RS232 line status (see flag
  44.   definitions below). This object is not very extensible since existing
  45.   method definitions are not included in the TPU source. The CommPort object
  46.   is actually a storage compatible facsimile of the actual object used by the
  47.   TPU }
  48.   CommPort = object
  49.                iQueue, oQueue: pointer;   { circular queue pointers    }
  50.                iCount, oCount,            { queue character counts     }
  51.                iTail, oTail,              { queue tail indecies        }
  52.                iHead, oHead,              { queue head indecies        }
  53.                iSize, oSize: word;        { queue space char counts    }
  54.                lowLimit, highLimit: word; { calculated tresholds       }
  55.                DosIntVec: pointer;        { saved DOS interrupt vector }
  56.                CommFlags: byte;           { line status flags          }
  57.                ComPort:   byte;           { port number (1 or 2)       }
  58.                Settings:  commConfig;     { configuration record       }
  59.  
  60.                Constructor Init(inSize, outSize: word; iPort: byte);
  61.                Destructor  Done; virtual;
  62.              end;
  63.  
  64. Const
  65.  
  66.   {bitmasks used to test and set CommFlags in CommPort object}
  67.   sntXoff     = $01;    { Xoff was sent to correspondent      }
  68.   xmitOn      = $02;    { Xmitter on                          }
  69.   RcvXoff     = $04;    { Xoff was received                   }
  70.   Dsr         = $08;    { Data set ready flag                 }
  71.   Carrier     = $10;    { Carrier flag                        }
  72.   LineActive  = $18;    { DSR + Carrier                       }
  73.   ParityErr   = $20;    { Input parity error                  }
  74.   FrameErr    = $40;    { Input framing error                 }
  75.   OvrFlow     = $80;    { Input overflow - receiver or queue  }
  76.   LineErrs    = $E0;    { Parity + framing + overflow         }
  77.   noSntXoff   = $FE;
  78.   xmitOff     = $FD;
  79.   noRcvXoff   = $FB;
  80.   noDsr       = $F7;
  81.   noCarrier   = $EF;
  82.   noLineActive= $E7;
  83.   noParityErr = $DF;
  84.   noFRameErr  = $BF;
  85.   noOvrFlow   = $7F;
  86.   noLineErrs  = $1F;
  87.  
  88. { -------------------------------------------------------------------------- }
  89. { DeflCfg contains the configuration that is automatically installed
  90.   when the CommPort object is initially created. It may also be used
  91.   by the application as a template for modified configuration settings }
  92.   DeflCfg : commConfig = ( Baud:B9600; Parity:NoParity;
  93.                            Bits:8; Stop:One; Protocol:XoffProtocol;
  94.                            ReadTime:0; EndOfString:#13;
  95.                            InTreshold:75; Resume:25 );
  96.  
  97. Var
  98.  
  99.   MaxPorts: byte;       { Maximum number of usable comm ports }
  100.  
  101. { -------------------------------------------------------------------------- }
  102. Function  Connect(Iprt: byte; iqSize, oqSize: word): CommPortPtr;
  103. { This function must be used before any of the other communications
  104.   procedures described below - or else the program will be halted with
  105.   an unflattering error message. Circular queues are allocated from the
  106.   heap. It is the applications responsibility to check if the requested
  107.   space is actually available.
  108.  
  109.   Iprt:         Comm port, usually 1 or 2;
  110.   iqSize:       Input queue size in characters;
  111.   oqSize:       Output queue size in characters;
  112.   CommPortPtr:  Pointer to the dynamically allocated CommPort object;
  113. }
  114.  
  115.  
  116. { -------------------------------------------------------------------------- }
  117. Procedure SetConfig(IprtPtr: CommPortPtr; var Config: commConfig);
  118. { Changes the configuration of the specified port. Although configuration
  119.   information is directly accessible to the application, this information
  120.   should not be changed directly by the application. Instead, a copy of
  121.   the configuration information should be made in the applications memory
  122.   space. The application may then modify the information and change the
  123.   setting for the port by using "SetConfig". A constant "DeflCfg" has been
  124.   defined. It contains the default configuration settings.
  125. }
  126.  
  127.  
  128. { -------------------------------------------------------------------------- }
  129. Procedure PutChar(IprtPtr: CommPortPtr; Ch: char);
  130. { Outputs a single character (control characters are of course legitimate).
  131.  
  132.   IprtPtr:      Comm port, usually 1 or 2;
  133. }
  134.  
  135.  
  136. { -------------------------------------------------------------------------- }
  137. Function  GetChar(IprtPtr: CommPortPtr; TimeOut: TimeOutPtr): char;
  138. { Returns a single character from the input queue. In case of input time-
  139.   out no data was received. Timeout may occur if the read operation cannot
  140.   complete in the time allotted by the value of "ReadTime" in the config-
  141.   uration record (specified in hundredths of a second).
  142.  
  143.   IprtPtr:      Comm port usually 1 or 2;
  144.   TimeOut:      Input timeout handling routine;
  145. }
  146.  
  147.  
  148. { -------------------------------------------------------------------------- }
  149. Procedure PutString(IprtPtr: CommPortPtr; var Msg: string255);
  150. { Outputs a string of 255 characters or less. No characters are added to
  151.   the output message. The caller must add any carriage returns and line
  152.   feeds (or other control characters) required by the application.
  153.  
  154.   IprtPtr:         Comm port usually 1 or 2;
  155. }
  156.  
  157.  
  158. { -------------------------------------------------------------------------- }
  159. Function  GetString(IprtPtr: CommPortPtr; TimeOut: TimeOutPtr): string255;
  160. { Returns a string of 255 characters or less. The string may be terminated
  161.   by the character specified in "EndOfString" in the configuration record,
  162.   if such a character was received. Otherwise, the string will be terminated
  163.   after 255 characters are received. In case of input timeout, any partial
  164.   string received is available to the timeout handler. Timeouts will occur
  165.   if the read operation cannot be finished in the time allotted by the value
  166.   of "ReadTime" in the configuration record. If "ReadTime" is zero or the
  167.   timeout pointer is NIL, no timeouts will occur.
  168.  
  169.   IprtPtr:      Comm port usually 1 or 2;
  170.   TimeOut:      Input timeout handling routine;
  171. }
  172.  
  173. Implementation
  174.  
  175.