![]() |
This HowTo leverages the information in OpenSlugJavaInstallWorkaround and USB2Serial, in order to be able to access serial ports from Java (e.g. the javax.comm package) Starting with OpenSlug 3.10 Beta and using a Belkin F5U003 USB-232 Adapter After plugging in the adapter, 'cat /proc/bus/usb/devices' reveals the device T: Bus=03 Lev=02 Prnt=02 Port=03 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 P: Vendor=056c ProdID=8007 Rev= 1.10 S: Manufacturer=Belkin Components S: Product=USB-232 Adapter S: SerialNumber=BL3592 C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=belkin E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl=0ms E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl=8ms Package installation for hardware: ipkg install kernel-module-usbserial ipkg install kernel-module-belkin-sa depmod -a modprobe belkin-sa Confirm hardware detection and installation using 'lsmod' Module Size Used by belkin_sa 6916 1 usbserial 23632 3 belkin_sa and 'ls /dev/ttyUSB*' crw-rw---- 1 root dialout 188, 0 Aug 14 00:21 /dev/ttyUSB0 NOTE: at this point I rebooted to make sure detection was automatic on boot. Next, install Java (updates since OpenSlugJavaInstallWorkaround HowTo)wget http://ipkg.nslu2-linux.org/feeds/unslung/cross/classpath_0.91-1_armeb.ipk wget http://ipkg.nslu2-linux.org/feeds/unslung/cross/jamvm_1.4.3-1_armeb.ipk wget http://ipkg.nslu2-linux.org/feeds/unslung/cross/jikes_1.22-1_armeb.ipk wget http://ipkg.nslu2-linux.org/feeds/unslung/cross/zlib_1.2.3-1_armeb.ipk wget http://ipkg.nslu2-linux.org/feeds/unslung/cross/libstdc++_5.0.7-4_armeb.ipk ipkg install classpath_* ipkg install zlib_* ipkg install jamvm_* ipkg install libstdc++_* ipkg install jikes_* Serial Port software from "http://www.rxtx.org/"Using "Linux, Windows, Solaris, Mac OS rxtx-2.1-7-bins-r2.zip (Final)" which can be unzipped anywhere. The required jar file for any execution of serial port access is: RXTXcomm.jar (put in your classpath). The other files in this zip file are not required for execution. The pre-compiled library used by RXTXcomm.jar was located at: For Debian on NSLU2 (see http://www.nslu2-linux.org/wiki/Debian/HomePage ), the right pre-compiled library can be endian-little version at : ftp://ftp.qbang.org/pub/rxtx/ToyBox/2.1-7-build1/Linux/glibc-2.3.5/arm-xscale-linux-gnu/librxtxSerial.so This file should be placed at: /opt/lib/classpath/librxtxSerial.so in order to be found by jamvm A simple test file to show detection of the serial ports:
import java.util.*;
import gnu.io.*;
public class Test {
public static void main(String[] args) {
Enumeration en = CommPortIdentifier.getPortIdentifiers();
while (en.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier) en.nextElement();
System.out.println("name=" + cpi.getName());
}
}
}
Compile Test.java /opt/bin/jikes -classpath /opt/share/jamvm/classes.zip:/opt/share/classpath/glibj.zip:RXTXcomm.jar Test.java The same with debian : /usr/bin/jikes -classpath /usr/share/jamvm/classes.zip:/usr/share/classpath/glibj.zip:RXTXcomm.jar Test.java Run Test /opt/bin/jamvm -classpath .:RXTXcomm.jar Test Again with debian giving exactly the same result : /usr/bin/jamvm -Djava.library.path=/usr/lib/classpath/ -classpath .:RXTXcomm.jar Test Experimental: JNI_OnLoad called. Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 name=/dev/ttyUSB0 name=/dev/ttyS1 name=/dev/ttyS0 NOTE: The RXTX Serial Package implements the javax.comm features, but it is in it's own Java package (gnu.io). This means any code previously developed for javax.comm with need to be re-compiled after (simply) changing the import statement: //import javax.comm.*; // <== commented out import gnu.io.*; // new package
view ·
edit ·
print ·
history ·
Last edited by aimevareillewanadoofr.
Based on work by aimevareillewanadoofr. Originally by Scott. Page last modified on February 15, 2008, at 10:55 AM
|