Verify if a COM port is connected or not

2

Is it possible via the line of code to check whether a COM port is connected or not?

Analyze: I have a program POS (Point of Sale) where it has the integration with SiTef, through a PinPad (card machine) and for it to work, the PinPad must be connected to a COM port.

PinPad Online:

Now, in order to make the system more robust and avoid exception when trying to perform the procedure with PinPad , if it is not connected, I would check via the line of code if it is or not connected and assign this check in the respective events that do the integration.

    
asked by anonymous 02.01.2018 / 19:19

1 answer

1

It is not possible to know if the connector is plugged in, but most of the equipment is to monitor the CTS signal that is used for data flow control.

if(port.CtsEnable)
{
}

If the hardware manufacturer is not using this port, then another option would be to send a status request command through the port and check for a possible response. Remember that if the device is disconnected, it will have the same effect as when disconnected.

    
02.01.2018 / 19:44