Linux, Java and USB

1.1k views Asked by At

Kind of a followup to this question, I have been able to:

Find the device for with which I am working, disconnect it from the kernel, and claim the (single) interface. . . and that's about as far as I can get.

When I try to write to the device (which is a custom wireless transceiver, not my own design), I get (when using LibUsb.bulkTransfer with the endpoint 0x00):

LibUsb.bulkTransfer(handle, (byte)0x00, bb, transfered, 5000);

an Input/Output error, and (when using LibUsb.bulkTransfer with the endpoint 0x81):

LibUsb.bulkTransfer(handle, (byte)0x81, bb, transfered, 5000);

a TimeOut error.

I'm pretty sure I have absolutely NO idea what I'm doing here (which doesn't help my position), and this is way deeper than I am accustomed to going as far as communicating with devices on a lower level (the most I've done is interop with .Net).

I've seen the lsusb command and executed it and gotten... a lot of stuff, and I can recognize some of it, but most of it I'm kind of lost with and was hoping for someone to hold my hand, or point me to a sort of... USB for Dummies guide that might help me figure out what I need to do.

The end result (ideally) will be a Java package that allows cross-platform communication with the device without any sort of tinkering on behalf of the end-user (and by cross-platform I mean, windows, linux and mac, which is why I'm using the java4usb java library).

Where I am right now is, using the output from the lsusb command, I'm hoping to be able to send commands from the transceiver to the external device with which it communicates. (basically it sends commands to a device connected to an LED that can turn the LED on and off, and make it flash, and it also can receive commands from that device and respond accordingly to them, but baby steps).

The lsusb output you can find here (it's quite verbose, and I didn't want to flood the question with more than necessary). Any help or direction would be tremendously appreciated.

EDIT: A bit more research reveals (from the lsusb output) that the 0x81 endpoint is an interrupt type. Putting 2 and 2 together lead me to the conclusion that I wanted neither a bulk transfer nor a control transfer but an interrupt transfer:

  Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x81  EP 1 IN
    bmAttributes            3
      Transfer Type            Interrupt
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0002  1x 2 bytes
    bInterval

LibUsb.interruptTransfer(handle, (byte)0x81, bb, transfered, 1000);

Unfortunately I'm still getting a Timeout error.

EDIT: Some more information is needed:

It has been suggested for Synchronous control (which is fine for half of what I need to do) that I should use the usb4java.LibUsb controlTransfer method, which is fine but there are several parameters that need to be filled, and I do not know what it is with that they need to be filled:

public static int controlTransfer(DeviceHandle handle, //I know this.
              byte bmRequestType, //<--- What goes here?
              byte bRequest,      //<--- What goes here?
              short wValue,       //<--- What goes here?
              short wIndex,       //<--- What goes here?
              ByteBuffer data,    //<--- What goes here?
              long timeout)       //<--- What goes here?

Any and all direction to the answer to what I need to populate these fields with would be a great help and greatly appreciated.

0

There are 0 answers