ZylSerialPort Delphi & C++Builder Component

Unit ZylSerialPort

Description
Uses
Classes, Interfaces, Objects and Records
Functions and Procedures
Types
Constants
Variables

Description

ZylSerialPort is a Delphi & C++Builder thread based serial port component. Use ZylSerialPort component to easily communicate with external devices on serial port connection, such as modems, bar code readers, GSM modules and others. It works in synchronous and asynchronous mode. You can use it also with USB, IrDA and Bluetooth devices, because these devices have a driver that redirects the input from the USB, IrDA or Bluetooth port to a virtual serial port (you can check it in System/Device Manager/Ports). If your USB device is not provided with such a driver, then use a USB controller whose vendor provides a virtual serial port driver, such as FTDI or use a USB/RS-232 adapter. If the connection is interrupted, you can set to auto-reconnect when the device is available again.

Overview

Classes, Interfaces, Objects and Records

Name Description
Class TExceptionLogger Exception logger class.
Class TZylSerialPort Implements serial port communication. General usage: You can use it in asynchronous (AutoReceive = true) and synchronous mode (AutoReceive = false). In asynchronous mode the component will check the serial port periodically for new data (Interval property), it will read automatically all the available data, if exist and will fire the OnReceive event. Here you will be able to get the data from the Buffer parameter. If you set the PacketSize property higher than 0, then maximum PacketSize amount of bytes will be read periodically (it can be fewer, if not enough data is available). If you set PacketTerminator to true, then data will be read automatically until it reach the NewLine property string. This will ensure that you receive the packet in one piece. If it will not receive NewLine in 60 seconds, then it will return the available data without NewLine. In this case PacketSize will be ignored. In synchronous mode OnReceive event will fire every time, when new data is available and you can read the data using the various Read methods programmatically.
Class EZylSerialPortException Serial Port exception class.

Types

TCommPort = (...);
TCommPortSet = set of TCommPort;
TBaudRate = (...);
TStopBits = (...);
TDataWidth = (...);
TParityBits = (...);
THwFlowControl = (...);
TSwFlowControl = (...);
TLineStatus = (...);
TLineStatusSet = set of TLineStatus;
TSerialCommPortType = (...);
TSerialError = (...);
TSerialErrorSet = set of TSerialError;
TConnectEvent = procedure(Sender: TObject; Port: TCommPort) of object;
TSendReceiveEvent = procedure(Sender: TObject; Buffer: AnsiString) of object;
TLineStatusEvent = procedure(Sender: TObject; LineStatus: TLineStatusSet) of object;
TDetectEvent = procedure(Sender: TObject; const Port: TCommPort; const BaudRate: TBaudRate; var Cancel: Boolean) of object;
TReconnectEvent = procedure(Sender: TObject; const Port: TCommPort; const BaudRate: TBaudRate; var Cancel: Boolean) of object;
TErrorEvent = procedure(Sender: TObject; const errorCode: Cardinal) of object;

Constants

dcb_Binary = $00000001;
dcb_ParityCheck = $00000002;
dcb_OutxCtsFlow = $00000004;
dcb_OutxDsrFlow = $00000008;
dcb_DtrControlMask = $00000030;
dcb_DtrControlDisable = $00000000;
dcb_DtrControlEnable = $00000010;
dcb_DtrControlHandshake = $00000020;
dcb_DsrSensivity = $00000040;
dcb_TXContinueOnXoff = $00000080;
dcb_OutX = $00000100;
dcb_InX = $00000200;
dcb_ErrorChar = $00000400;
dcb_NullStrip = $00000800;
dcb_RtsControlMask = $00003000;
dcb_RtsControlDisable = $00000000;
dcb_RtsControlEnable = $00001000;
dcb_RtsControlHandshake = $00002000;
dcb_RtsControlToggle = $00003000;
dcb_AbortOnError = $00004000;
dcb_Reserveds = $FFFF8000;
se_Break = $0010;
se_Frame = $0008;
se_Overrun = $0002;
se_RxOver = $0001;
se_RxParity = $0004;

Description

Types

TCommPort = (...);

Physical serial port enumeration type.

