tonino.dna 0 Newbie Poster

I am building a device connected to the serial port of my PC. I need to chect the signal level of the RTS and DCD lines.
How can I do that using MSCOMM?

thanks

tonino

Dani AI

Generated

Short answer: open the port with the MSComm control and read the modem-status properties. MSComm exposes properties you can poll or inspect from the OnComm event: use MSComm1.CDHolding to see DCD (carrier detect). RTS on the PC is an output you control with MSComm1.RTSEnable; if the remote device toggles its RTS that will appear on the PC as CTS, readable via MSComm1.CTSHolding. Always open the port (PortOpen = True) before reading these properties.

Example (polling in a Timer or test routine):

' open port first
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

' poll current states
Dim dcdState As Boolean
Dim ctsState As Boolean
Dim rtsState As Boolean

dcdState = MSComm1.CDHolding    ' DCD / RLSD input
ctsState = MSComm1.CTSHolding   ' PC CTS (remote RTS)
rtsState = MSComm1.RTSEnable    ' RTS asserted by MSComm

Notes and troubleshooting: check wiring (straight vs null-modem) because pin mapping determines which physical signal shows up where (DCD is pin 1, RTS pin 7, CTS pin 8 on a DB9). Hardware flow control or the control's handshaking can flip RTS automatically, so disable automatic handshaking if you need manual reads. Many USB-to-serial adapters do not fully implement modem lines; test on a true RS-232 port or verify the adapter/driver. If you need lower-level access, use the Win32 modem-status API (GetCommModemStatus) instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.