I've installed javax.comm and seen the examples sampleread and samplewrite. Now I want to communicate with a serial port. On the port, I've a reader, who reads chips. The chips have an ID and some other informations. I can open the port and get the input- and outputstream, but I can't communicate with the port. Normally if I would write "V?\r" on the outputstream, the inputstream should give me the version of the reader. But that doesn't come. Instead, I get this: . I don't know why. If I write again something on the outputstream, the inputstream is empty.
Here is the function I use to write and read on the port:
String messageString = "V?\r"; byte[] readBuffer = new byte[256];
If this is a StringBuffer that you're printing out, then you will have problems. numBytes is the number of bytes read in from the input stream (not the content of the input stream which you have placed in readBuffer.
It wasn't the problem. Now, if I do that with a serialEvent, I only get the string I sent to the port. Means: I can send data to the port, but I get the same data back. A little bit bizzarre!
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.DATA_AVAILABLE: StringBuffer SB; SB = new StringBuffer(); byte[] readBuffer = new byte[20]; try { while (inputStream.available() > 0) { int numBytes = inputStream.read(readBuffer); SB.append(numBytes); System.out.println("\nSB: " + SB); }