So i have to find a new solution and after some googling i have found the "Java simple serial Connector" project which is an excellent solution to access the serial com port from java. The library consists of one jar (jssc.jar) which contains some java classes and the native libraries for Windows (32bit and 64bit) Mac OS X and Linux. To use the library in your project you have to add the jssc.jar to your class path.
Example how to write to the serial com Port in Java
public class TestComPort { public static void main(String[] args) { SerialPort serialPort = new SerialPort("COM5"); try { serialPort.openPort();// Open serial port serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.writeBytes("Hello World".getBytes()); System.out.println(new String(serialPort.readBytes(10))); serialPort.closePort(); } catch (SerialPortException e) { e.printStackTrace(); } } }
No comments:
Post a Comment