Monks,

I am trying to connect to a USB device plugged into my Ubuntu linux system. The command set is a set of 64 bytes with the first byte as the command. Command 0x02 is a version cmd and doesn't require any other information so the rest of the bytes can be 0x00. From the documents Bulk interface 4 ep7=IN ep8=OUT. It should send info (64bytes) which will contain the version.

I am getting a -22 error when reading or writing and not sure what I am doing wrong. Any assistance is appreciated.

(Note: when printing the endpoint out address I am getting bEndpointAddress of 8), bulk_write needs (endpoint, bytes, timeout)

#!/usr/bin/perl use Device::USB; use Data::Dumper; $idV = 0x0432; # VendorID changed to protect the innocent $idP = 0x4321; # productID changed to protect the innocent my $usb = Device::USB->new(); my $dev = $usb->find_device($idV, $idP); if (!defined $dev) { print "Unable to find device \n"; exit; } $dev->open(); $driver = $dev->get_driver_np(0); if (defined $driver) { print "connected to driver ($driver), releasing\n"; $res = $dev->detach_kernel_driver_np(0); } $res = $dev->claim_interface(0); if ($res == 0) { print "device claimed\n"; } $dev->set_configuration(1); my $cfg = $dev->config()->[0]; my $inter = $cfg->interfaces()->[4]; #epi=endpoint in, epo=endpoint out if (!defined $inter) { print "inter not defined\n"; } my $epi = $inter->[0]->endpoints()->[0]; my $epo = $inter->[0]->endpoints()->[1]; # string of hex values in pairs i.e. 02 00 00, 64 entries # cmd string is 0x02 followed by all 0x00 $mybuff = '02000000000000000000000000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +'; # convert string to bytestring my @hex = ($mybuff =~ /(..)/g); #grab pairs into @hex 02 00 etc my @dec = map { hex($_) } @dec; # convert to decimal my @byteArr = map { pack('C', $_) } @hex; # pack into bytearray my $bs = pack("b", @byteArr); #push back into a byte string format print "calling bulk_write\n"; $bWritten = $dev->bulk_write($epo, $bs, 5000); print "bWritten=($bWritten)\n"; my $readInfo; print "calling bulk_read\n"; $bRead = $dev->bulk_read($epi, $readInfo, 64, 5000); print "bRead=($bRead)\n"; print "readInfo=($readInfo)\n"; print "release interface 0\n"; $res = $dev->release_interface(0); print "claim release result = ($res)\n";
output:
connected to driver (snd-usb-audio), releasing device claimed calling bulk_write bWritten=(-22) calling bulk_read bRead=(-22) readInfo=() release interface 0 claim release result = (0)
I am seeing in syslog during this run, I am not sure if that means It did or did not properly claim it even through the claim response was ok
[2509634.708198] usb 2-1.7.7.2: usbfs: interface 0 claimed by usbfs wh +ile 'perl' sets config #1
Again thanks!
s&&VALKYRIE &&& print $_^q|!4 =+;' *|

In reply to How to use Device::USB to bulk_write/read from usb device by wulvrine

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.