Class TCommPortDriver
Unit
Declaration
type TCommPortDriver = class(TComponent)
Description
The base class of an communication port driver.
:
This class was created to reduce the efforts to create new communication port drivers, both on single-thread and multi-threads environments.
To make a minimal usable communication port driver, you must overwrite only five virtual methods that do all work (don't forget of the properties/procedures/functions particular of your communication port). The methods that you must overwrite are this:
function ComSettingsOK:Boolean; virtual;
Overwrite this function to check if the setting of your communication port are rigth.
procedure PortStart(var Ok:Boolean); virtual;
Opens the communication port. If it was open successfully, return true on OK variable.
procedure PortStop(var Ok:Boolean); virtual;
Closes the communication port. If it was closed successfully, return true on OK variable.
procedure Read(Packet:PIOPacket); virtual; abstract;
Overwrite this method to read data of your communication port.
procedure Write(Packet:PIOPacket); virtual; abstract;
Overwrite this method to write data on your communication port.
After do this, your communication port already is thread-safe!
Hierarchy
- TComponent
- TCommPortDriver
Overview
Fields
FDelayBetweenCmds:Cardinal; |
|
FExclusiveDevice:Boolean; |
|
PActive:Boolean; |
|
PClearBufOnErr:Boolean; |
|
Protocols:array of TComponent; |
|
EventInterfaces:IPortDriverEventNotificationArray; |
Methods
procedure SetActive(v:Boolean); virtual; |
|
procedure CommError(WriteCmd:Boolean; Error:TIOResult); |
|
procedure CommPortOpened; |
|
procedure CommPortOpenError; |
|
procedure CommPortClose; |
|
procedure CommPortCloseError; |
|
procedure CommPortDisconected; |
|
procedure DoReadError(Error:TIOResult); virtual; |
|
procedure DoWriteError(Error:TIOResult); virtual; |
|
procedure DoPortOpened(sender:TObject); virtual; |
|
procedure DoPortOpenError(sender:TObject); virtual; |
|
procedure DoPortClose(sender:TObject); virtual; |
|
procedure DoPortCloseError(sender:TObject); virtual; |
|
procedure DoPortDisconnected(sender:TObject); virtual; |
|
procedure Read(Packet:PIOPacket); virtual; abstract; |
|
procedure Write(Packet:PIOPacket); virtual; abstract; |
|
procedure NeedSleepBetweenRW; virtual; abstract; |
|
procedure PortStart(var Ok:Boolean); virtual; abstract; |
|
procedure PortStop(var Ok:Boolean); virtual; abstract; |
|
function ComSettingsOK:Boolean; virtual; |
|
procedure ClearALLBuffers; virtual; abstract; |
|
procedure DoExceptionInActive; |
|
procedure RefreshLastOSError; |
|
constructor Create(AOwner:TComponent); override; |
|
destructor Destroy; override; |
|
procedure AddProtocol(Prot:TComponent); |
|
procedure DelProtocol(Prot:TComponent); |
|
function IOCommandSync(Cmd:TIOCommand; ToWrite:BYTES; BytesToRead, BytesToWrite, DriverID, DelayBetweenCmds:Cardinal; CallBack:TDriverCallBack; Res1:TObject; Res2:Pointer; OnBegin:TNotifyEvent = nil; OnEnd:TNotifyEvent = nil):Cardinal; overload; deprecated; |
|
function IOCommandSync(Cmd:TIOCommand; BytesToWrite:Cardinal; ToWrite:BYTES; BytesToRead, DriverID, DelayBetweenCmds:Cardinal; pkt:PIOPacket; OnBegin:TNotifyEvent = nil; OnEnd:TNotifyEvent = nil):Cardinal; overload; |
|
function Lock(DriverID:Cardinal):Boolean; |
|
function Unlock(DriverID:Cardinal):Boolean; |
|
function ReallyActive:Boolean; virtual; |
Properties
property OnCommErrorReading: TCommPortErrorEvent read FOnCommErrorReading write FOnCommErrorReading; |
|
property OnCommErrorWriting: TCommPortErrorEvent read FOnCommErrorWriting write FOnCommErrorWriting; |
|
property OnCommPortOpened: TNotifyEvent read FOnCommPortOpened write FOnCommPortOpened; |
|
property OnCommPortOpenError: TNotifyEvent read FOnCommPortOpenError write FOnCommPortOpenError; |
|
property OnCommPortClosed: TNotifyEvent read FOnCommPortClosed write FOnCommPortClosed; |
|
property OnCommPortCloseError: TNotifyEvent read FOnCommPortCloseError write FOnCommPortCloseError; |
|
property OnCommPortDisconnected: TNotifyEvent read FOnCommPortDisconnected write FOnCommPortDisconnected; |
|
property ReadRetries: Cardinal read FReadRetries write SetReadRetries default 3; |
|
property WriteRetries: Cardinal read FWriteRetries write SetWriteRetries default 3; |
|
property Active: Boolean read PActive write SetActive stored true default false; |
|
property ClearBuffersOnCommErrors: Boolean read PClearBufOnErr write PClearBufOnErr default true; |
|
property LockedBy: Cardinal read PLockedBy; |
|
property Locked: Boolean read GetLocked; |
|
property LastOSErrorNumber: LongInt read FLastOSErrorNumber; |
|
property LastOSErrorMessage: AnsiString read FLastOSErrorMessage; |
|
property CommandsPerSecond: LongInt read FCommandsSecond; |
|
property TXBytes: Int64 read FTXBytes; |
|
property TXBytesSecond: Int64 read FTXBytesSecond; |
|
property RXBytes: Int64 read FRXBytes; |
|
property RXBytesSecond: Int64 read FRXBytesSecond; |
|
property LogIOActions: Boolean read FLogActions write SetLogActions default false; |
|
property LogFile: AnsiString read FLogFile write SetLogFile; |
Description
Fields
FDelayBetweenCmds:Cardinal; |
|
FExclusiveDevice:Boolean; |
|
: Stores if the communication port is exclusive (like serial port) |
PActive:Boolean; |
|
: Stores the actual state of the communication port driver (Open or closed); |
PClearBufOnErr:Boolean; |
|
: Stores if the buffers must be cleared after some communication error. |
Protocols:array of TComponent; |
|
: Array that stores what's protocols uses this communication port driver. See also |
EventInterfaces:IPortDriverEventNotificationArray; |
|
: Array que armazena os drivers de protocolo dependentes. See also |
Methods
procedure CommError(WriteCmd:Boolean; Error:TIOResult); |
|
: Send a communication error message from the thread to the application. |
procedure CommPortOpened; |
|
: Sends a message to the application/protocol thread when the communication port was open. |
procedure CommPortOpenError; |
|
: Sends a message to the application/protocol thread, if communication port can't be open. |
procedure CommPortClose; |
|
: Sends a message to the application/protocol thread when the communication port was close. |
procedure CommPortCloseError; |
|
: Sends a message to the application/protocol thread, if the communication port can't be closed. |
procedure CommPortDisconected; |
|
: Sends a message to the application/protocol thread, if the communication port was disconnected (TCP/IP). |
procedure DoReadError(Error:TIOResult); virtual; |
|
///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// : Notifies the OnCommErrorReading event about an read error. |
procedure DoWriteError(Error:TIOResult); virtual; |
|
: Notifies the OnCommErrorWriting event about an write error. |
procedure DoPortOpened(sender:TObject); virtual; |
|
: Notifies the OnCommPortOpened when the communication port opens. |
procedure DoPortOpenError(sender:TObject); virtual; |
|
: Notifies the OnCommPortOpenError event if a error occurs when opening communication port. |
procedure DoPortClose(sender:TObject); virtual; |
|
: Notifies the OnCommPortClosed event when the communication port was closed. |
procedure DoPortCloseError(sender:TObject); virtual; |
|
: Notifies the OnCommPortCloseError event if a error occurs when closing communication port. |
procedure DoPortDisconnected(sender:TObject); virtual; |
|
: Notifies the OnCommPortDisconnected event when a connection is lost (usefull in TCP/IP) |
procedure Read(Packet:PIOPacket); virtual; abstract; |
|
: Procedure called when is needed to read something on communication port. To create a new communication port, you must overwritten this procedure. . Parameters
See also |
procedure Write(Packet:PIOPacket); virtual; abstract; |
|
: Procedure called when is needed to write something on communication port. To create a new communication port, you must overwritten this procedure. . Parameters
See also |
procedure NeedSleepBetweenRW; virtual; abstract; |
|
: |
procedure RefreshLastOSError; |
|
: |
constructor Create(AOwner:TComponent); override; |
|
: Creates the communication port, initializing threads and internal variables. |
destructor Destroy; override; |
|
: Destroys the communication port, closing and removing all references of protocols to it. See also |
procedure DelProtocol(Prot:TComponent); |
|
: Removes a protocol driver of the list of dependents. Parameters
See also |
function IOCommandSync(Cmd:TIOCommand; ToWrite:BYTES; BytesToRead, BytesToWrite, DriverID, DelayBetweenCmds:Cardinal; CallBack:TDriverCallBack; Res1:TObject; Res2:Pointer; OnBegin:TNotifyEvent = nil; OnEnd:TNotifyEvent = nil):Cardinal; overload; deprecated; |
|
Warning: this symbol is deprecated. : Do a synchronous I/O request to the communication port (blocks your application until this action is done). Parameters
ReturnsReturns the I/O command ID. Returns 0 if the communication port has been destroied or if the communication port is closed. See also
|
function IOCommandSync(Cmd:TIOCommand; BytesToWrite:Cardinal; ToWrite:BYTES; BytesToRead, DriverID, DelayBetweenCmds:Cardinal; pkt:PIOPacket; OnBegin:TNotifyEvent = nil; OnEnd:TNotifyEvent = nil):Cardinal; overload; |
|
: Do a synchronous I/O request to the communication port (blocks your application until this action is done). Parameters
ReturnsReturns the I/O command ID. Returns 0 if the communication port has been destroied or if the communication port is closed. See also
|
function ReallyActive:Boolean; virtual; |
|
: Return true if the communication port is open really. |
Properties
property OnCommErrorReading: TCommPortErrorEvent read FOnCommErrorReading write FOnCommErrorReading; |
|
: Event called when a read error occurs on communication port. |
property OnCommErrorWriting: TCommPortErrorEvent read FOnCommErrorWriting write FOnCommErrorWriting; |
|
: Event called when a write error occurs on communication port. |
property OnCommPortOpened: TNotifyEvent read FOnCommPortOpened write FOnCommPortOpened; |
|
: Event called when the communication port was open. |
property OnCommPortOpenError: TNotifyEvent read FOnCommPortOpenError write FOnCommPortOpenError; |
|
: Event called when the communication was not open successfully. |
property OnCommPortClosed: TNotifyEvent read FOnCommPortClosed write FOnCommPortClosed; |
|
: Event called when the communication port was closed. |
property OnCommPortCloseError: TNotifyEvent read FOnCommPortCloseError write FOnCommPortCloseError; |
|
: Event called when the communication was not closed successfully. |
property OnCommPortDisconnected: TNotifyEvent read FOnCommPortDisconnected write FOnCommPortDisconnected; |
|
: Event called when the communication port has been disconected. |
property ReadRetries: Cardinal read FReadRetries write SetReadRetries default 3; |
|
: Number of read retries. |
property WriteRetries: Cardinal read FWriteRetries write SetWriteRetries default 3; |
|
: Number of write retries. |
property Active: Boolean read PActive write SetActive stored true default false; |
|
: Opens ( |
property ClearBuffersOnCommErrors: Boolean read PClearBufOnErr write PClearBufOnErr default true; |
|
:If |
property LockedBy: Cardinal read PLockedBy; |
|
:Identification of who have exclusive access on communication port. |
property Locked: Boolean read GetLocked; |
|
:Returns |
property LastOSErrorNumber: LongInt read FLastOSErrorNumber; |
|
: The last error code registered by the OS. |
property LastOSErrorMessage: AnsiString read FLastOSErrorMessage; |
|
: The last error message registered by the OS. |
property CommandsPerSecond: LongInt read FCommandsSecond; |
|
: How many I/O commands are processed by second. Updated every 1 second. |
property TXBytes: Int64 read FTXBytes; |
|
: Total of bytes sent (written). |
property TXBytesSecond: Int64 read FTXBytesSecond; |
|
: Total of bytes sent on the last second. |
property RXBytes: Int64 read FRXBytes; |
|
: Total of bytes received (received). |
property RXBytesSecond: Int64 read FRXBytesSecond; |
|
: Total of bytes received on the last second. |
property LogIOActions: Boolean read FLogActions write SetLogActions default false; |
|
: Enable/disables the log of I/O actions of the communication port. |
property LogFile: AnsiString read FLogFile write SetLogFile; |
|
: File to store the log of I/O actions of the communication port. |
Author
- Fabio Luis Girardi <[email protected]>
Generated by PasDoc 0.14.0.