| Class TCommPortDriver (unit ComDrv32) |
TComponent
| Constructors |
constructor Create( AOwner: TComponent );+-------------------------------------------------------------------------+ | TCOMMPORTDRIVER | +-------------------------------------------------------------------------+
| Functions |
function Connect: boolean;
function Connected: boolean;Returns true if connected
procedure ContinuePolling;Re-starts polling (after pause)
function CountRX: integer;Returns number of received bytes in the RX buffer
destructor Destroy;Allocate a window handle to catch timer's notification messages
procedure Disconnect;Start the timer (used for polling)
procedure FlushBuffers( inBuf, outBuf: boolean );Flush rx/tx buffers
function GetLineStatus: TComPortLineStatusSet;
function IsPolling: boolean;Returns true if polling has not been paused
function OutFreeSpace: word;Returns the output buffer free space or 65535 if not connected
procedure PausePolling;Pauses polling
function ReadByte( var Value: byte ): boolean;
function ReadChar( var Value: char ): boolean;
function ReadData( DataPtr: pchar; MaxDataSize: UINT ): UINT;
function SendByte( Value: byte ): boolean;
function SendChar( Value: char ): boolean;
function SendData( DataPtr: pointer; DataSize: UINT ): UINT;Send data (breaks the data in small packets if it doesn't fit in the output buffer)
function SendDataEx( DataPtr: pchar; DataSize, Timeout: UINT ): UINT;
function SendString( s: string ): boolean;Sends a pascal string (NULL terminated if $H+ (default))
function SendZString( s: pchar ): boolean;Sends a C-style string (NULL terminated)
procedure ToggleDTR( onOff: boolean );
procedure ToggleRTS( onOff: boolean );
procedure ApplyCOMSettings;Apply COM settings
procedure SetComHandle( Value: THANDLE );The COM port handle made public and writeable.
procedure SetComPort( Value: TComPortNumber );Start the timer (used for polling)
procedure SetComPortBaudRate( Value: TComPortBaudRate );Change COM port
procedure SetComPortDataBits( Value: TComPortDataBits );Apply changes
procedure SetComPortHwHandshaking( Value: TComPortHwHandshaking );Apply changes
procedure SetComPortInBufSize( Value: word );Apply changes
procedure SetComPortOutBufSize( Value: word );Adjust the RX packet size
procedure SetComPortParity( Value: TComPortParity );Apply changes
procedure SetComPortPollingDelay( Value: word );PacketTimeout cannot be less than polling delay + some extra ms
procedure SetComPortStopBits( Value: TComPortStopBits );Apply changes
procedure SetComPortSwHandshaking( Value: TComPortSwHandshaking );Apply changes
procedure SetPacketSize( Value: smallint );Set new output buffer size
procedure SetPacketTimeout( Value: integer );If the PacketSize if greater than then RX buffer size then increase the RX buffer size
procedure TimerWndProc( var msg: TMessage );COM port polling proc
| Properties |
property CheckLineStatus : boolean
property ComPort : TComPortNumber
property ComPortDataBits : TComPortDataBits
property ComPortHwHandshaking : TComPortHwHandshaking
property ComPortInBufSize : word
property ComPortOutBufSize : word
property ComPortParity : TComPortParity
property ComPortPollingDelay : word
property ComPortSpeed : TComPortBaudRate
property ComPortStopBits : TComPortStopBits
property ComPortSwHandshaking : TComPortSwHandshaking
property EnableDTROnOpen : boolean
property InputTimeout : UINT
property OutputTimeout : word
property PacketMode : TPacketMode
property PacketSize : smallint
property PacketTimeout : integer
property ComHandle : THANDLE| Events |
event OnReceiveData : TComPortReceiveDataEvent
event OnReceivePacket : TComPortReceivePacketEvent| Variables |
FCkLineStatus : boolean;
FComPort : TComPortNumber;
FComPortBaudRate : TComPortBaudRate;
FComPortDataBits : TComPortDataBits;
FComPortHandle : THANDLE;
FComPortHwHandshaking : TComPortHwHandshaking;
FComPortInBufSize : word;
FComPortOutBufSize : word;
FComPortParity : TComPortParity;
FComPortPollingDelay : word;
FComPortReceiveData : TComPortReceiveDataEvent;
FComPortReceivePacket : TComPortReceivePacketEvent;
FComPortStopBits : TComPortStopBits;
FComPortSwHandshaking : TComPortSwHandshaking;
FEnableDTROnOpen : boolean;
FFirstByteOfPacketTime : DWORD;
FInputTimeout : UINT;
FNotifyWnd : HWND;
FOutputTimeout : word;
FPacketMode : TPacketMode;
FPacketSize : smallint;
FPacketTimeout : integer;
FRXPollingPauses : integer;
FTempInBuffer : pointer;| Constructors |
constructor Create( AOwner: TComponent );Constructor
+-------------------------------------------------------------------------+ | TCOMMPORTDRIVER | +-------------------------------------------------------------------------+
| Functions |
function Connect: boolean;Opens the COM port and takes of it. Returns false if something goes wrong.
Setup buffers size
function Connected: boolean;Returns true if COM port has been opened
Returns true if connected
procedure ContinuePolling;Re-starts polling (after pause)
Re-starts polling (after pause)
function CountRX: integer;Returns number of received bytes in the RX buffer
Returns number of received bytes in the RX buffer
destructor Destroy;Destructor
Allocate a window handle to catch timer's notification messages
procedure Disconnect;Closes the COM port and releases control of it
Start the timer (used for polling)
procedure FlushBuffers( inBuf, outBuf: boolean );Flushes the rx/tx buffers
Flush rx/tx buffers
function GetLineStatus: TComPortLineStatusSet;Returns the current state of CTS, DSR, RING and RLSD (CD) lines. The function fails if the hardware does not support the control-register values (that is, returned set is always empty).
Returns CTS, DSR, RING and RLSD (CD) signals status
function IsPolling: boolean;Returns true if polling has not been paused
Returns true if polling has not been paused
function OutFreeSpace: word;Returns the output buffer free space or 65535 if not connected
Returns the output buffer free space or 65535 if not connected
procedure PausePolling;Pauses polling
Pauses polling
function ReadByte( var Value: byte ): boolean;Reads a byte. Returns true if the byte has been read
Reads a byte. Returns true if the byte has been read
function ReadChar( var Value: char ): boolean;Reads a char. Returns true if char has been read
Reads a char. Returns true if char has been read
function ReadData( DataPtr: pchar; MaxDataSize: UINT ): UINT;Reads binary data. Returns number of bytes read
Reads binary data. Returns number of bytes read
function SendByte( Value: byte ): boolean;Sends a byte. Returns true if the byte has been sent
Sends a byte. Returns true if the byte has been sent
function SendChar( Value: char ): boolean;Sends a char. Returns true if the char has been sent
Sends a char. Returns true if the char has been sent
function SendData( DataPtr: pointer; DataSize: UINT ): UINT;Sends binary data
Send data (breaks the data in small packets if it doesn't fit in the output buffer)
function SendDataEx( DataPtr: pchar; DataSize, Timeout: UINT ): UINT;Sends binary data. Returns number of bytes sent. Timeout overrides the value specifiend in the OutputTimeout property
Sends binary data. Returns number of bytes sent. Timeout overrides the value specifiend in the OutputTimeout property
function SendString( s: string ): boolean;Sends a pascal string (NULL terminated if $H+ (default))
Sends a pascal string (NULL terminated if $H+ (default))
function SendZString( s: pchar ): boolean;Sends a C-style strings (NULL terminated)
Sends a C-style string (NULL terminated)
procedure ToggleDTR( onOff: boolean );Set DTR line high (onOff=TRUE) or low (onOff=FALSE). You must not use HW handshaking.
Set DTR line high (onOff=TRUE) or low (onOff=FALSE). You must not use HW handshaking.
procedure ToggleRTS( onOff: boolean );Set RTS line high (onOff=TRUE) or low (onOff=FALSE). You must not use HW handshaking.
Set RTS line high (onOff=TRUE) or low (onOff=FALSE). You must not use HW handshaking.
procedure ApplyCOMSettings;Applies current settings to open COM port
Apply COM settings
procedure SetComHandle( Value: THANDLE );Sets the COM port handle
The COM port handle made public and writeable. This lets you connect to external opened com port. Setting ComPortHandle to 0 acts as Disconnect.
procedure SetComPort( Value: TComPortNumber );Selects the COM port to use
Start the timer (used for polling)
procedure SetComPortBaudRate( Value: TComPortBaudRate );Selects the baud rate
Change COM port
procedure SetComPortDataBits( Value: TComPortDataBits );Selects the number of data bits
Apply changes
procedure SetComPortHwHandshaking( Value: TComPortHwHandshaking );Selects the kind of hardware flow control
Apply changes
procedure SetComPortInBufSize( Value: word );Sets the RX buffer size
Apply changes
procedure SetComPortOutBufSize( Value: word );Sets the TX buffer size
Adjust the RX packet size
procedure SetComPortParity( Value: TComPortParity );Selects the kind of parity
Apply changes
procedure SetComPortPollingDelay( Value: word );Sets the delay between polling checks
PacketTimeout cannot be less than polling delay + some extra ms
procedure SetComPortStopBits( Value: TComPortStopBits );Selects the number of stop bits
Apply changes
procedure SetComPortSwHandshaking( Value: TComPortSwHandshaking );Selects the kind of software flow control
Apply changes
procedure SetPacketSize( Value: smallint );Sets the size of incoming packets
Set new output buffer size
procedure SetPacketTimeout( Value: integer );Sets the timeout for incoming packets
If the PacketSize if greater than then RX buffer size then increase the RX buffer size
procedure TimerWndProc( var msg: TMessage );Polling proc
COM port polling proc
| Properties |
property CheckLineStatus : booleanSet to TRUE to prevent hangs when not device connected or device is OFF
property ComPort : TComPortNumber# of the COM Port to use
property ComPortDataBits : TComPortDataBitsData bits to used (5..8, for the 8250 the use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits)
property ComPortHwHandshaking : TComPortHwHandshakingKind of Hardware Handshaking to use: hhNONE no handshaking hhNONERTSON no handshaking but keep RTS line on hhCTSRTS RTS/CTS
property ComPortInBufSize : wordInput Buffer size
property ComPortOutBufSize : wordOutput Buffer size
property ComPortParity : TComPortParityKind of Parity to use (none,odd,even,mark,space)
property ComPortPollingDelay : wordms of delay between COM port pollings
property ComPortSpeed : TComPortBaudRateCOM Port speed (bauds)
property ComPortStopBits : TComPortStopBitsStop bits to use (1, 1.5, 2)
property ComPortSwHandshaking : TComPortSwHandshakingKind of Software Handshaking to use: shNONE no handshaking shXONXOFF XON/XOFF handshaking
property EnableDTROnOpen : booleanSet to TRUE to enable DTR line on connect and to leave it on until disconnect. Set to FALSE to disable DTR line on connect.
property InputTimeout : UINTInput timeout (milliseconds)
property OutputTimeout : wordOutput timeout (milliseconds)
property PacketMode : TPacketModeWhat to do with incomplete packets (in RX)
property PacketSize : smallintRX packet size (this value must be less than ComPortInBufSize)
property PacketTimeout : integerTimeout (ms) for a complete packet (in RX)
property ComHandle : THANDLEMake the Handle of the COM port public (for TAPI...) [read/write]
| Events |
event OnReceiveData : TComPortReceiveDataEventEvent to raise when there is data available (input buffer has data) (called only if PacketSize = 0)
event OnReceivePacket : TComPortReceivePacketEventEvent to raise when there is data packet available (called only if PacketSize <> 0)
| Variables |
FCkLineStatus : boolean;Set to TRUE to prevent hangs when no device connected or device is OFF
FComPort : TComPortNumber;# of the COM Port to use
FComPortBaudRate : TComPortBaudRate;COM Port speed (brXXX)
FComPortDataBits : TComPortDataBits;Data bits size (dbXXX)
FComPortHandle : THANDLE;COM Port Device Handle
FComPortHwHandshaking : TComPortHwHandshaking;Type of hw handshaking (hw flow control) to use (hhXXX)
FComPortInBufSize : word;Size of the input buffer
FComPortOutBufSize : word;Size of the output buffer
FComPortParity : TComPortParity;Type of parity to use (ptXXX)
FComPortPollingDelay : word;ms of delay between COM port pollings
FComPortReceiveData : TComPortReceiveDataEvent;Event to raise on data reception (asynchronous)
FComPortReceivePacket : TComPortReceivePacketEvent;Event to raise on packet reception (asynchronous)
FComPortStopBits : TComPortStopBits;How many stop bits to use (sbXXX)
FComPortSwHandshaking : TComPortSwHandshaking;Type of sw handshaking (sw flow control) to use (shXXX)
FEnableDTROnOpen : boolean;Specifies if the DTR line must be enabled/disabled on connect
FFirstByteOfPacketTime : DWORD;Time of the first byte of current RX packet
FInputTimeout : UINT;Timeout for ReadData
FNotifyWnd : HWND;This is used for the timer
FOutputTimeout : word;Output timeout - milliseconds
FPacketMode : TPacketMode;What to do with incomplete packets (pmXXX)
FPacketSize : smallint;Size of a data packet
FPacketTimeout : integer;ms to wait for a complete packet (<=0 = disabled)
FRXPollingPauses : integer;Number of RX polling timer pauses
FTempInBuffer : pointer;Temporary buffer (RX) - used internally