Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1698 | - | 1 | package dongfang.mkt.main; |
2 | |||
3 | import java.io.IOException; |
||
4 | import java.io.PrintStream; |
||
5 | |||
6 | import dongfang.mkt.comm.FrameQueue; |
||
7 | import dongfang.mkt.comm.serial.RXTXSerialPort; |
||
8 | import dongfang.mkt.frames.ConfirmFrame; |
||
9 | import dongfang.mkt.frames.ExternalControlRequestFrame; |
||
10 | |||
11 | public class SendCommand { |
||
12 | private static final PrintStream STDERR = System.out; |
||
13 | private void sendCommand(final FrameQueue q, final int command) throws IOException { |
||
14 | ExternalControlRequestFrame f = new ExternalControlRequestFrame(); |
||
15 | try { |
||
16 | f.setCommand(command); |
||
17 | f.setFrameNum(1); // 0 does not work. |
||
18 | q.sendRequest(f); |
||
19 | ConfirmFrame cf = (ConfirmFrame) q.getResponseFor(f, 2000); |
||
20 | System.out.println("Confirmed: " + cf); |
||
21 | } catch (IOException ex) { |
||
22 | STDERR.println(ex); |
||
23 | } |
||
24 | } |
||
25 | |||
26 | public static void main(String[] args) throws IOException { |
||
27 | SendCommand test = new SendCommand(); |
||
28 | int command = Integer.parseInt(args[0]); |
||
29 | RXTXSerialPort _port = new RXTXSerialPort(); |
||
30 | _port.init(null); |
||
31 | FrameQueue q = new FrameQueue(_port); |
||
32 | test.sendCommand(q, command); |
||
33 | q.kill(); |
||
34 | } |
||
35 | } |