[Rxtx] RxTx usb support

Kustaa Nyholm Kustaa.Nyholm at planmeca.com
Mon Mar 1 07:02:57 MST 2010


> So what do you think? Does USB access fit into the RxTx project scope?

I don't think rxtx should be expanded to embrace anything beyond what
Javacomm 'supports'. So some other project or a new project would be
better. In a way libusb project would be 'natural' place for language
wrappers for libusb library. This of course reflects my view that
the libusb is first and foremost a cross platform usb API which just
happens to be written in C.

Further in my view the Java wrapper should reflect the usblib API
C API as closely as possible not to introduce object orientation
to the procedural API. I've done this with libusb 0.1 using JNA,
which was a trivial two hour exercise with no C code involved accross all
JNA supported platforms and this approach allows leveraging on all the
example code and documentation with just trivial changes.

Here is what it looks like for libusb 0.1:

public interface LibUSBInterface extends Library {
    void usb_init();
    int usb_find_busses();
    int usb_find_devices();
    USB_bus usb_get_busses();
    String usb_strerror();
    USB_dev_handle usb_open(USB_device dev);
    int usb_close(USB_dev_handle dev);
    int usb_set_configuration(USB_dev_handle dev, int configuration);
    int usb_claim_interface(USB_dev_handle dev, int interfce);
    int usb_release_interface(USB_dev_handle dev, int interfce);
    int usb_set_altinterface(USB_dev_handle dev, int alternate);
    int usb_resetep(USB_dev_handle dev, int ep);
    int usb_clear_halt(USB_dev_handle dev, int ep);
    int usb_reset(USB_dev_handle dev);
    int usb_set_debug(int level);
    int usb_detach_kernel_driver_np(USB_dev_handle dev, int interfce);
    int usb_get_driver_np(USB_dev_handle dev, int interfce, byte[] name, int
namelen);
    int usb_get_string(USB_dev_handle dev, int index, int langid, byte[]
buf, int buflen);
    int usb_get_string_simple(USB_dev_handle dev, int index, byte[] buf, int
buflen);
    int usb_get_descriptor_by_endpoint(USB_dev_handle udev, int ep, byte
type, byte index, byte[] buf, int size);
    int usb_get_descriptor(USB_dev_handle udev, byte type, byte index,
byte[] buf, int size);
    int usb_bulk_write(USB_dev_handle dev, int ep, byte[] bytes, int size,
int timeout);
    int usb_bulk_read(USB_dev_handle dev, int ep, byte[] bytes, int size,
int timeout);
    int usb_interrupt_write(USB_dev_handle dev, int ep, byte[] bytes, int
size, int timeout);
    int usb_interrupt_read(USB_dev_handle dev, int ep, byte[] bytes, int
size, int timeout);
    int usb_control_msg(USB_dev_handle dev, int requesttype, int request,
int value, int index, byte[] bytes, int size, int timeout);
}

I would expect this could be done easily for 1.0 too. Doing the JNA/JNI
is not the difficult part, getting a cross platform USB library is,
so far only libusb 0.1 has delivered but the recent activity on 1.0
project seems very encouraging.

But this is the wrong list for this sort of discussion.

br Kusti







More information about the Rxtx mailing list