Check whether a COM port is connected or not

Asked

Viewed 568 times

2

It is possible via code line to check whether a COM port is connected or not ?

Analysis: I have a program PDV(Point of Sale) where the same has the integration with Sitef, through a Pinpad(cardboard machine) and for it to work, the Pinpad has to be connected in a COM port.

Pinpad Connected:

inserir a descrição da imagem aqui

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

1 answer

1


It is not possible to know if the connector is plugged, but in most equipment 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.