1

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.

Community
  • 1
  • 1
Will
  • 3,413
  • 7
  • 50
  • 107
  • If you want to do true cross-platform communication you can't limit yourself to Linux/Mac/Windows – Good Person May 20 '14 at 21:31
  • Okay so then I'm going for pseudo cross-platform communication. Also, whomever gave the -1, care to explain? – Will May 20 '14 at 21:36
  • If I were you, I would target POSIX platforms + windows. That would be a lot better – Good Person May 20 '14 at 21:38
  • I can't even begin to pretend to know what that is. The lowest level development I've done (with any level of practicality) was C++. – Will May 20 '14 at 21:46
  • POSIX is a common API that many unix-like systems (osx, Linux, *BSD, etc.) implement. Things like open(2), read(2), etc. come from there. libusb is implemented on top of this. I mainly trying to get you to not think of "linux" as the only *nix – Good Person May 20 '14 at 23:14
  • Okay cool thanks... is there a posix for dummies somewhere? – Will May 21 '14 at 00:30
  • USB for dummies : [this one is not bad](http://www.beyondlogic.org/usbnutshell/usb1.shtml). You hesitate between control transfer and interrupt transfer : all devices have a control endpoint (endpoint 0), it is not shown by lsusb. This endpoint address 0x81 is an IN endpoint, it is to read data from the device. If you want to send commands to the device, you probably want a control transfer. – Leiaz May 21 '14 at 11:54
  • Thanks. So then, for what I'm doing I would want to do a LibUsb.FillControlTransfer, and populate the EndPoint address with 0x00 (I think?) – Will May 21 '14 at 15:06
  • Or the synchronous one [controlTransfer()](http://usb4java.org/apidocs/org/usb4java/LibUsb.html#controlTransfer%28org.usb4java.DeviceHandle,%20byte,%20byte,%20short,%20short,%20java.nio.ByteBuffer,%20long%29). You don't need to give the address of the control endpoint, it is always 0. – Leiaz May 21 '14 at 16:06
  • Synchronous would be great for when I actually need to send a command from the device to the wireless devices with which it communicates. However there are several questions that I have regarding the control transfer method described by your link (See Edit, and thanks for your help). – Will May 21 '14 at 16:29
  • I don't know that device you are trying to use, and I am not at all an expert, so I won't be very useful for the specifics. Those parameters are described [here](http://www.beyondlogic.org/usbnutshell/usb6.shtml#SetupPacket), outside of the standard usb requests, it depends on the class of device or can be vendor specific. You have a HID device, so *perhaps* you want the HID class specific request : SET_REPORT (and perhaps using a HID API would simply things here). Type of report, data, would depend on the command. What kind of documentation do you have about the device ? – Leiaz May 21 '14 at 18:31
  • Not enough. The company that made it for my boss were kind of stingy with that. Beyond the lsusb output I don't have a lot. i know that when it sends data it sends out a 6 byte packet starting and ending with zeroes, and that incoming data it expects a packet of 3 bytes. – Will May 21 '14 at 18:36
  • any book/tutorial on Unix programming will cover POSIX. http://pubs.opengroup.org/onlinepubs/9699919799/ is a great reference (though not a tutorial) – Good Person May 21 '14 at 20:10

0 Answers0