in reply to Win32::SerialPort - How do I detect if device is still connected?
Serial ports have basically three error conditions:
(1) is something that needs to be handled in the driver and the Win32::SerialPort module. I don't use Windows (and my coworker uses hardware that has an integrated USB port), so i'm not sure exactly how to detect and handle this.
Depending on the circumstances, you may or may not be able to detect (2). With modern USB Dongles and devices not using most of the serial lines, there might be no way to detect (by hardware) if the cable is plugged in, so you'd handle (2) like (3), see below. If it is a a classic serial connection with all the signals, you might be able to inquire the status of "Data terminal ready" and "Data Carrier detect" (i think) lines, but i rather doubt that your setup still has support for these.
For (3) and most likely (2), the only thing you can do is exchange some sort of keep-alive messages. Many serial protocols have a way of doing that, but this really is device specific. Maybe the protocol has some sort of lifeticks you can request from the remote device. Or you can try to request some sort of device status if you have not received data from that device in a certain timeframe. Some protocols also have dummy/no-operation commands. If the device has a way to identify itself (often implemented on replies to ENQ or DC* bytes, see your favourite ASCII table), you can also use that to check if the device is still working.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32::SerialPort - How do I detect if device is still connected?
by petro4213 (Acolyte) on Jul 04, 2024 at 12:48 UTC | |
by cavac (Prior) on Jul 04, 2024 at 14:09 UTC | |
by NERDVANA (Priest) on Jul 04, 2024 at 17:44 UTC |