1 | import java.io.*;
|
2 | import gnu.io.CommPort;
|
3 | import gnu.io.CommPortIdentifier;
|
4 | import gnu.io.SerialPort;
|
5 | import gnu.io.NoSuchPortException;
|
6 | import gnu.io.PortInUseException;
|
7 | import gnu.io.UnsupportedCommOperationException;
|
8 |
|
9 | /**
|
10 | *
|
11 | * @author
|
12 | */
|
13 | public class UsbStick {
|
14 |
|
15 | private static SerialPort serialPort = null;
|
16 |
|
17 |
|
18 | public void dateiBeschreiben(String zeile){
|
19 | ...
|
20 | }
|
21 |
|
22 | public void verbinden(){
|
23 | CommPortIdentifier portIdentifier = null;
|
24 | CommPort commPort = null;
|
25 |
|
26 | try{
|
27 | portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyUSB0");
|
28 | }catch(NoSuchPortException e){
|
29 | System.out.println(e);
|
30 | }
|
31 |
|
32 | //Open the port and give the port name and a timeout
|
33 | try{
|
34 | commPort = portIdentifier.open("/dev/ttyUSB0", 2000); //Warning: Dereferencing possible null pointer
|
35 | }catch(PortInUseException e){
|
36 | System.out.println(e);
|
37 | }
|
38 |
|
39 |
|
40 | this.serialPort = (SerialPort) commPort; //Warning: Accessing static field serialPort
|
41 |
|
42 | //Set the baud rate and other parameters of the serial port
|
43 | try{
|
44 | this.serialPort.setSerialPortParams(115200, 8, 1, 0); //Warning: Accessing static field serialPort
|
45 |
|
46 | }catch(UnsupportedCommOperationException e){
|
47 | System.out.println(e);
|
48 | }
|
49 | }
|
50 |
|
51 | /**
|
52 | * @param args the command line arguments
|
53 | */
|
54 | public static void main(String[] args){
|
55 | // TODO code application logic here
|
56 | UsbStick beschreiben = new UsbStick();
|
57 |
|
58 | beschreiben.verbinden();
|
59 |
|
60 |
|
61 | InputStream in = null; //Warning: The assigned value is never used
|
62 | String zeile = null; //Warning: The assigned value is never used
|
63 | BufferedReader reader = null; //Warning: The assigned value is never used
|
64 | while(true){
|
65 |
|
66 | in = this.serialPort.getInputStream(); //Error: non static variable this cannot be referenced from a static context
|
67 | if (in != null){
|
68 | try{
|
69 | reader = new BufferedReader(new InputStreamReader(in));
|
70 | zeile = reader.readLine();
|
71 | System.out.println(zeile);
|
72 | beschreiben.dateiBeschreiben(zeile);
|
73 | }catch(IOException e){
|
74 | System.out.println("IOException");
|
75 | }
|
76 | }
|
77 | }
|
78 | }
|
79 | }
|