Author Topic: Detecting a device connected to PC's COM1  (Read 16633 times)

JohnM

  • Member
  • ***
  • Posts: 2
Detecting a device connected to PC's COM1
« 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:
Code: [Select]
   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

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Detecting a device connected to PC's COM1
« Reply #1 on: December 03, 2010, 10:13:49 am »
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

JohnM

  • Member
  • ***
  • Posts: 2
Re: Detecting a device connected to PC's COM1
« Reply #2 on: December 03, 2010, 11:49:58 am »
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


mdlayt

  • Member
  • ***
  • Posts: 40
Re: Detecting a device connected to PC's COM1
« Reply #3 on: December 10, 2010, 03:45:52 pm »
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.

 

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Detecting a device connected to PC's COM1
« Reply #4 on: March 16, 2011, 01:31:15 pm »
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