cSerialPort Properties Reference
📋 Properties List
cSerialPort Properties
| Property | Type | Access | Description |
|---|---|---|---|
IsOpen | Boolean | Read-only | Whether the serial port is open |
PortName | String | Read/Write | Port name, cannot be modified after opening |
Handle | Long | Read-only | Serial port handle |
Config | cSerialConfig | Read/Write | Configuration object |
LastError | Long | Read-only | Last error code |
LastErrorMsg | String | Read-only | Last error description |
ReceivedCount | Long | Read-only | Cumulative received bytes |
SentCount | Long | Read-only | Cumulative sent bytes |
InBufferCount | Long | Read-only | Current bytes in input buffer |
OutBufferCount | Long | Read-only | Current bytes in output buffer |
CtsHolding | Boolean | Read-only | CTS signal status |
DsrHolding | Boolean | Read-only | DSR signal status |
RingHolding | Boolean | Read-only | RING signal status |
CdHolding | Boolean | Read-only | CD/RLSD signal status |
IsWaitingOnCts | Boolean | Read-only | Whether waiting on CTS |
IsWaitingOnDsr | Boolean | Read-only | Whether waiting on DSR |
IsWaitingOnRlsd | Boolean | Read-only | Whether waiting on RLSD |
IsXoffHold | Boolean | Read-only | Whether paused by XOFF |
IsXoffSent | Boolean | Read-only | Whether XOFF has been sent |
Monitoring | Boolean | Read-only | Whether monitoring is active |
PollInterval | Long | Read/Write | Polling interval(ms), 10~60000 |
cSerialConfig Properties
| Property | Type | Default | Description |
|---|---|---|---|
BaudRate | Long | 9600 | Baud rate |
DataBits | Long | 8 | Data bits, 4~8 |
StopBits | Long | 0 | Stop bits |
Parity | Long | 0 | Parity |
FlowControl | Long | 0 | Flow control |
DtrControl | Long | 1 | DTR control mode |
RtsControl | Long | 1 | RTS control mode |
ReadIntervalTimeout | Long | 50 | Read interval timeout(ms) |
ReadTotalTimeoutMultiplier | Long | 0 | Read per-byte timeout multiplier |
ReadTotalTimeoutConstant | Long | 100 | Read fixed timeout(ms) |
WriteTotalTimeoutMultiplier | Long | 0 | Write per-byte timeout multiplier |
WriteTotalTimeoutConstant | Long | 100 | Write fixed timeout(ms) |
InBufferSize | Long | 4096 | Input buffer size(bytes) |
OutBufferSize | Long | 4096 | Output buffer size(bytes) |
XonChar | Byte | &H11 | XON character |
XoffChar | Byte | &H13 | XOFF character |
ErrorChar | Byte | 0 | Parity error replacement character |
EofChar | Byte | 0 | EOF character |
EvtChar | Byte | 0 | Event trigger character |
NullDiscard | Boolean | False | Whether to discard NULL bytes |
AbortOnError | Boolean | False | Whether to abort read/write on error |
TXContinueOnXoff | Boolean | False | Whether to continue sending after XOFF |
ParityReplace | Boolean | True | Whether to replace characters on parity error |
🔧 cSerialPort Properties Details
IsOpen
Whether the serial port is open.
If sp.IsOpen Then
Debug.Print "Serial port is open"
End IfPortName
Port name. Cannot be modified after opening, must close first.
sp.PortName = "COM3"
sp.OpenPort
' sp.PortName = "COM4" ' Error! Cannot change after opening
sp.ClosePort
sp.PortName = "COM4" ' Can change after closingConfig
Configuration object, type cSerialConfig. Changes while port is open require calling ApplyConfig to take effect.
' Read configuration
Debug.Print sp.Config.BaudRate
' Modify configuration
sp.Config.BaudRate = br115200
If sp.IsOpen Then sp.ApplyConfig ' Must manually apply if already open
' Replace entire configuration object
Dim cfg As New cSerialConfig
cfg.BaudRate = br9600
Set sp.Config = cfg ' Automatically appliesLastError / LastErrorMsg
Last Win32 error code and description. OpenPort returns False and sets LastError on failure.
If Not sp.OpenPort("COM99") Then
Debug.Print "Error code: " & sp.LastError
Debug.Print "Error description: " & sp.LastErrorMsg
End IfReceivedCount / SentCount
Cumulative send/receive byte count. Can be reset with ResetCounters.
Debug.Print "Received: " & sp.ReceivedCount & " bytes"
Debug.Print "Sent: " & sp.SentCount & " bytes"
sp.ResetCountersInBufferCount / OutBufferCount
Current byte count in input/output buffer.
If sp.InBufferCount > 0 Then
Debug.Print "Buffer has " & sp.InBufferCount & " bytes available"
End IfSignal Line Status Properties
| Property | Signal | Description |
|---|---|---|
CtsHolding | CTS | Clear To Send |
DsrHolding | DSR | Data Set Ready |
RingHolding | RING | Ring Indicator |
CdHolding | CD/RLSD | Carrier Detect |
Debug.Print "CTS=" & sp.CtsHolding & " DSR=" & sp.DsrHolding
Debug.Print "RING=" & sp.RingHolding & " CD=" & sp.CdHoldingPollInterval
Monitoring polling interval in milliseconds, range 10~60000. Can be specified when calling StartMonitoring, or modified via property.
sp.PollInterval = 100 ' 100ms polling⚙️ cSerialConfig Properties Details
BaudRate
Baud rate, use eBaudRate enum constants. Supports up to 256000, far exceeding the MSComm control's limit of 115200.
| Constant | Value | Description |
|---|---|---|
br110 | 110 | |
br300 | 300 | |
br600 | 600 | |
br1200 | 1200 | |
br2400 | 2400 | |
br4800 | 4800 | |
br9600 | 9600 | Default |
br14400 | 14400 | |
br19200 | 19200 | |
br38400 | 38400 | |
br56000 | 56000 | |
br57600 | 57600 | |
br115200 | 115200 | Common high-speed |
br128000 | 128000 | |
br256000 | 256000 | Maximum supported |
cfg.BaudRate = br9600 ' Or br115200, br57600, br256000, etc.DataBits
Data bits, range 4~8, throws error if out of range.
cfg.DataBits = 8StopBits
Stop bits, use eStopBits enum: sb1(0), sb1_5(1), sb2(2).
Parity
Parity, use eParity enum: ptNone(0), ptOdd(1), ptEven(2), ptMark(3), ptSpace(4).
FlowControl
Flow control, use eFlowControl enum. Setting this automatically synchronizes DTR/RTS control modes.
cfg.FlowControl = fcRtsCts ' Hardware flow control RTS/CTSDtrControl / RtsControl
DTR/RTS control modes. Use eDtrControl/eRtsControl enum: dcDisable(0), dcEnable(1), dcHandshake(2), rcToggle(3, RTS only).
Timeout Parameters
| Parameter | Description |
|---|---|
ReadIntervalTimeout | Maximum interval between two reads, return on timeout |
ReadTotalTimeoutMultiplier | Per-byte timeout multiplier |
ReadTotalTimeoutConstant | Read fixed timeout |
WriteTotalTimeoutMultiplier | Write per-byte timeout multiplier |
WriteTotalTimeoutConstant | Write fixed timeout |
Total timeout = Multiplier × byte count + Constant. See Advanced - Timeout Strategies
InBufferSize / OutBufferSize
Buffer sizes, must be greater than 0.
XonChar / XoffChar
XON/XOFF flow control characters, default &H11(DC1) and &H13(DC3).
📚 Enum Reference
All enums are defined in class modules (not standard modules), so they are exported with the DLL type library and available to external projects. See Overview - Architecture for details.
eBaudRate (cSerialConfig)
Baud rate constants. Maximum: 256000. See BaudRate for full table.
eParity (cSerialConfig)
| Constant | Value | Win32 Constant | Description |
|---|---|---|---|
ptNone | 0 | NOPARITY | No parity |
ptOdd | 1 | ODDPARITY | Odd parity |
ptEven | 2 | EVENPARITY | Even parity |
ptMark | 3 | MARKPARITY | Mark parity |
ptSpace | 4 | SPACEPARITY | Space parity |
eStopBits (cSerialConfig)
| Constant | Value | Win32 Constant | Description |
|---|---|---|---|
sb1 | 0 | ONESTOPBIT | 1 stop bit |
sb1_5 | 1 | ONE5STOPBITS | 1.5 stop bits |
sb2 | 2 | TWOSTOPBITS | 2 stop bits |
eDtrControl (cSerialConfig)
| Constant | Value | Win32 Constant | Description |
|---|---|---|---|
dcDisable | 0 | DTR_CONTROL_DISABLE | DTR line disabled |
dcEnable | 1 | DTR_CONTROL_ENABLE | DTR line enabled |
dcHandshake | 2 | DTR_CONTROL_HANDSHAKE | DTR flow control handshake |
eRtsControl (cSerialConfig)
| Constant | Value | Win32 Constant | Description |
|---|---|---|---|
rcDisable | 0 | RTS_CONTROL_DISABLE | RTS line disabled |
rcEnable | 1 | RTS_CONTROL_ENABLE | RTS line enabled |
rcHandshake | 2 | RTS_CONTROL_HANDSHAKE | RTS flow control handshake |
rcToggle | 3 | RTS_CONTROL_TOGGLE | RTS toggle mode |
eFlowControl (cSerialConfig)
| Constant | Value | Description |
|---|---|---|
fcNone | 0 | No flow control |
fcXonXoff | 1 | Software flow control (XON/XOFF) |
fcRtsCts | 2 | Hardware flow control (RTS/CTS) |
fcDtrDsr | 3 | Hardware flow control (DTR/DSR) |
fcRtsCtsAndXonXoff | 4 | Mixed flow control (RTS/CTS + XON/XOFF) |
eCommEvent (cSerialPort)
Communication events for SetCommMask / WaitForEvent / PinChanged.
| Constant | Value | Description |
|---|---|---|
EV_RXCHAR | &H1 | Character received |
EV_RXFLAG | &H2 | Event character received |
EV_TXEMPTY | &H4 | Transmit buffer empty |
EV_CTS | &H8 | CTS signal changed |
EV_DSR | &H10 | DSR signal changed |
EV_RLSD | &H20 | RLSD(CD) signal changed |
EV_BREAK | &H40 | Break detected |
EV_ERR | &H80 | Line status error |
EV_RING | &H100 | Ring detected |
EV_PERR | &H200 | Printer error |
EV_RX80FULL | &H400 | Receive buffer 80% full |
EV_EVENT1 | &H800 | Device event 1 |
EV_EVENT2 | &H1000 | Device event 2 |
eCommError (cSerialPort)
Communication errors from ClearCommError / ErrorOccurred / ReadCommErrors.
| Constant | Value | Description |
|---|---|---|
CE_RXOVER | &H1 | Receive buffer overflow |
CE_OVERRUN | &H2 | Character overrun |
CE_RXPARITY | &H4 | Parity error |
CE_FRAME | &H8 | Frame error |
CE_BREAK | &H10 | Break detected |
CE_TXFULL | &H100 | Transmit buffer full |
CE_PTO | &H200 | Parallel port timeout |
CE_IOE | &H400 | I/O error |
CE_DNS | &H800 | Device not selected |
CE_OOP | &H1000 | Out of paper |
CE_MODE | &H8000 | Mode error |
eModemStatus (cSerialPort)
Modem status from GetCommModemStatus / ReadModemStatus.
| Constant | Value | Description |
|---|---|---|
MS_CTS_ON | &H10 | CTS (Clear To Send) |
MS_DSR_ON | &H20 | DSR (Data Set Ready) |
MS_RING_ON | &H40 | RING (Ring Indicator) |
MS_RLSD_ON | &H80 | RLSD/CD (Carrier Detect) |
Last Updated: 2026-07-05