Reputation: 31
I am currently fool-proofing my code for connecting to a device though a serial port on a PC. Currently, though, if the user is to connect to this device when it is powered off, it will create a serial port object from a port chosen by user, and open it. It will then proceed to test, and fail, communication with this device. If I power up the device after this has happened the port will be stuck open and I am unable to use it until I restart my application.
I have tried to close the port in various ways and places within my code but it remains stuck until the application itself is re-opened.
How can I fix or prevent this problem?
Upvotes: 0
Views: 463
Reputation: 31
Posting back. The answer I found after much testing was to use the object.close(). I used an event handler for the current window saying if it closes, which it will when it fails to connect to device, run a function that will ensure the port is closed before user attempts to reconnect.
Upvotes: 1