Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix USB interface on macOS #193

Merged
merged 3 commits into from
Jul 18, 2024
Merged

Conversation

parasyte
Copy link
Contributor

When the usbportinfo-interface feature is enabled on macOS, the UsbPortInfo::interface is always None. A careful reading of https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/USBBook/USBOverview/USBOverview.html#//apple_ref/doc/uid/TP40002644-BBIDGCHB indicates that device matching or interface matching needs to be considered on a per-application basis. This PR switches the class to IOUSBHostInterface when the feature is enabled, allowing the interface number to be returned.

I am not familiar with macOS, but this seems like a fair compromise without changing the serialport APIs to make a distinction between searching for devices and searching for interfaces.

@sirhcel
Copy link
Contributor

sirhcel commented Jul 12, 2024

Thank you for spotting this @parasyte and for preparing this PR!

The IOUSBHostDevice class does not provide interface information but at a first glance does the IOUSBHostInterface class provide everything for UsbPortInfo. Since the feature gate usbportinfo-interface is scheduled to disappear with the next major release and the field UsbPortInfo::interfaceto become generally available.

After weighing this for while: Shouldn't looking up the information from IOUSBHostInterface instead from IOUSBHostDevice be the default?

@parasyte
Copy link
Contributor Author

So, again I need to be transparent that I don’t know Mac APIs. But my interpretation of the docs suggests that the Device and Interface classes should be used when you want either device or interface information. And that is going to be an application’s concern, not the library’s.

So, while it does appear, at least empirically, that the Interface class gives you everything you want… I’m not sure I would rely on that. They are different things for a reason. I suspect some devices might be capable of exposing information differently about itself (e.g. through the Device class) and about all of its interfaces (Interface class).

All in all, I’m in favor of just using the Interface class to simplify things. It can always be changed later if it breaks anything, right?

parasyte and others added 2 commits July 18, 2024 22:49
USB interface number information is currently missing macOS (with
feature usbportinfo-interface). The required information is not provided
in IOUSBHostDevice but along with all other information of interest in
IOUSBHostInterface.

As it is planned to remove the feature gate for  UsbPortInfo::interface
with the next major release, IOUSBHostInterface is the dict to use for
looking up information for USB serial ports. There is no point in using
different lookups in the meanwhile.
@sirhcel
Copy link
Contributor

sirhcel commented Jul 18, 2024

So, again I need to be transparent that I don’t know Mac APIs. But my interpretation of the docs suggests that the Device and Interface classes should be used when you want either device or interface information. And that is going to be an application’s concern, not the library’s.

My knowledge of the macOS APIs is limited. But as USB serial device are - to the extend of my understanding - are always accessed through the endpoints specified by an USB interface, looking up things from the perspective of an USB interface seems the right thing to do to me here.

So, while it does appear, at least empirically, that the Interface class gives you everything you want… I’m not sure I would rely on that. They are different things for a reason. I suspect some devices might be capable of exposing information differently about itself (e.g. through the Device class) and about all of its interfaces (Interface class).

This might be the case but as all information we are currently interested in is (also) provided through IOUSBHostInterface, this looks good for me to go.

All in all, I’m in favor of just using the Interface class to simplify things. It can always be changed later if it breaks anything, right?

Great! As we are not changing/breaking the public API here, we are fine to roll out a patch release if things don't work out as expected.

@sirhcel sirhcel merged commit 5039050 into serialport:main Jul 18, 2024
30 checks passed
@parasyte parasyte deleted the fix/macos-usb-interface branch July 19, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants