List USB devices from BASIC
Leo Smiers (245) 56 posts |
For a little project I need to find the usb descriptor (USBxx) for a USB device. |
Leo Smiers (245) 56 posts |
Just to bump this one up. Is my question to simple, to hard, not understood or impossible to answer? |
Rick Murray (539) 13851 posts |
Look at Service Calls. One of them (use OS_ServiceCall) will return a linked list of all connected USB devices, however note that it is your responsibility to free all of the blocks as you walk the list (and once you find the device you are interested in, keep on going until all blocks are freed). |
Rick Murray (539) 13851 posts |
https://www.riscosopen.org/wiki/documentation/show/OS_ServiceCall https://www.riscosopen.org/wiki/documentation/show/Service_USBDriver https://www.riscosopen.org/wiki/documentation/show/Service_USBDriver%201 |
Leo Smiers (245) 56 posts |
Rick thank you for your help. I now have a neat little BASIC program that lists the connected usb devices. However that is not what I am looking for. I need a way to get to the description field as shown in the output of usbdevices. This is so I can find match the device by the description to the USB device. Any more pointers? BTW It is great fun to re-learn all the BASIC skills that I have lost over the years. |
Leo Smiers (245) 56 posts |
To follow up on my own thread. |
Rick Murray (539) 13851 posts |
I read your message earlier, but didn’t fancy replying using a phone while trying to eat a Big Mac. What it looks like you need, which USBDescriptors should guide you to, is to walk into the Device Descriptors block, after the USBServiceCall block (+32…) to find the USB Device Descriptor, part of which is the iProduct string; but note that a zero (NULL) is a valid index, meaning there is no string description. |
John Williams (567) 768 posts |
Is this a new healthy-eating option? Isn’t he on Casualty |
Rick Murray (539) 13851 posts |
I read your message earlier, but didn’t fancy replying using a phone while trying to eat a Big Mac. Somehow I doubt that… ;-)
No idea. The last time I watched seriously was when Duffy was in it. I briefly watched it on and off again a while back with a dark haired woman that often wore a black pinafore dress. She got shot in the back, which is I guess one of the better ways to bow out of that series. I saw part of it recently. Can’t believe Charlie is still in it. Shouldn’t they have a spin off series set in a nursing home by now? Don’t watch broadcast TV much these days; I mostly just watch a few animé series, but don’t seem to have as much free time as I used to. Tonight I’ll be watching Cold Eyes. I just hope the subtitles were written by a person, not a machine! Edit: Thanks to Wikia and looking through the entire cast, that woman I mentioned – Selena. http://i82.photobucket.com/albums/j276/JB-Casualty/Selena/Character-NathanSelenaMaggie.jpg Would have saved me a lot of time if she’d been called Alice or something at the start of the alphabet. Speaking of which, Alice was cute. |
Chris Mahoney (1684) 2165 posts |
It’s very healthy compared to some of these! |
Neil Fazakerley (464) 124 posts |
When I saw the title of this thread I thought it would provide just the info I was after. Having read through it though, I’m none the wiser. |
Steve Pampling (1551) 8172 posts |
From his comments above I’d say Leo has some BASIC code. |
Rick Murray (539) 13851 posts |
Here’s something I put together. May be wrong in loads of ways, but seems to work for me…
The output is: *enumdevs USB1 Synopsys DWC OTG root hub &00000000 USB2 &04249514 USB3 &0424EC00 USB4 Prolific Technology Inc. USB-Serial Controller &067B2303 USB5 Logitech USB-PS/2 Optical Mouse &046DC03D USB6 USB USB Keykoard &1C4F0002 Yes, “Keykoard” really is like that. Cheap Chinese Crap. ;-) |
Tristan M. (2946) 1039 posts |
FWIW I just tried your listing on my Pi B. Works fine for me. e: |
Neil Fazakerley (464) 124 posts |
Thanks Rick, I’ll give it a go. |
Leo Smiers (245) 56 posts |
My website might be dusty, but I am not (yet). I have a BASIC program to communicate with a CodeBug. This contains code to find the USB port depending on the vendor en device Id’s. |
Neil Fazakerley (464) 124 posts |
Unfortunately, when I run the above code I get no output. num% and where% return 0 and 1, then 1 and 2, followed by the usual ‘click mouse to continue’. |
Colin (478) 2433 posts |
If you want to just find a device using a vendor Id – which you can get from ‘usbdevices’ and ‘usbdevinfo’ try
which you call like this
note -1 means you don’t care what the version is |
Neil Fazakerley (464) 124 posts |
Thanks Colin – got that working fine. |
Colin (478) 2433 posts |
does that help? It’s untested but should work. The servicecall returns a list all the known usbdevices including all of their descriptors – if you run my !usbdescriptors program you see all the info available for each item in the list. item% is an item in list% ie a block of data containing information about a single device. You could use
If you want to do complex code with the list you have to remember to delete any device list made with FNusb_makeDeviceList with PROCusb_deleteDeviceList when you are finished with the list. |
Neil Fazakerley (464) 124 posts |
Many thanks Colin. I’ll have a play with it tonight. |
Leo Smiers (245) 56 posts |
As promised. Here is a function to find the usb device from the vendor and product code.
You can use this as follows to open the read and write channels
To read do
To write do
|
Leo Smiers (245) 56 posts |
One click is enough |
Neil Fazakerley (464) 124 posts |
My thanks to Rick, Colin and Leo. I now have some suitable code working with my project. |