svn-gvsig-desktop / tags / v1_10_0_Build_1256 / extensions / extGPS / test / Test.java @ 34207
History | View | Annotate | Download (3.86 KB)
1 | 4720 | jaume | /*
|
---|---|---|---|
2 | * Test.class is just that.. a Test
|
||
3 | */
|
||
4 | |||
5 | |||
6 | 4747 | jaume | import gnu.io.CommPortIdentifier; |
7 | import gnu.io.RXTXCommDriver; |
||
8 | import gnu.io.SerialPort; |
||
9 | import gnu.io.SerialPortEvent; |
||
10 | import gnu.io.SerialPortEventListener; |
||
11 | import gnu.io.UnsupportedCommOperationException; |
||
12 | 4720 | jaume | |
13 | 4747 | jaume | import java.io.IOException; |
14 | import java.io.InputStream; |
||
15 | import java.io.OutputStream; |
||
16 | import java.util.TooManyListenersException; |
||
17 | |||
18 | 4720 | jaume | public class Test implements SerialPortEventListener { |
19 | |||
20 | InputStream inputStream;
|
||
21 | OutputStream outputStream;
|
||
22 | SerialPort serialPort; |
||
23 | Thread readThread;
|
||
24 | |||
25 | public static void main(String[] args) { |
||
26 | if (args.length < 1) { |
||
27 | System.out.print("Test.class /dev/ports/serialx\n"); |
||
28 | System.exit(-1); |
||
29 | } |
||
30 | System.out.println("opening the Port: " + args[0]); |
||
31 | Test reader = new Test(args[0]); |
||
32 | } |
||
33 | |||
34 | public Test(String PortName) { |
||
35 | RXTXCommDriver TxPort = new RXTXCommDriver();
|
||
36 | System.out.print("open Ports\n"); |
||
37 | serialPort = (SerialPort) TxPort.getCommPort(PortName, CommPortIdentifier.PORT_SERIAL); |
||
38 | System.out.print("Get Streams\n"); |
||
39 | try {
|
||
40 | inputStream = serialPort.getInputStream(); |
||
41 | outputStream = serialPort.getOutputStream(); |
||
42 | } catch (IOException e) { |
||
43 | e.printStackTrace(); |
||
44 | } |
||
45 | try {
|
||
46 | serialPort.addEventListener(this);
|
||
47 | } catch (TooManyListenersException e) { |
||
48 | e.printStackTrace(); |
||
49 | } |
||
50 | try {
|
||
51 | System.out.println("Baud is " + serialPort.getBaudRate()); |
||
52 | System.out.println("Bits is " + serialPort.getDataBits()); |
||
53 | System.out.println("Stop is " + serialPort.getStopBits()); |
||
54 | System.out.println("Par is " + serialPort.getParity()); |
||
55 | System.out.print("Set Params\n"); |
||
56 | serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||
57 | System.out.println("Baud is " + serialPort.getBaudRate()); |
||
58 | System.out.println("Bits is " + serialPort.getDataBits()); |
||
59 | System.out.println("Stop is " + serialPort.getStopBits()); |
||
60 | System.out.println("Par is " + serialPort.getParity()); |
||
61 | System.out.print("Set Params\n"); |
||
62 | serialPort.setSerialPortParams(9600, SerialPort.DATABITS_7, SerialPort.STOPBITS_2, SerialPort.PARITY_ODD);
|
||
63 | System.out.println("Baud is " + serialPort.getBaudRate()); |
||
64 | System.out.println("Bits is " + serialPort.getDataBits()); |
||
65 | System.out.println("Stop is " + serialPort.getStopBits()); |
||
66 | System.out.println("Par is " + serialPort.getParity()); |
||
67 | } catch (UnsupportedCommOperationException e) {
|
||
68 | e.printStackTrace(); |
||
69 | } |
||
70 | System.out.print("Sending 0x01\n"); |
||
71 | try {
|
||
72 | outputStream.write((byte)0x01); |
||
73 | System.out.print("0x01 Sent\n"); |
||
74 | } catch (IOException e) { |
||
75 | e.printStackTrace(); |
||
76 | } |
||
77 | } |
||
78 | public void serialEvent(SerialPortEvent event) { |
||
79 | switch(event.getEventType()) {
|
||
80 | case SerialPortEvent.BI:
|
||
81 | System.out.print("BI\n"); |
||
82 | case SerialPortEvent.OE:
|
||
83 | System.out.print("OE\n"); |
||
84 | case SerialPortEvent.FE:
|
||
85 | System.out.print("FE\n"); |
||
86 | case SerialPortEvent.PE:
|
||
87 | System.out.print("PE\n"); |
||
88 | case SerialPortEvent.CD:
|
||
89 | System.out.print("CD\n"); |
||
90 | case SerialPortEvent.CTS:
|
||
91 | System.out.print("CTS\n"); |
||
92 | case SerialPortEvent.DSR:
|
||
93 | System.out.print("DSR\n"); |
||
94 | case SerialPortEvent.RI:
|
||
95 | System.out.print("RI\n"); |
||
96 | case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
|
||
97 | System.out.print("Out Buff Empty\n"); |
||
98 | break;
|
||
99 | case SerialPortEvent.DATA_AVAILABLE:
|
||
100 | System.out.print("Data Available\n"); |
||
101 | break;
|
||
102 | } |
||
103 | } |
||
104 | |||
105 | } |