Rev 1630 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1630 | - | 1 | package dongfang.mkt.main; |
2 | |||
3 | import java.io.IOException; |
||
4 | |||
5 | import dongfang.mkt.comm.FrameQueue; |
||
6 | import dongfang.mkt.comm.MKConnection; |
||
7 | import dongfang.mkt.comm.serial.RXTXSerialPort; |
||
8 | import dongfang.mkt.frames.RequestFrame; |
||
1688 | - | 9 | import dongfang.mkt.frames.ReadVariablesRequestFrame; |
10 | import dongfang.mkt.frames.ReadVariablesResponseFrame; |
||
1630 | - | 11 | |
12 | public class VariablesReader { |
||
13 | private static int[] readVariables(String portIdentifier) throws IOException { |
||
14 | MKConnection port = new RXTXSerialPort(); |
||
15 | port.init(portIdentifier); |
||
16 | FrameQueue q = new FrameQueue(port); |
||
17 | int[] variables = null; |
||
18 | |||
1688 | - | 19 | ReadVariablesRequestFrame frame = new ReadVariablesRequestFrame(RequestFrame.FC_ADDRESS); |
1630 | - | 20 | q.sendRequest(frame); |
1688 | - | 21 | ReadVariablesResponseFrame r = (ReadVariablesResponseFrame) q.getResponseFor(frame, 5000); |
1630 | - | 22 | if (r == null) { |
23 | System.err.println("ERROR. Timeout waiting for response."); |
||
24 | } else { |
||
25 | variables = r.getVariables(); |
||
26 | } |
||
27 | q.kill(); |
||
28 | return variables; |
||
29 | } |
||
30 | |||
31 | public static void main(String[] args) throws IOException { |
||
32 | String portIdentifier = null; |
||
33 | if (args.length > 0) portIdentifier = args[0]; |
||
34 | int[] vars = readVariables(portIdentifier); |
||
35 | for (int i=0; i<vars.length; i++) { |
||
36 | System.out.println("var" + i + ": " + vars[i]); |
||
37 | } |
||
38 | System.exit(0); |
||
39 | } |
||
40 | } |