A useful little script for USB IDs
WTFE last edited by
Sorry for my choice of "weird" programming languages but I haven't yet found a decent replacement for Rexx in general utility scripting yet. It's easy enough to read, though, that I'm sure it can be trivially ported to the more hipster-oriented languages.
build-usb.rxis a simple utility that you run by issuing
rexx build-usb.rx(or its equivalent on whatever OS you happen to be using). It will connect to the Linux kernel USB database and will download its contents, parsing all available vendor ID and product ID codes. (It specifically only looks for VIDs and PIDs, not everything in the database). It generates the file
USB.rxas output. This output file should be placed somewhere in your Rexx implementation's macro path. (For Regina on Linux that would be found in the
REGINA_MACROSenvironment variable. Other Rexx implementations will have their own equivalents.) When that is in place you have a new (external) function available that will let you look up a VID or a VID,PID pair to get a string back formatted for easy parsing. You can read the opening comment at the link above for full details, but as an example:
parse value USB(4321, 8765) with 'VENDOR:' vendor '->' 'PRODUCT:' product say vendor product
This snippet of code will print
UNKNOWNbecause there is no '4321' VID. :
parse value USB('1a86', '7523') with 'VENDOR:' vendor '->' 'PRODUCT:' product say vendor product
This code will print
QinHeng Electronics HL-340 USB-Serial adapter.
Or the following short script will read the output from
lsusband print the vendors and products of everything on your USB bus (in Linux):
address system 'lsusb' with output fifo '' do queued() parse pull 'Bus' . 'Device' . 'ID' vidpid . parse value vidpid with vid ':' pid . parse value USB(vid, pid) with 'VENDOR:' vendor '->' 'PRODUCT:' product say vendor product end
(Yes, I'm aware that lsusb already prints that information. It's just an example of use, not an actually useful script!)
Tyche Banned last edited by Tyche
@WTFE This brings back memories. I used to write REXX applications for IBM's TSO.