Go to most recent revision |
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.VariablesRequestFrame;
import dongfang.mkt.frames.VariablesResponseFrame;
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;
VariablesRequestFrame frame =
new VariablesRequestFrame
(RequestFrame.
FC_ADDRESS);
q.
sendRequest(frame
);
VariablesResponseFrame r =
(VariablesResponseFrame
) 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);
}
}