gdillen
Posts: 18
Joined: Sat Feb 01, 2014 11:36 am

Reading from USB port

Tue Feb 11, 2014 1:35 pm

I need to read continuous data streams from an USB connected device, can someone point me in the direction as where to look for to achieve this?
I already have Java 7 JDK on my Pi.

Thanks.

User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Re: Reading from USB port

Tue Feb 11, 2014 2:04 pm

You'll probably want to use serial communication. There is a lot of documentation out there about linking an Arduino to a Pi. I suggest starting there.

Good Luck!
Rich

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Reading from USB port

Fri Feb 14, 2014 12:27 pm

gdillen wrote:I need to read continuous data streams from an USB connected device, can someone point me in the direction as where to look for to achieve this?
I already have Java 7 JDK on my Pi.

Thanks.
If you want to talk directly to the USB device then your application needs to access the libUSB system libary on the Pi. If the device is a USB "HID" device then you can access the device in a slightly more convenient way using libHID.
The documenation for libusb is found at http://www.libusb.org/

if you are familiar with writing JNI code then its quite easy to "simply" write the JNI code in C and use it with your application in order to talk to the USB device.

there exist some projects that provide a java abstraction on top of libUSB thus you may want to use one of these projects if you do not feel comforable writing JNI code:
https://github.com/trygvis/javax-usb-libusb1
https://github.com/rtyley/JNA-USB


many USB devices got Linux drivers and may be best accessed using the linux device handlers.
for example GPS USBdevices gets mapped into regular Linux serial ports under /dev/tty*
USB harddrives gets mapped into regular Linux block device files under /dev/sd* just like scsi disks.
USB printers gets mapped into /dev/lp* files
and so on, thus it is rare that you need to talk directly to the USB device by writing your own driver in java using libUSB, for most devices you can talk to them by accessing the Linux device files.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

Return to “Java”