Guys,
This is a follow up to another poorly named discussion I started. My question is basically "Can Java work with the BeagleBone hardware interfacing directly enough to be effective?" With some help of Koen Kooi on another thread I came up with the following steps for getting Java to access a USB connection via RxTx.
Here is what I have done:
1. Installed newest distro (not sure this made a difference, but needed to be done anyway)
2. opkg update
3. opkg install openjdk-6-jre
4. opkg install rxtx
4a. I had to copy all files from /usr/lib/jni/librxtx*
to /usr/lib/jvm/java-6-openjdk/jre/lib/arm
to make the libraries work at all. This was not done by the install
rxtx above. Probably a better way todo this with a link if someone would
like to comment on that.
5. Run my program which basically just spits out the com ports. Output reads:
WARNING: RXTX Version mismatch Jar version = RXTX-2.2pre1 native lib Version = RXTX-2.2pre2RXTX Warning: Removing stale lock file. /var/lock/LCK..ttyUSB0/dev/ttyUSB0 - SerialNote:
Changing the version of the jar file doesn't get rid of the warning
regardless. However, that is the USB device that is hooked up. It is
spitting out a 9600 baud GPS signal from a UART to RS232 serial
converter.
6. When I run this on windows I come up with:
$GPRMC,053000.004,V,4035.6940,
N,12223.2450,W,0.00,0.00,300512,,,N*69
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,053001.004,4035.6940,N,12223.2450,W,0,0,,172.8,M,-22.8,M,,*71
$GPGLL,4035.6940,N,12223.2450,W,053001.004,V,N*5A
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,01,25,,,25*78
$GPRMC,053001.004,V,4035.6940,N,12223.2450,W,0.00,0.00,300512,,,N*68
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
7. However, when I change only the port ID to /dev/ttyUSB0 it comes up with the following on the BeagleBone:
GGL43.90,,22.40W54104VN5E.,M-28M,7
GGAA1,,,,,,,1
$PT,00,,M00,00,,*2325,,00,.0301,N6
GGA,542044364,,22.45,,,,128,2.,,*6
$PS,,,,,,,,,,*E$PS,,,079
GRC03004V43.90,,22.40W.000,05,,*F
GGL43.90,,22.40W54304VN5C.,M-28M,7
GGAA1,,,,,,,1
It's obviously getting something and parts of it
are right. However, it's not getting it correctly. I would post all my
code up here, but it's several files. Here are the biggies though:
This code spins up some stuff:
inBuffer = new StringBuffer();
outBuffer = new StringBuffer();
portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyUSB0");
CommPort commPort = portIdentifier.open("test", 2000);
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
reader = new SerialReader(serialPort.getInputStream(), inBuffer);
writer = new SerialWriter(serialPort.getOutputStream(), outBuffer);
new Thread(reader).start();
new Thread(writer).start();
Then later this code reads it. This is the thread that gets started:
byte[] buffer = new byte[1024];
int len = -1;
try {
while ((len = this.in.read(buffer)) > -1) {
if (pause) {
continue;
}
if(stop) {
return;
}
String str = new String(buffer, 0, len);
System.out.print(str);
inBuffer.append(str);
}
} catch (IOException e) {
e.printStackTrace();
}
Bonus to anyone who can help me get a UART connection working too!
Thanks,
Gregg