home *** CD-ROM | disk | FTP | other *** search
- {Version 0.2 - Requires Turbo Pascal version 5.5}
-
- { Copyright (C) 1989 by Alpac Systems
- Finn J. R. Nielsen
- 1741 W. Orchid Lane
- Phoenix, AZ 85021 }
-
-
- Unit QCom; Interface uses Dos;
-
- Type
-
- String255 = string[255];
- BaudRates = (B110, B150, B300, B600, B1200, B2400,
- B4800, B9600, B19200, B38400);
- ParityBit = (NoParity, Odd, reserved1, Even,
- reserved2, Mark, reserved3, Space);
- DataBits = 5..8;
- StopBits = (One, One_Half, Two);
- ProtocolType = (NoProtocol, XoffProtocol, DsrProtocol);
- CommPortPtr = ^CommPort;
- TimeOutCmd = (Continue, Terminate);
- TimeOutHdlr = Function (Var Msg: string255): TimeOutCmd;
- TimeOutPtr = ^TimeOutHdlr;
-
- commConfig = record { configuration record format }
- Baud: BaudRates;
- Parity: ParityBit;
- Bits: DataBits;
- Stop: StopBits;
- Protocol: ProtocolType;
- ReadTime: word; { read timeout value (0 = no checking) }
- EndOfString: char; { char signalling end of input string }
- InTreshold, { Xoff or DTR to suspend when this input
- queue treshold is reached }
- Resume: byte; { Xon or DTR resumption at this threshold }
- end; { Thresholds as integer percentages of the queue size }
-
- { -------------------------------------------------------------------------- }
- { The CommPort object is here to allow the application to examine data values
- in the object. The application may examine "Count" values to determine if
- any characters are ready in either of the two queues. The "CommFlags" also
- contains useful information about the RS232 line status (see flag
- definitions below). This object is not very extensible since existing
- method definitions are not included in the TPU source. The CommPort object
- is actually a storage compatible facsimile of the actual object used by the
- TPU }
- CommPort = object
- iQueue, oQueue: pointer; { circular queue pointers }
- iCount, oCount, { queue character counts }
- iTail, oTail, { queue tail indecies }
- iHead, oHead, { queue head indecies }
- iSize, oSize: word; { queue space char counts }
- lowLimit, highLimit: word; { calculated tresholds }
- DosIntVec: pointer; { saved DOS interrupt vector }
- CommFlags: byte; { line status flags }
- ComPort: byte; { port number (1 or 2) }
- Settings: commConfig; { configuration record }
-
- Constructor Init(inSize, outSize: word; iPort: byte);
- Destructor Done; virtual;
- end;
-
- Const
-
- {bitmasks used to test and set CommFlags in CommPort object}
- sntXoff = $01; { Xoff was sent to correspondent }
- xmitOn = $02; { Xmitter on }
- RcvXoff = $04; { Xoff was received }
- Dsr = $08; { Data set ready flag }
- Carrier = $10; { Carrier flag }
- LineActive = $18; { DSR + Carrier }
- ParityErr = $20; { Input parity error }
- FrameErr = $40; { Input framing error }
- OvrFlow = $80; { Input overflow - receiver or queue }
- LineErrs = $E0; { Parity + framing + overflow }
- noSntXoff = $FE;
- xmitOff = $FD;
- noRcvXoff = $FB;
- noDsr = $F7;
- noCarrier = $EF;
- noLineActive= $E7;
- noParityErr = $DF;
- noFRameErr = $BF;
- noOvrFlow = $7F;
- noLineErrs = $1F;
-
- { -------------------------------------------------------------------------- }
- { DeflCfg contains the configuration that is automatically installed
- when the CommPort object is initially created. It may also be used
- by the application as a template for modified configuration settings }
- DeflCfg : commConfig = ( Baud:B9600; Parity:NoParity;
- Bits:8; Stop:One; Protocol:XoffProtocol;
- ReadTime:0; EndOfString:#13;
- InTreshold:75; Resume:25 );
-
- Var
-
- MaxPorts: byte; { Maximum number of usable comm ports }
-
- { -------------------------------------------------------------------------- }
- Function Connect(Iprt: byte; iqSize, oqSize: word): CommPortPtr;
- { This function must be used before any of the other communications
- procedures described below - or else the program will be halted with
- an unflattering error message. Circular queues are allocated from the
- heap. It is the applications responsibility to check if the requested
- space is actually available.
-
- Iprt: Comm port, usually 1 or 2;
- iqSize: Input queue size in characters;
- oqSize: Output queue size in characters;
- CommPortPtr: Pointer to the dynamically allocated CommPort object;
- }
-
-
- { -------------------------------------------------------------------------- }
- Procedure SetConfig(IprtPtr: CommPortPtr; var Config: commConfig);
- { Changes the configuration of the specified port. Although configuration
- information is directly accessible to the application, this information
- should not be changed directly by the application. Instead, a copy of
- the configuration information should be made in the applications memory
- space. The application may then modify the information and change the
- setting for the port by using "SetConfig". A constant "DeflCfg" has been
- defined. It contains the default configuration settings.
- }
-
-
- { -------------------------------------------------------------------------- }
- Procedure PutChar(IprtPtr: CommPortPtr; Ch: char);
- { Outputs a single character (control characters are of course legitimate).
-
- IprtPtr: Comm port, usually 1 or 2;
- }
-
-
- { -------------------------------------------------------------------------- }
- Function GetChar(IprtPtr: CommPortPtr; TimeOut: TimeOutPtr): char;
- { Returns a single character from the input queue. In case of input time-
- out no data was received. Timeout may occur if the read operation cannot
- complete in the time allotted by the value of "ReadTime" in the config-
- uration record (specified in hundredths of a second).
-
- IprtPtr: Comm port usually 1 or 2;
- TimeOut: Input timeout handling routine;
- }
-
-
- { -------------------------------------------------------------------------- }
- Procedure PutString(IprtPtr: CommPortPtr; var Msg: string255);
- { Outputs a string of 255 characters or less. No characters are added to
- the output message. The caller must add any carriage returns and line
- feeds (or other control characters) required by the application.
-
- IprtPtr: Comm port usually 1 or 2;
- }
-
-
- { -------------------------------------------------------------------------- }
- Function GetString(IprtPtr: CommPortPtr; TimeOut: TimeOutPtr): string255;
- { Returns a string of 255 characters or less. The string may be terminated
- by the character specified in "EndOfString" in the configuration record,
- if such a character was received. Otherwise, the string will be terminated
- after 255 characters are received. In case of input timeout, any partial
- string received is available to the timeout handler. Timeouts will occur
- if the read operation cannot be finished in the time allotted by the value
- of "ReadTime" in the configuration record. If "ReadTime" is zero or the
- timeout pointer is NIL, no timeouts will occur.
-
- IprtPtr: Comm port usually 1 or 2;
- TimeOut: Input timeout handling routine;
- }
-
- Implementation
-