Rev 1630 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package dongfang.mkt.main;
import java.io.IOException;
import dongfang.mkt.comm.FrameQueue;
import dongfang.mkt.comm.MKConnection;
import dongfang.mkt.comm.serial.RXTXSerialPort;
import dongfang.mkt.frames.RequestFrame;
import dongfang.mkt.frames.ReadVariablesRequestFrame;
import dongfang.mkt.frames.ReadVariablesResponseFrame;
public class VariablesReader
{
private static int[] readVariables
(String portIdentifier
) throws IOException {
MKConnection port =
new RXTXSerialPort
();
port.
init(portIdentifier
);
FrameQueue q =
new FrameQueue
(port
);
int[] variables =
null;
ReadVariablesRequestFrame frame =
new ReadVariablesRequestFrame
(RequestFrame.
FC_ADDRESS);
q.
sendRequest(frame
);
ReadVariablesResponseFrame r =
(ReadVariablesResponseFrame
) q.
getResponseFor(frame,
5000);
if (r ==
null) {
System.
err.
println("ERROR. Timeout waiting for response.");
} else {
variables = r.
getVariables();
}
q.
kill();
return variables
;
}
public static void main
(String[] args
) throws IOException {
String portIdentifier =
null;
if (args.
length > 0) portIdentifier = args
[0];
int[] vars = readVariables
(portIdentifier
);
for (int i=
0; i
<vars.
length; i++
) {
System.
out.
println("var" + i +
": " + vars
[i
]);
}
System.
exit(0);
}
}