Ports
May 18, 2013, 11:06:34 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Pages: [1]
  Print  
Author Topic: Detecting a device connected to PC's COM1  (Read 4339 times)
JohnM
Member
*
Posts: 2


« 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:
   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
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1625


WWW
« 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
Logged
JohnM
Member
*
Posts: 2


« 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

Logged
mdlayt
Member
***
Posts: 40


« 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.

 
Logged
GlennP
Frequent Contributor
****
Posts: 126


« Reply #4 on: March 16, 2011, 12: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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!