Comm32 Logo
Home Button   

Topic:   Timeouts on PortOpen

By: tleadbeaterPosted on: Mar 14 2010 at 05:37:50 PM
Is there any way to set a timeout when attempting to open a port when nothing is attached?

By: Support Posted on: Mar 15 2010 at 01:04:50 PM
You're trying to sense whether a device is attached to your com port ?

Assuming the port exists - If you open a port when nothing is attached then you won't get an error.

If your cable has a link from your DSR to the remote device's DTR (and the remote device sets its DTR on) then you will see a change in the state of the DSRHolding property when the remote device is connected/disconnected.

Maybe you could open the port and then wait a moment before checking the status of the DSRHolding property to decide if a device is attached.

Not all devices use DTR but you could also do a similar thing with the CTSHolding property.

Does that help ?

By: PaulPosted on: Mar 15 2010 at 01:37:12 PM
I had a similar requirement but I didn't have any of the RTS/CTS DTR/DSR lines connected so couldn't actually detect the other device.

So in my cable in the plug connected to my com port I made a short link between the DTR and DSR pins. Now I open my com port and then set DTREnable=True and then I read the state of the DSRHolding property - if it's true I know that my cable is connected to the com port (Then set DTREnable=False and check the DSRHolding again to confirm that it also went to false)

Obviously this doesn't tell me if the remote device is connected and powered up but at least I know there's a cable connected to my com port which was all I really needed to know.