ZigEmbeddedGroup / serial

Serial port configuration library for Zig
MIT License
53 stars 18 forks source link

[Windows] add support for port information #9

Closed lachlanm-git closed 11 months ago

lachlanm-git commented 11 months ago

This is an attempt to add serial port information (issue #8) . This is done iteratively via InformationIterator which will return a PortInformation struct for each serial port.

This PR only adds Windows support. It is (I thought) surprisingly convoluted to get things like the serial number.

I'm thinking perhaps something like a VCP is not handled well but I do not have a device to test. I have tested with devices using Windows CDC driver and FTDI.

Referenced implementations :


Note, I'm very fresh to Zig and I'm sure a lot of this code could be improved. So please, feel free to make edits or suggestions - it would be a good learning experience for me.

lachlanm-git commented 11 months ago

Here is some example output from running serial-list-info.exe. I found it useful to compare/test against "usbview.exe" and py -m serial.tools.list_ports --verbose (pyserial)

Port name: COM5

  • System location: \.\COM5
  • Friendly name: USB Serial Port (COM5)
  • Description: USB Serial Port
  • Manufacturer: FTDI
  • Serial #: FT1UKRMGA
  • HW ID: FTDIBUS\VID_0403+PID_6001+FT1UKRMGA\0000
  • VID: 0x0403 PID: 0x6001

Port name: COM4

  • System location: \.\COM4
  • Friendly name: USB Serial Port (COM4)
  • Description: USB Serial Port
  • Manufacturer: FTDI
  • Serial #: RC8DEXWRA
  • HW ID: FTDIBUS\VID_0403+PID_6001+RC8DEXWRA\0000
  • VID: 0x0403 PID: 0x6001

Port name: COM6

  • System location: \.\COM6
  • Friendly name: USB Serial Device (COM6)
  • Description: USB Serial Device
  • Manufacturer: Microsoft
  • Serial #: E6614104035C3C31
  • HW ID: USB\VID_2E8A&PID_0005&MI_00\6&C508D77&0&0000
  • VID: 0x2E8A PID: 0x0005

Port name: COM7

  • System location: \.\COM7
  • Friendly name: USB Serial Device (COM7)
  • Description: USB Serial Device
  • Manufacturer: Microsoft
  • Serial #: 0
  • HW ID: USB\VID_3473&PID_0001\0
  • VID: 0x3473 PID: 0x0001

Note, the thorny one is USB\VID_2E8A&PID_0005&MI_00\6&C508D77&0&0000. This requires iterating over parent nodes to extract the serial number.

ikskuh commented 11 months ago

Very cool, looks good so far!