Class TMSComm (unit MSComm) |
Inherits from
TComponent
This is the TMSComm object
constructor Create(AOwner: TComponent);
- DoTransmit} { construct: create invisible message window, set default values
procedure Close;
Open} { closes the comm port, if it is open.
destructor Destroy;
Create} { destructor: close invisible message window, close comm port
procedure FlushRX;
Close} { Empty the RX Queue
procedure FlushTX;
FlushRX} { Empty the TX Queue
function GetError: String;
ParseGenErr} { returns error text (if any) and clears it
function Open: Boolean;
GetError} { Explicitly open port.
procedure Read(Data: PChar; Len: Word);
Write} { Read data from comm port.
procedure Write(Data: PChar; Len: Word);
Destroy} { Write data to comm port.
procedure DoEvent;
WndProc} { some comm event occured.
procedure DoReceive;
DoEvent} { we rec'd some data, see if receive event is on and fire
procedure DoTransmit;
DoReceive} { This event will fire when the transmit buffer goes BELOW the point set
in txLowCount.
function parseGenErr(var Stat : TComStat): String;
parseOpenErr} { failure to read or write to comm port results in a negative returned
value.
function parseOpenErr(Errcode: Integer): String;
Read} { failure to open results in a negative cId, this will translate the
negative cId value into an explanation.
procedure SetBaudRate(Value: TBaudRate);
Set baud rate: 110-256,000.
procedure SetDataBits(Value: TDataBits);
SetParityBits} { set # of data bits 4-8
procedure SetEvents(Value: TCommEvents);
SetTxLow} { Build the event mask.
procedure SetFlowControl(Value: TFlowControl);
SetStopBits} { Set flow control: None, RTS/CTS, or Xon/Xoff.
procedure SetParityBits(Value: TParityBits);
SetBaudRate} { set parity: none, odd, even, mark, space
procedure SetRxFull(Value: Word);
SetFlowControl} { RxFull indicates the number of bytes the COM driver must write to the
application's input queue before sending a notification message.
procedure SetStopBits(Value: TStopBits);
SetDataBits} { set number of stop bits 1, 1.
procedure SetTxLow(Value: Word);
SetRxFull} { TxLow Indicates the minimum number of bytes in the output queue.
procedure WndProc(var Msg: TMessage);
SetEvents} { This is the message handler for the invisible window; it handles comm msgs
that are handed to the invisible window.
property BaudRate : TBaudRate
property DataBits : TDataBits
property Events : TCommEvents
property FlowControl : TFlowControl
property ParityBits : TParityBits
property Port : Byte
property RxBufSize : Word
property RxFullCount : Word
property StopBits : TStopBits
property TxBufSize : Word
property TxLowCount : Word
property TxTimeout : Word
property Version : Single
event OnCommEvent : TNotifyCommEventEvent
event OnError : TNotifyErrorEvent
event OnReceive : TNotifyReceiveEvent
event OnTransmitLow : TNotifyTransmitLowEvent
cId : Integer;
Error : String;
handle to comm port
FBaudRate : TBaudRate;
FDataBits : TDataBits;
FEvents : TCommEvents;
FFlowControl : TFlowControl;
FhWnd : hWnd;
FOnCommEvent : TNotifyCommEventEvent;
FOnError : TNotifyErrorEvent;
FOnReceive : TNotifyReceiveEvent;
FOnTransmitLow : TNotifyTransmitLowEvent;
FParityBits : TParityBits;
FPort : Byte;
FRxBufSize : Word;
FRxFull : Word;
FStopBits : TStopBits;
FTxBufSize : Word;
FTxLow : Word;
FTxTimeout : Word;
FVersion : Single;
constructor Create(AOwner: TComponent);
DoTransmit} { construct: create invisible message window, set default values
procedure Close;
Open} { closes the comm port, if it is open.
destructor Destroy;
Create} { destructor: close invisible message window, close comm port
procedure FlushRX;
Close} { Empty the RX Queue
procedure FlushTX;
FlushRX} { Empty the TX Queue
function GetError: String;
ParseGenErr} { returns error text (if any) and clears it
function Open: Boolean;
GetError} { Explicitly open port. Returns success/failure, check error property for details.
This routine also begins hooking the comm messages to our invisible window we
created upon instantiation. Will close port (if open) before re-opening.
procedure Read(Data: PChar; Len: Word);
Write} { Read data from comm port. Should only do read when you've been notified you
have data. Attempting to read when nothing is in read buffer results
in spurious error. You can never read a larger chunk than the read buffer
size. NOTE: theoretically, you should check the Error property for errors
after every read. Any error during read or write can stop flow of data.
procedure Write(Data: PChar; Len: Word);
Destroy} { Write data to comm port.
procedure DoEvent;
WndProc} { some comm event occured. see if we need to report it as an event based
on the FOnEvent flags set in the control.
procedure DoReceive;
DoEvent} { we rec'd some data, see if receive event is on and fire
procedure DoTransmit;
DoReceive} { This event will fire when the transmit buffer goes BELOW the point set
in txLowCount. It will NOT fire when a transmission takes place.
function parseGenErr(var Stat : TComStat): String;
parseOpenErr} { failure to read or write to comm port results in a negative returned
value. This will translate the value into an explanation.
function parseOpenErr(Errcode: Integer): String;
Read} { failure to open results in a negative cId, this will translate the
negative cId value into an explanation.
procedure SetBaudRate(Value: TBaudRate);
Set baud rate: 110-256,000. Notice that this will change the baud rate of the port
immediately-- if it is currently open! This goes for most of the other com port
settings below as well.
procedure SetDataBits(Value: TDataBits);
SetParityBits} { set # of data bits 4-8
procedure SetEvents(Value: TCommEvents);
SetTxLow} { Build the event mask. Indicates which misc events we want the comm control to
tell us about.
procedure SetFlowControl(Value: TFlowControl);
SetStopBits} { Set flow control: None, RTS/CTS, or Xon/Xoff. Flow control works in conjunction
with the read and write buffers to ensure that the flow of data *will* stop if
the buffers get critically full. If there is no flow control, it's possible
to lose data.. with flow control on, the chance for losing data is much lower.
Standard (16450 and 16550) UARTs do not implement flow control in hardware, so
if the processor doesn't service the interrupt and halt the flow, data will be
lost anyway. (I've heard rumors of a 16650 UART that works correctly, but I
haven't seen one yet.)
procedure SetParityBits(Value: TParityBits);
SetBaudRate} { set parity: none, odd, even, mark, space
procedure SetRxFull(Value: Word);
SetFlowControl} { RxFull indicates the number of bytes the COM driver must write to the
application's input queue before sending a notification message. The message
signals the application to read information from the input queue. This "forces"
the driver to send notification during periods of data "streaming." It will
stop what it's doing and notify you when it gets at least this many chars.
This will only affect data streaming; normally data is sent during lulls in
the "stream." If there are no lulls, this setting comes into effect. The
event OnReceive fires when ANY amount of data is received. The maximum
chunk of data you will receive is set by the RxFull amount.
procedure SetStopBits(Value: TStopBits);
SetDataBits} { set number of stop bits 1, 1.5 or 2
procedure SetTxLow(Value: Word);
SetRxFull} { TxLow Indicates the minimum number of bytes in the output queue. When the
number of bytes in the output queue falls below this number, the COM driver
sends the application a notification message, signaling it to write information
to the output queue. This can be handy to avoid overflowing the (outgoing)
read buffer. The event OnTransmitLow fires when this happens.
procedure WndProc(var Msg: TMessage);
SetEvents} { This is the message handler for the invisible window; it handles comm msgs
that are handed to the invisible window. We hook into these messages using
EnableCommNotification and our invisible window handle. This routine hands
off to the "do(x)" routines below.
property BaudRate : TBaudRate
property DataBits : TDataBits
property Events : TCommEvents
property FlowControl : TFlowControl
property ParityBits : TParityBits
property Port : Byte
property RxBufSize : Word
property RxFullCount : Word
property StopBits : TStopBits
property TxBufSize : Word
property TxLowCount : Word
property TxTimeout : Word
property Version : Single
event OnCommEvent : TNotifyCommEventEvent
event OnError : TNotifyErrorEvent
event OnReceive : TNotifyReceiveEvent
event OnTransmitLow : TNotifyTransmitLowEvent
cId : Integer;
Error : String;
handle to comm port
FBaudRate : TBaudRate;
FDataBits : TDataBits;
FEvents : TCommEvents;
FFlowControl : TFlowControl;
FhWnd : hWnd;
FOnCommEvent : TNotifyCommEventEvent;
FOnError : TNotifyErrorEvent;
FOnReceive : TNotifyReceiveEvent;
FOnTransmitLow : TNotifyTransmitLowEvent;
FParityBits : TParityBits;
FPort : Byte;
FRxBufSize : Word;
FRxFull : Word;
FStopBits : TStopBits;
FTxBufSize : Word;
FTxLow : Word;
FTxTimeout : Word;
FVersion : Single;