sh4rif wrote:Hello folks
I got all the ideas but since this is not only my first ever embedded programming its my first ever raspberry pi programming.... so i want my job done within a minimum amount of time... because i only have mid of June this year to finish all my final year project... i have to split my time between my other modules and my final project... so if you kindly please advise me....
how to receive data and
how to send data back to that device
using USB ports, dosent matter if sending and receiving data direct to USB port or any other way... shortest and easiest.... and i have to do all the programming in Java as a requirement....
First you need to find out which kind of protocol is in use by your USB device. Try connect your device to the raspberry pi and then type dmesg
to see what the Linux kernel makes out of it. The USB devices usually fall into one of the following categories.
* a generic HID device
simply read and write, like from a text file, from the linux specific HIDRAW device files in
/dev/hidraw* http://www.mjmwired.net/kernel/Document ... hidraw.txt
these USB devices can also be interfaced by calling libhid or libusb directly using JNI from Java
* a HID device with known protocol ( mouse, keyboard, joypad )
the simplest is to read the events, like a text file, from the linux specific /dev/input/event* files
or use libhid/libusb directly using JNI from Java
* a USB device with known linux kernel driver like a printer or serial port.
for example a thermal labelprinter can be easily directly controlled from Java by writing to the
/dev/lp0 printer file http://labb.zafena.se/?category_name=gplable
this project runs fine on the raspberry pi if you have the usblp
kernel module loaded.
many devices ends up as a serial port, use the java rtxt library to talk to them or run a serial port to tcp/ip socket daemon like ser2net and then talk to the serial port by opening a network socket.
* a USB device with un-known linux kernel driver
these devices can only be interfaced by calling libusb using JNI from Java
If you need direct USB device access then I highly recommend you to issue calls using libUSB or libHID from Java using JNI, thats why I mentioned it three times already. It enable multi enpoint communication using custom data packet lenghts.
JNI Java Native Interface
is the only way to get the Java JVM to connect to C/C++ libraries like libUSB and libHID.
Writing your own Java JNI to interface libUSB is a quite small task because the libUSB interface is quite slim but still it can be error prone.
You can use libraries like Java Native Access, JNA
(internally using JNI and libffi) to create the C/C++ library binding from within java itself.
You may also look at using Gluegen
that can more or less write the JNI code for you if you supply it a config under which class name you want libusb and its functions to appear under on the Java side.
There do exist some libraries like jUSB but they have not been maintained for years. Gentoo have this package in its portage system. To my knowledge jusb is not packaged by debian but some debian users have got it to work.
<- some gentoo patches for jusb is found here