serialport / serialport-rs

A cross-platform serial port library in Rust. Provides a blocking I/O interface and port enumeration including USB device information.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

windows: UsbPortInfo: Provide the same info about Manufacturer and Product name as POSIX

jcsxdev opened this issue · comments

EDITED (2024-01-06): updated 2. Improvement request topic about a workaround using the winapi crate.
EDITED (2024-01-01): updated 2. Improvement request topic about a workaround using the windows crate.

  1. Issue description
  2. Improvement request
  3. Others

1. Issue description

On POSIX systems, the UsbPortInfo returns custom Manufacturer and Product name linked to iVendor and iProduct attributes from Device Descriptor. In contrast, in Windows:

This is causing the following issue:

  • The Manufacturer and Product name information obtained from Windows is completely different from POSIX. If this information is used for device detection, the code will not be portable.

2. Improvement request

In Windows, the information must be obtained via DeviceIoControl. In a similar way to the lswinusb – a Rust library for listing USB Descriptors on Windows.

Workaround

This is a workaround that was developed using the lswinsub project, but using the winapi crate instead of the windows or windows-sys crate:

It can be tested using the iocontrol feature. Example:

  • cargo run --features iocontrol --example list_ports

But it is not a solution developed by someone who has experience with Rust and the Win32 API. This needs to be reviewed and/ or rewritten by someone with more experience.

3. Others

Additional information:

  1. The USBViewer program also uses DeviceIoControl:
  2. Python module pySerial also faces the same problem:

You are absolutely right. I would expect to get the same information on systems where the port enumeration returns anything at all.

Than you very much for pointing this out and your comprehensive research! My schedule is tight these days. But it looks like you are already working on implementing this and this looks good skimming through it. Awesome! :) Would you mind filing a PR when this works for you?

Than you very much for pointing this out and your comprehensive research! My schedule is tight these days. But it looks like you are already working on implementing this and this looks good skimming through it. Awesome! :)

Thank you for the feedback.

Would you mind filing a PR when this works for you?

No problem. I will file a PR when I complete some tests.

Example:

  • The tests I had performed worked under the following condition:

IMG01_CONDITION1

  • But they failed under the following condition:

IMG02_CONDITION2

I have made new changes to the iocontrol feature to fix this issue, but they haven't been tested yet.