0

I'm current working with this C++ library - https://github.com/wjwwood/serialv- to read a COM port device on Windows.

The application appears to work well, but I've encountered a strange edge case.

When I plug in the device, before starting the application, the application will work as expected, but when there's no device available, I poll the COM ports for new connections. If a new connection is found, the application appears to pick up the hotplugged device, but the stream appears to be corrrupted in someway.

If, however, I "serial::close()" the device (see here - http://wjwwood.io/serial/doc/1.1.0/classserial_1_1_serial.html#afbe59407e718bc3d22ea4a67b304db6c) and reopen it, the device works as intended.

To workaround this, I currently capture 12 seconds of the COM port stream, and if it's corrupted, I close and reopen the hotplugged device.

This feels like quite a nasty hack, but I also suspect that I'm not the only one to have encountered this problem.

Are there more efficient solutions out there? Or is this just an RTFM moment?

Charlie
  • 4,197
  • 5
  • 42
  • 59
  • Which connection is hotplugged, between device and serial port, or between serial port (probably a USB converter) and computer? – Ben Voigt Feb 13 '15 at 20:30
  • To be precise about it, I'm plugging an RF dongle into the USB port of a Windows machine. – Charlie Feb 13 '15 at 20:46
  • So the COM port itself is actually being added and removed. Does that driver perform serial enumeration? Can it be disabled? (By default, new serial ports are automatically tested to see whether the data looks like serial mouse data -- this can cause significant problems with devices that aren't mice) – Ben Voigt Feb 13 '15 at 20:48
  • Driver or library? And if by enumeration, you mean a a list of all available serial ports, then yes. I use a static class method (serial::list_ports() - ) to determine what's available, and then iterate through that list... So now I see your point... Do you mean I can't just assume that first device in that list is the RF dongle? – Charlie Feb 14 '15 at 00:25
  • 1
    No, I mean `serenum.sys` If it is loading, it's doing this to your RF device: http://blogs.msdn.com/b/doronh/archive/2006/11/13/what-is-the-serial-enumeration-protocol.aspx And see https://msdn.microsoft.com/en-us/library/windows/hardware/ff547040(v=vs.85).aspx Basically, if you have a COM port that isn't a physical RS-232 connector, you should try to disable the serenum.sys device detection. – Ben Voigt Feb 14 '15 at 00:28
  • I think I understand. I'd have to make a change to the device driver .inf file, right? I'm not sure if I can do that. Failing that, would you consider an application level solution to be a sensible approach? – Charlie Feb 14 '15 at 01:57
  • A registry change should do it for devices that have already been seen by Windows, changing the inf will do it for devices added in the future (note that by "added" I'm not counting reattaching a device, that just transitions between "not present" and "present" state), but editing the inf will also void the signature. So I'd use the registry method at least long enough to find out if that is your problem. – Ben Voigt Feb 14 '15 at 02:00
  • The registry change appeared not to work for me. I followed the instructions found here - http://stackoverflow.com/questions/9226082/device-misdetected-as-serial-mouse - taking care to edit both the seremouse and serenum values to 4 (disable at startup, I think) but it does not look like it's changed the devices' behaviour. – Charlie Feb 17 '15 at 01:32

0 Answers0