Skip to content

cSerialPort Properties Reference

📋 Properties List

cSerialPort Properties

PropertyTypeAccessDescription
IsOpenBooleanRead-onlyWhether the serial port is open
PortNameStringRead/WritePort name, cannot be modified after opening
HandleLongRead-onlySerial port handle
ConfigcSerialConfigRead/WriteConfiguration object
LastErrorLongRead-onlyLast error code
LastErrorMsgStringRead-onlyLast error description
ReceivedCountLongRead-onlyCumulative received bytes
SentCountLongRead-onlyCumulative sent bytes
InBufferCountLongRead-onlyCurrent bytes in input buffer
OutBufferCountLongRead-onlyCurrent bytes in output buffer
CtsHoldingBooleanRead-onlyCTS signal status
DsrHoldingBooleanRead-onlyDSR signal status
RingHoldingBooleanRead-onlyRING signal status
CdHoldingBooleanRead-onlyCD/RLSD signal status
IsWaitingOnCtsBooleanRead-onlyWhether waiting on CTS
IsWaitingOnDsrBooleanRead-onlyWhether waiting on DSR
IsWaitingOnRlsdBooleanRead-onlyWhether waiting on RLSD
IsXoffHoldBooleanRead-onlyWhether paused by XOFF
IsXoffSentBooleanRead-onlyWhether XOFF has been sent
MonitoringBooleanRead-onlyWhether monitoring is active
PollIntervalLongRead/WritePolling interval(ms), 10~60000

cSerialConfig Properties

PropertyTypeDefaultDescription
BaudRateLong9600Baud rate
DataBitsLong8Data bits, 4~8
StopBitsLong0Stop bits
ParityLong0Parity
FlowControlLong0Flow control
DtrControlLong1DTR control mode
RtsControlLong1RTS control mode
ReadIntervalTimeoutLong50Read interval timeout(ms)
ReadTotalTimeoutMultiplierLong0Read per-byte timeout multiplier
ReadTotalTimeoutConstantLong100Read fixed timeout(ms)
WriteTotalTimeoutMultiplierLong0Write per-byte timeout multiplier
WriteTotalTimeoutConstantLong100Write fixed timeout(ms)
InBufferSizeLong4096Input buffer size(bytes)
OutBufferSizeLong4096Output buffer size(bytes)
XonCharByte&H11XON character
XoffCharByte&H13XOFF character
ErrorCharByte0Parity error replacement character
EofCharByte0EOF character
EvtCharByte0Event trigger character
NullDiscardBooleanFalseWhether to discard NULL bytes
AbortOnErrorBooleanFalseWhether to abort read/write on error
TXContinueOnXoffBooleanFalseWhether to continue sending after XOFF
ParityReplaceBooleanTrueWhether to replace characters on parity error

🔧 cSerialPort Properties Details

IsOpen

Whether the serial port is open.

vb
If sp.IsOpen Then
    Debug.Print "Serial port is open"
End If

PortName

Port name. Cannot be modified after opening, must close first.

vb
sp.PortName = "COM3"
sp.OpenPort
' sp.PortName = "COM4"  ' Error! Cannot change after opening
sp.ClosePort
sp.PortName = "COM4"     ' Can change after closing

Config

Configuration object, type cSerialConfig. Changes while port is open require calling ApplyConfig to take effect.

vb
' 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 applies

LastError / LastErrorMsg

Last Win32 error code and description. OpenPort returns False and sets LastError on failure.

vb
If Not sp.OpenPort("COM99") Then
    Debug.Print "Error code: " & sp.LastError
    Debug.Print "Error description: " & sp.LastErrorMsg
End If

ReceivedCount / SentCount

Cumulative send/receive byte count. Can be reset with ResetCounters.

vb
Debug.Print "Received: " & sp.ReceivedCount & " bytes"
Debug.Print "Sent: " & sp.SentCount & " bytes"
sp.ResetCounters

InBufferCount / OutBufferCount

Current byte count in input/output buffer.

vb
If sp.InBufferCount > 0 Then
    Debug.Print "Buffer has " & sp.InBufferCount & " bytes available"
End If

Signal Line Status Properties

PropertySignalDescription
CtsHoldingCTSClear To Send
DsrHoldingDSRData Set Ready
RingHoldingRINGRing Indicator
CdHoldingCD/RLSDCarrier Detect
vb
Debug.Print "CTS=" & sp.CtsHolding & " DSR=" & sp.DsrHolding
Debug.Print "RING=" & sp.RingHolding & " CD=" & sp.CdHolding

PollInterval

