So ok.
I managed the RS485 converter to work.
I'm actually writing a Java program to acquire data from my serial-connected sensors using rxtx lib.
The good news is that I can send coomands on the rs485 converter (a green blinking LED tells that the port is receiving something).
The bad news is that no data come back from the converter!
I had a basic program (written to work under a Windows system) that was working. The important part is:
open "COM9:9600,n,8,1,cs,ds,rs" for random as #dgh
for tryW = 1 to 10
print #dgh, "$aRB"
GOSUB [delay]
H$ = input$(#dgh,lof(#dgh))
if left$(H$,1)="*" then exit for
next tryW
aa = val(mid$(H$,2,9))/100
bb = val(mid$(H$,13,9))/100
cc = val(mid$(H$,24,9))/100
dd = val(mid$(H$,35,9))/100
and similar for...next loops for the other sensors.
I'm trying to replicate this behaviour through my Java code:
String defaultPort = "COM10";
portList = CommPortIdentifier.getPortIdentifiers();
serialPort = (SerialPort)portId.open("DataReading", 2000);
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
outputStream = serialPort.getOutputStream();
inputStream = serialPort.getInputStream();
serialPort.notifyOnOutputEmpty(true);
int available = 0, k = 0;
boolean check = true;
for (int i=0; i<10; i++) {
while (check) {
outputStream.write("$aRB".getBytes());
Thread.sleep(k++);
available = inputStream.available();
if (available > 0) {
System.out.println(k);
check = false;
}
if (k == 100)
check = false;
System.out.print(".");
}
check = true;
k = 0;
System.out.println("");
System.out.println("Available data: " + available);
if (available > 0) {
int prova = inputStream.read(byteArray, 0, available);
System.out.println("Read: " + prova);
} else {
System.out.println("No data found!");
}
}
serialPort.close();
System.exit(1);
A lot of things are messing in this pseudo-code I wrote, but the point is that the ouputStream.write seems to do correctly his dirty jpb, while the instruction "inputStream.available()" constantly returns 0, even when it should find some data.
My only thought is related with the "open" command in basic:
open "COM9:9600,n,8,1,cs,ds,rs" for random as #dgh
Should I use the same parameters (cs, ds, rs) in my Java program too? How?
Or the problem is buried much deeper, probably in the way RS485 protocol should be used? Maybe I'm wrong, but in the basic code I was using nothing seems to be too hard to understand and implement in a similar Java program. The result, however, is that the basic code is working, while my Java code not!
Please, help me!