Values
  • spNone
  • spCOM1
  • spCOM2
  • spCOM3
  • spCOM4
  • spCOM5
  • spCOM6
  • spCOM7
  • spCOM8
  • spCOM9
  • spCOM10
  • spCOM11
  • spCOM12
  • spCOM13
  • spCOM14
  • spCOM15
  • spCOM16
  • spCOM17
  • spCOM18
  • spCOM19
  • spCOM20
  • spCOM21
  • spCOM22
  • spCOM23
  • spCOM24
  • spCOM25
  • spCOM26
  • spCOM27
  • spCOM28
  • spCOM29
  • spCOM30
  • spCOM31
  • spCOM32
  • spCOM33
  • spCOM34
  • spCOM35
  • spCOM36
  • spCOM37
  • spCOM38
  • spCOM39
  • spCOM40
  • spCOM41
  • spCOM42
  • spCOM43
  • spCOM44
  • spCOM45
  • spCOM46
  • spCOM47
  • spCOM48
  • spCOM49
  • spCOM50
  • spCOM51
  • spCOM52
  • spCOM53
  • spCOM54
  • spCOM55
  • spCOM56
  • spCOM57
  • spCOM58
  • spCOM59
  • spCOM60
  • spCOM61
  • spCOM62
  • spCOM63
  • spCOM64
  • spCOM65
  • spCOM66
  • spCOM67
  • spCOM68
  • spCOM69
  • spCOM70
  • spCOM71
  • spCOM72
  • spCOM73
  • spCOM74
  • spCOM75
  • spCOM76
  • spCOM77
  • spCOM78
  • spCOM79
  • spCOM80
  • spCOM81
  • spCOM82
  • spCOM83
  • spCOM84
  • spCOM85
  • spCOM86
  • spCOM87
  • spCOM88
  • spCOM89
  • spCOM90
  • spCOM91
  • spCOM92
  • spCOM93
  • spCOM94
  • spCOM95
  • spCOM96
  • spCOM97
  • spCOM98
  • spCOM99
  • spCOM100
  • spCOM101
  • spCOM102
  • spCOM103
  • spCOM104
  • spCOM105
  • spCOM106
  • spCOM107
  • spCOM108
  • spCOM109
  • spCOM110
  • spCOM111
  • spCOM112
  • spCOM113
  • spCOM114
  • spCOM115
  • spCOM116
  • spCOM117
  • spCOM118
  • spCOM119
  • spCOM120
  • spCOM121
  • spCOM122
  • spCOM123
  • spCOM124
  • spCOM125
  • spCOM126
  • spCOM127
  • spCOM128
  • spCOM129
  • spCOM130
  • spCOM131
  • spCOM132
  • spCOM133
  • spCOM134
  • spCOM135
  • spCOM136
  • spCOM137
  • spCOM138
  • spCOM139
  • spCOM140
  • spCOM141
  • spCOM142
  • spCOM143
  • spCOM144
  • spCOM145
  • spCOM146
  • spCOM147
  • spCOM148
  • spCOM149
  • spCOM150
  • spCOM151
  • spCOM152
  • spCOM153
  • spCOM154
  • spCOM155
  • spCOM156
  • spCOM157
  • spCOM158
  • spCOM159
  • spCOM160
  • spCOM161
  • spCOM162
  • spCOM163
  • spCOM164
  • spCOM165
  • spCOM166
  • spCOM167
  • spCOM168
  • spCOM169
  • spCOM170
  • spCOM171
  • spCOM172
  • spCOM173
  • spCOM174
  • spCOM175
  • spCOM176
  • spCOM177
  • spCOM178
  • spCOM179
  • spCOM180
  • spCOM181
  • spCOM182
  • spCOM183
  • spCOM184
  • spCOM185
  • spCOM186
  • spCOM187
  • spCOM188
  • spCOM189
  • spCOM190
  • spCOM191
  • spCOM192
  • spCOM193
  • spCOM194
  • spCOM195
  • spCOM196
  • spCOM197
  • spCOM198
  • spCOM199
  • spCOM200
  • spCOM201
  • spCOM202
  • spCOM203
  • spCOM204
  • spCOM205
  • spCOM206
  • spCOM207
  • spCOM208
  • spCOM209
  • spCOM210
  • spCOM211
  • spCOM212
  • spCOM213
  • spCOM214
  • spCOM215
  • spCOM216
  • spCOM217
  • spCOM218
  • spCOM219
  • spCOM220
  • spCOM221
  • spCOM222
  • spCOM223
  • spCOM224
  • spCOM225
  • spCOM226
  • spCOM227
  • spCOM228
  • spCOM229
  • spCOM230
  • spCOM231
  • spCOM232
  • spCOM233
  • spCOM234
  • spCOM235
  • spCOM236
  • spCOM237
  • spCOM238
  • spCOM239
  • spCOM240
  • spCOM241
  • spCOM242
  • spCOM243
  • spCOM244
  • spCOM245
  • spCOM246
  • spCOM247
  • spCOM248
  • spCOM249
  • spCOM250
  • spCOM251
  • spCOM252
  • spCOM253
  • spCOM254
  • spCustom: Custom port name
