ich versuche gerade die java commapi mit Debian zum
Laufen zu bringen, folgendes habe ich gemacht:
apt-get install librxtx-java
danach habe ich die commapi von sun heruntergeladen:
comm3.0_u1_solaris_sparc.zip
soll wohl die richtige sein, obwohl es auch eine
Linux Variante gibt?!
comm.jar habe in folgendes Verzeichnis kopiert:
debian:/usr/lib/jvm/java-1.5.0-sun/jre/lib/ext#
und noch eine Config Datei in
debian:/usr/lib/jvm/java-1.5.0-sun/jre/lib# erzeugt.
cat javax.comm.properties
Driver=gnu.io.RXTXCommDriver
Nun habe ich hier folgendes Beispiel ausprobiert:
Code: Alles auswählen
package de.serial;
import java.io.*;
import java.util.*;
import javax.comm.*;
/**
* Class declaration
*
*
* @author
* @version 1.8, 08/03/00
*/
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
/**
* Method declaration
*
*
* @param args
*
* @see
*/
public static void main(String[] args) {
boolean portFound = false;
String defaultPort = "/dev/ttyS0";
if (args.length > 0) {
defaultPort = args[0];
}
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
System.out.println("Found port: "+defaultPort);
portFound = true;
SimpleRead reader = new SimpleRead();
}
}
}
if (!portFound) {
System.out.println("port " + defaultPort + " not found.");
}
}
/**
* Constructor declaration
*
*
* @see
*/
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
/**
* Method declaration
*
*
* @see
*/
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}
/**
* Method declaration
*
*
* @param event
*
* @see
*/
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
}
java.io.IOException: Error instantiating class gnu.io.RXTXCommDriver
gnu.io.RXTXCommDriver
at javax.comm.CommPortIdentifier.loadDriver(CommPortIdentifier.java:239)
at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
at de.serial.SimpleRead.main(SimpleRead.java:37)
Exception in thread "main" java.lang.UnsatisfiedLinkError: isSessionActive
at com.sun.comm.SunrayInfo.isSessionActive(Native Method)
at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155)
at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100)
at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138)
at de.serial.SimpleRead.main(SimpleRead.java:37)
Was mache ich falsch???
regards
eliot