Page 1 of 1

Connecting to USB Serial Device

Posted: Tue Feb 20, 2024 9:44 am
by theSuess
I'm porting an existing tool to the switch and the last piece of the puzzle is communicating with a device attached to the USB port. The existing implementation supports either libserial or libusb, both of which seem to be incompatible with the switch.

I think I should be able to rewrite the communication lib using usbhs, but I can't even get the switch to discover the device at all.
My current minimal code looks like this:

Code: Select all

memset(interfaces, 0, sizeof(interfaces));
memset(&filter, 0, sizeof(filter));
filter.Flags = 0
rc = usbHsQueryAllInterfaces(&filter,interfaces,sizeof(interfaces),&total_entries);
if (R_FAILED(rc)) printf("querying interfaces: 0x%x\n", rc);
if (R_SUCCEEDED(rc)) printf("queried interfaces. Found %d\n",total_entries);
When running this on hardware, no device is detected. I've tried multiple devices with no difference in outcome

Am I approaching this the right way, or is there a better way to talk to USB devices?

Re: Connecting to USB Serial Device

Posted: Tue Feb 20, 2024 2:45 pm
by WinterMute

Re: Connecting to USB Serial Device

Posted: Tue Feb 20, 2024 3:27 pm
by theSuess
Sadly, that didn't work either in my case. I tried matching against the VID/PID with no results.

I'm not sure if I got the right values, so I'd like to just dump everything the switch sees - Is it possible to build a filter which matches almost every device?

Re: Connecting to USB Serial Device

Posted: Tue Feb 20, 2024 8:32 pm
by WinterMute
You could try using UsbHsInterfaceFilterFlags_bcdDevice_Min for flags & set bcdDevice_Min=0 - that should pick up anything the system hasn't claimed for itself.

Re: Connecting to USB Serial Device

Posted: Wed Feb 21, 2024 6:09 pm
by theSuess
Found my issue.... I had sys-con loaded which claims all USB devices... Thanks for the help, learnt a lot about USB and the switch while debugging this. Now to actually talking to the device...