There's good high-level advice in other answers, but from a practical POV it's pretty simple. There are two control inputs (DSR and CTS) and two control outputs (DTR and RTS). DTR is on pin 4 (9-pin version) and RTS is on pin 7. DSR / CTS are pins 6 and 8.
Place a Comm Port object on a VB form, and set .CommPort
to the number of your port. For pure logic control purposes it doesn't matter what .Settings
(baudrate etc) you use because you won't be sending and receiving any serial data, so just accept the defaults.
Set .PortOpen = True
, then change the DTR and RTS outputs by setting .DTREnable
/ .RTSEnable
to true or false as required. You should set these False at design time to avoid false triggering. Be aware that these lines may be toggled by the system when the PC reboots.
You can poll the .CTSHolding
and .DSRHolding
properties to detect changes on those inputs, or react to the .OnComm
event, which will get signaled when there's a change in either one. You still have to sort out which one caused the event, but that's just a Select Case.