I have a code which sends commands to a relay board over a virtual serial port attached to one of the USB connectors on the PC, and reads the response.
Syntax:
send:
command\r
response:
command\r
answer\r
>
On my dev PC, it works fine. (Lubuntu 13.10) but on the target PC (Lubuntu 12.04 LTS) it reads only the command I have sent. For example:
Send:
gpio read 0\r
Correct response (on my dev env it works like this):
gpio read 0\r
1\r
>
It also works well on other machimes too. But, unfortunatelly on that PC which I want to develop for, the response is like:
gpio read 0
And here the stream ends without the real response.
My code is:
public static String command(String command) throws Exception {
byte[] buffer = new byte[1024];
int len = 0;
out.flush();
try{
out.write(command.getBytes());
out.write('\r');
out.flush();
int data;
Thread.sleep(100);
while (in.available() > 0)
{
data = in.read();
if ( (char) data == '>') {
break;
}
buffer[len++] = (byte) data;
}
} catch (IOException ex){
}
return new String(buffer);
}
Some parameters which might be useful:
dev machine:
kernel: 3.11.0-12 generic
java version: 1.7.0_51 OpenJDK IcedTea 2.4.4, 7u51-2.4.4-0ubuntu0.13.10.1
target machine:
kernel 3.7.1-030701-generic
java version: 1.7.0_55 OpenJDK IcedTea 2.4.7, 7u55-2.4.7-1ubuntu1~0.12.04.2
In both cases I use RXTX-2.2-pre2
Any ideas? Thanks for advance!