Created
August 5, 2016 02:41
-
-
Save jhgorse/968bfab268c2837f76b20470d6678c52 to your computer and use it in GitHub Desktop.
Perl Device::USB exploration and fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://search.cpan.org/~gwadej/Device-USB-0.36/lib/Device/USB.pm#SYNOPSIS | |
# https://github.com/gwadej/perl-device-usb | |
# cpanm install Device::USB | |
# bash$ cpanm --local-lib=~/.perl5 local::lib && eval $(perl -I ~/.perl5/lib/perl5/ -Mlocal::lib) | |
use lib ("~/perl5/lib/perl5/darwin-thread-multi-2level"); | |
use Device::USB; | |
my $usb = Device::USB->new(); | |
# 0 CLASS_PER_INSTANCE | |
# 3 CLASS_HID - none seen? Darwin does not share this at all http://www.libusb.org/ticket/33 | |
# 9 CLASS_HUB | |
# 255 CLASS_VENDOR_SPEC | |
my @devices = $usb->list_devices_if( | |
sub { | |
$_->bDeviceClass() == Device::USB::CLASS_PER_INSTANCE | |
# || $_->bDeviceClass() == Device::USB::CLASS_HUB | |
# || $_->bDeviceClass() == Device::USB::CLASS_VENDOR_SPEC | |
} ); | |
my $dcount = @devices; | |
print "$dcount Device::USB::CLASS_CLASS_PER_INSTANCE (0) \n"; | |
foreach $a (@devices) { printf "%04X:%04X %02x Mfg: %-12s P: %s\n", $a->idVendor(), $a->idProduct(), $a->bDeviceClass(), $a->manufacturer(), $a->product(); } | |
my $dev = $usb->find_device( 0x05AC, 0x024F ); # device | |
print "\nQLAB Irradiance sensor device:\n$dev\n"; # Not an HID often so that userland gets a chance | |
printf "Device: %04X:%04X Class %04X\n", $dev->idVendor(), $dev->idProduct(), $dev->bDeviceClass(); | |
$dev->open(); | |
print "Manufactured by ", $dev->manufacturer(), "\n", | |
" Product: ", $dev->product(), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment