PORTS Forum
Ports and Interfaces => Serial Ports => Topic started by: JohnM on December 02, 2010, 11:52:15 am
-
Coding in PowerBasic, I can tell if the port was opened or not by executing this code:
CommPort$ = "COM1"
Comm Open CommPort$ As #CommBuf
If ErrClear Then Exit Function ' Exit if port cannot be opened
BUT I ALSO want to detect if there's a device connected to that port (eg, a modem, printer, data collector, phone box, etc.), or else report "Nothing's connected to port: " & CommPort$
I don't want to mistakenly interpret a "non-response" from an existing device to be "no device is present", or to incorrectly interpret a long timeout as "proof of non-existence"...
Is there a test that is ALWAYS able to detect when there is no device connected? (For my situation, a connected device that is not powered up is considered "not connected".)
Thanks for any guidance you can provide,
-John
-
There is no universal way to detect a connected device on a serial port. If you're writing the device firmware, you can define a device-specific way. For example, the device can wait for an initial "space-bar" code from the remote end and return an acknowledgment message
-
Thanks, Jan,
I've been searching the internet and reading all night, and I've prety much come to the same conclusion: unless the device is sending out "I'm alive" signals (or something that can be so interpreted), my application program cannot tell it's there...
-John
-
I don't know if your reading included a Plug and Play spec.
It has been a while since I looked at PNP, but my guess is for that class of devices, there is no problem reliably (and without harm) checking for device present.
Obviously this isn't all devices, but is probably more than 99% of devices designed to work with Windows in the last 15 years.
-
Hi,
I think it more depends on what is connected, most serial devices wait until they get a signal before they reply. USB can dynamically detect a device via Enumeration.... If your device is a Serial Device ie not USB the device it self has to asked if it is there... If you have multiple devices that can be connected it might be easier if less code pretty to open the port and try to talk to one device if that device does not answer back, close the port and open it again (if the settings are different) and try to talk to the next. I did the same a while back and 'Hero' status was granted that some ATE didn't have to removed.
Glenn