TCommPortSet = set of TCommPort;

Physical serial port set type.

TBaudRate = (...);

Baud rate enumeration type. It's the measure of how fast data is moving between instruments that use serial communication. Unit of measurement: bps (bits per second). RS-232 uses only two voltage states, called MARK and SPACE. In such a two-state coding scheme, the baud rate is identical to the maximum number of bits of information, including "control" bits, that are transmitted per second.

Values
  • br000075
  • br000110
  • br000134
  • br000150
  • br000300
  • br000600
  • br001200
  • br001800
  • br002400
  • br004800
  • br007200
  • br009600
  • br014400
  • br019200
  • br038400
  • br057600
  • br115200
  • br128000
  • br230400
  • br256000
  • br460800
  • br921600
  • brCustom: CustomBaudRate will be used.
TStopBits = (...);

Stop bits enumeration type. The last part of a character frame consists of 1, 1.5, or 2 stop bits. These bits are always represented by a negative voltage. If no further characters are transmitted, the line stays in the negative (MARK) condition. The transmission of the next character frame, if any, is heralded by a start bit of positive (SPACE) voltage.

Values
  • sb1Bit: 1 stop bit.
  • sb1_5Bits: 1.5 stop bits.
  • sb2Bits: 2 stop bits.
TDataWidth = (...);

Data bits enumeration type (ByteSize). Data bits are transmitted "upside down and backwards." Inverted logic is used and the order of transmission is from least significant bit (LSB) to most significant bit (MSB). To interpret the data bits in a character frame, you must read from right to left, and read 1 for negative voltage and 0 for positive voltage.

Values
  • dw5Bits: 5 bits.
  • dw6Bits: 6 bits.
  • dw7Bits: 7 bits.
  • dw8Bits: 8 bits.
TParityBits = (...);

Parity bits enumeration type. An optional parity bit follows the data bits in the character frame. The parity bit, if present, also follows inverted logic: read 1 for negative voltage and 0 for positive voltage. This bit is included as a simple means of error checking. The idea is this: you specify ahead of time whether the parity of the transmission is to be even or odd. Suppose the parity is chosen to be odd. The transmitter will then set the parity bit in such a way as to make an odd number of 1's among the data bits and the parity bit.

Values
  • pbNone: No parity.
  • pbOdd: Odd.
  • pbEven: Even.
  • pbMark: Mark.
  • pbSpace: Space.
THwFlowControl = (...);

Hardware flow control enumeration type.

Possible values: None, None + RTS always on, RTS/CTS.

Values
  • hfNONE: No hardware handshake.
  • hfDTRDSR: DTR flow control.
  • hfRTSCTS: RTS flow control.
TSwFlowControl = (...);

Software flow control enumeration type.

Possible values: None, XON/XOFF.

Values
  • sfNONE: No software handshake.
  • sfXONXOFF: XON/XOFF.
TLineStatus = (...);

Line status enumeration type.

Possible values: Clear To Send, Data Set Ready, Ring, Carrier Detect = Received Line Signal Detected (RLSD).

