Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Serial Port Disconnect Issue

  • 05-02-2009 10:55am
    #1
    Closed Accounts Posts: 20


    Hi all.

    SCENARIO: I have Barcode Scanner plugged into the pc as serial device. I have a windows service written in C# which connects to the scanner and listens for new barcode scans.
    If the scanner is unplugged my code does not know about of this, it goes on thinking the scanner is still connected, nature of serial comms I! I need the code to know so that it can start listening again for the device.

    I notice that a registry key is added to : HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM and that key is removed as soon as the device is disconnected.

    I thought I could poll this key and watch for any changes.

    PROBLEM
    : If my C# code has connected to the device, and the device is then unplugged, this registry key does not get removed! Only after I have stopped the service does the key get removed :(.

    Any help or ideas regarding this would be much appreciated, I have been working on this one problem for two days and have got no where.

    Regards


Comments

  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    Is the scanner connected over Serial -> USB converter, then mapped to a virtual comport? Or is the scanner a USB one that maps to a virtual comport?

    Cause windows as such has no idea when a device is disconnected from a serial port.

    For USB devices which communicate via virtual comport the registry keys will be written/removed, as the devices are plugged in and out.

    You service can try implement a disconnection detection by looking at the data coming in or polling the device. If your code thinks something is wrong you could close the comport and try re-open it. If its been disconnected your code will not be able to get the handle.


  • Closed Accounts Posts: 20 Whackhead


    Just solved this! Finally!

    Polling the device works, basically I just write a 0 to it every few seconds, if the device is disconnected an exception is raised and I can then begin the reconnect procedure :D.
    Why on earth is this simple solution not documented on the net.

    Thanks for the reply


Advertisement