Monitoring polling interval in milliseconds, range 10~60000. Can be specified when calling StartMonitoring, or modified via property.

vb
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.

ConstantValueDescription
br110110
br300300
br600600
br12001200
br24002400
br48004800
br96009600Default
br1440014400
br1920019200
br3840038400
br5600056000
br5760057600
br115200115200Common high-speed
br128000128000
br256000256000Maximum supported
vb
cfg.BaudRate = br9600      ' Or br115200, br57600, br256000, etc.

DataBits

Data bits, range 4~8, throws error if out of range.

vb
cfg.DataBits = 8

StopBits

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.

vb
cfg.FlowControl = fcRtsCts   ' Hardware flow control RTS/CTS

DtrControl / RtsControl

DTR/RTS control modes. Use eDtrControl/eRtsControl enum: dcDisable(0), dcEnable(1), dcHandshake(2), rcToggle(3, RTS only).

Timeout Parameters

ParameterDescription
ReadIntervalTimeoutMaximum interval between two reads, return on timeout
ReadTotalTimeoutMultiplierPer-byte timeout multiplier
ReadTotalTimeoutConstantRead fixed timeout
WriteTotalTimeoutMultiplierWrite per-byte timeout multiplier
WriteTotalTimeoutConstantWrite 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)

ConstantValueWin32 ConstantDescription
ptNone0NOPARITYNo parity
ptOdd1ODDPARITYOdd parity
ptEven2EVENPARITYEven parity
ptMark3MARKPARITYMark parity
ptSpace4SPACEPARITYSpace parity

eStopBits (cSerialConfig)

ConstantValueWin32 ConstantDescription
sb10ONESTOPBIT1 stop bit
sb1_51ONE5STOPBITS1.5 stop bits
sb22TWOSTOPBITS2 stop bits

eDtrControl (cSerialConfig)

ConstantValueWin32 ConstantDescription
dcDisable0DTR_CONTROL_DISABLEDTR line disabled
dcEnable1DTR_CONTROL_ENABLEDTR line enabled
dcHandshake2DTR_CONTROL_HANDSHAKEDTR flow control handshake

eRtsControl (cSerialConfig)

ConstantValueWin32 ConstantDescription
rcDisable0RTS_CONTROL_DISABLERTS line disabled
rcEnable1RTS_CONTROL_ENABLERTS line enabled
rcHandshake2RTS_CONTROL_HANDSHAKERTS flow control handshake
rcToggle3RTS_CONTROL_TOGGLERTS toggle mode

eFlowControl (cSerialConfig)

ConstantValueDescription
fcNone0No flow control
fcXonXoff1Software flow control (XON/XOFF)
fcRtsCts2Hardware flow control (RTS/CTS)
fcDtrDsr3Hardware flow control (DTR/DSR)
fcRtsCtsAndXonXoff4Mixed flow control (RTS/CTS + XON/XOFF)

eCommEvent (cSerialPort)

Communication events for SetCommMask / WaitForEvent / PinChanged.

ConstantValueDescription
EV_RXCHAR&H1Character received
EV_RXFLAG&H2Event character received
EV_TXEMPTY&H4Transmit buffer empty
EV_CTS&H8CTS signal changed
EV_DSR&H10DSR signal changed
EV_RLSD&H20RLSD(CD) signal changed
EV_BREAK&H40Break detected
EV_ERR&H80Line status error
EV_RING&H100Ring detected
EV_PERR&H200Printer error
EV_RX80FULL&H400Receive buffer 80% full
EV_EVENT1&H800Device event 1
EV_EVENT2&H1000Device event 2

eCommError (cSerialPort)

Communication errors from ClearCommError / ErrorOccurred / ReadCommErrors.

ConstantValueDescription
CE_RXOVER&H1Receive buffer overflow
CE_OVERRUN&H2Character overrun
CE_RXPARITY&H4Parity error
CE_FRAME&H8Frame error
CE_BREAK&H10Break detected
CE_TXFULL&H100Transmit buffer full
CE_PTO&H200Parallel port timeout
CE_IOE&H400I/O error
CE_DNS&H800Device not selected
CE_OOP&H1000Out of paper
CE_MODE&H8000Mode error

eModemStatus (cSerialPort)

Modem status from GetCommModemStatus / ReadModemStatus.

ConstantValueDescription
MS_CTS_ON&H10CTS (Clear To Send)
MS_DSR_ON&H20DSR (Data Set Ready)
MS_RING_ON&H40RING (Ring Indicator)
MS_RLSD_ON&H80RLSD/CD (Carrier Detect)

Last Updated: 2026-07-05

VB6 and LOGO copyright of Microsoft Corporation