Values
  • lsCTS: Clear To Send.
  • lsDSR: Data Set Ready.
  • lsRING: Ring.
  • lsDCD: Carrier Detect = Received Line Signal Detected (alternately RLSD or CD).
TLineStatusSet = set of TLineStatus;

Line status set type.

TSerialCommPortType = (...);

Serial port type enumeration.

Possible values: Serial, USB, Bluetooth, Virtual, Unknown.

Values
  • stSerial: Serial.
  • stUsb: USB.
  • stBluetooth: Bluetooth.
  • stVirtual: Virtual serial port.
  • stUnknown: Unknown type.
TSerialError = (...);

Serial communication errors enumeration type. It can be one or more of the following values.

You can sometimes get errors at the beginning of the communication. The problem is probably that you are opening the port while the remote device is in the middle of transmitting. This can cause your serial port to miss-detect the start bit of the data byte, causing corrupted data (framing errors) until there is a gap in the communication and the UART can resynchronize with the next start bit in the data stream.

Values
  • seBreak: The hardware detected a break condition.
  • seFrame: The hardware detected a framing error.
  • seOverrun: A character-buffer overrun has occurred. The next character is lost.
  • seRxOver: An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
  • seRxParity: The hardware detected a parity error.
TSerialErrorSet = set of TSerialError;

Serial error set type.

TConnectEvent = procedure(Sender: TObject; Port: TCommPort) of object;

Type of OnConnect and OnDisconnect events.

Parameters
Sender
Sender object.
Port
The name of the serial port.
TSendReceiveEvent = procedure(Sender: TObject; Buffer: AnsiString) of object;

Type of OnReceive and OnSend events.

Parameters
Sender
Sender object.
Buffer
Read / write buffer data, the string of what you receive or send.
TLineStatusEvent = procedure(Sender: TObject; LineStatus: TLineStatusSet) of object;

Type of OnLineStatusChange event.

Parameters
Sender
Sender object.
LineStatus
New line status value.
TDetectEvent = procedure(Sender: TObject; const Port: TCommPort; const BaudRate: TBaudRate; var Cancel: Boolean) of object;

Type of OnDetect event.

Parameters
Sender
Sender object.
Port
The name of the detected serial port.
BaudRate
Detected baud rate value.
Cancel
If this parameter is true, the detection process will be cancellled.
TReconnectEvent = procedure(Sender: TObject; const Port: TCommPort; const BaudRate: TBaudRate; var Cancel: Boolean) of object;

Type of OnReconnect event.

Parameters
Sender
Sender object.
Port
The name of the serial port.
BaudRate
Baud rate value.
Cancel
If this parameter is true, the reconnection process will be cancellled.
TErrorEvent = procedure(Sender: TObject; const errorCode: Cardinal) of object;

Type of OnError event.

Parameters
Sender
Sender object.
errorCode
The code of the error.

Constants

dcb_Binary = $00000001;
 
dcb_ParityCheck = $00000002;
 
dcb_OutxCtsFlow = $00000004;
 
dcb_OutxDsrFlow = $00000008;
 
dcb_DtrControlMask = $00000030;
 
dcb_DtrControlDisable = $00000000;
 
dcb_DtrControlEnable = $00000010;
 
dcb_DtrControlHandshake = $00000020;
 
dcb_DsrSensivity = $00000040;
 
dcb_TXContinueOnXoff = $00000080;
 
dcb_OutX = $00000100;
 
dcb_InX = $00000200;
 
dcb_ErrorChar = $00000400;
 
dcb_NullStrip = $00000800;
 
dcb_RtsControlMask = $00003000;
 
dcb_RtsControlDisable = $00000000;
 
dcb_RtsControlEnable = $00001000;
 
dcb_RtsControlHandshake = $00002000;
 
dcb_RtsControlToggle = $00003000;
 
dcb_AbortOnError = $00004000;
 
dcb_Reserveds = $FFFF8000;
 
se_Break = $0010;
 
se_Frame = $0008;
 
se_Overrun = $0002;
 
se_RxOver = $0001;
 
se_RxParity = $0004;
 
Copyright © 2003 - 2025 by Zyl Soft. All rights reserved.
Generated by PasDoc 0.16.0.