MU Soapbox

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Muxify
    • Mustard

    A useful little script for USB IDs

    Code
    vid code generation usb pid rexx
    2
    2
    209
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WTFE
      WTFE last edited by

      Source code available here.

      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.rx is 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.rx as 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_MACROS environment 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 UNKNOWN because 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 lsusb and 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 1 Reply Last reply Reply Quote 1
      • Tyche
        Tyche Banned @WTFE last edited by Tyche

        @WTFE This brings back memories. I used to write REXX applications for IBM's TSO. 🙂

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post