What steps will reproduce the problem?
I am communicating with custom code written on an Arduino UNO. When a specific
byte pattern is sent over the serial port (9600, 8 bits, no parity, 1 stop
bit), the UNO will read its UUID from EEPROM and write them back over the
serial port.
I have verified the Arduino is operating correctly by using CoolTerm and
sending the byte pattern manually. However when I do the steps in code, using
JSSC, I get seeming random data back.
This is the code I am using:
> int retVal[] = null;
> byte msg[] = new byte[5];
> msg[0] = 0x48; // Header 1
> msg[1] = 0x57; // Header 2
> msg[2] = (byte) deviceID; // Addr
> msg[3] = 0; // Length
> msg[4] = 0; // Output Mode
> try {
> this.serial.writeBytes(msg);
> try {
> retVal = this.serial.readIntArray(maxLen);
> } catch (SerialPortException e) {
> AppLog.get().log("Error reading from device " + deviceID);
> AppLog.get().log(e);
> }
> } catch (SerialPortException e) {
> AppLog.get().log("Error writing to device " + deviceID);
> AppLog.get().log(e);
> }
If I put a breakpoint on the line that reads "this.serial.writeBytes(msg);" and
then single step though the code, I get the correct results. If I run
normally, or don't put a breakpoint there, then I get seemingly random data
back.
I have tried putting a Thread.sleep(100) between the write and the read,
thinking that it might be a timing issue, but that seems to have no effect.
I know that the Arduino is receiving the data correctly, because the other
commands that don't reply work perfectly. It is just when I read after writing
that things go wrong.
What version of the product are you using? On what operating system?
JSSC 0.9, OSX 10.8.2
Any help is greatly appreciated