Commit 01444232 by Tref

update with better structure

parent 6d3d0170
Showing with 63 additions and 9 deletions
...@@ -2,19 +2,73 @@ package com.tDiagnostics; ...@@ -2,19 +2,73 @@ package com.tDiagnostics;
//import com.tDiagnostics.device.Connection; //import com.tDiagnostics.device.Connection;
import com.tDiagnostics.device.ConnectDevice; import com.fazecast.jSerialComm.SerialPort;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
public class Main { public class Main {
public void main(String[] args) {
int lastd = -1;
SerialPort comPort2 = SerialPort.getCommPort("COM13");
comPort2.setBaudRate(9600);
comPort2.setParity(SerialPort.NO_PARITY);
comPort2.setNumDataBits(8);
comPort2.setNumStopBits(1);
comPort2.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 500, 500);
comPort2.openPort();
OutputStream out2 = comPort2.getOutputStream();
InputStream in2 = comPort2.getInputStream();
int d;
//in2 = InputStream.nullInputStream();
while (true) {
try {
d = in2.read();
if (d != lastd)
System.out.println(d);
} catch (IOException e) {
d = -1;
}
//d = 203;
lastd = d;
if (d == 203) {
try {
StringBuilder str = new StringBuilder();
str.append('D');
String str2 = str.toString();
out2.write(str2.getBytes(StandardCharsets.UTF_8));
System.out.println(str2);
} catch (IOException e) {
e.printStackTrace();
}
} else if (d == 204) {
} else if (d != -1 && d < 203) {
try {
StringBuilder str = new StringBuilder();
str.append('G');
public static void main(String[] args) {
// write your code here
char c = 1; str.append(';');
ConnectDevice connection = new ConnectDevice(c); String str2 = str.toString();
if(connection.startConnection()){ out2.write(str2.getBytes(StandardCharsets.UTF_8));
System.out.println("Success"); System.out.println(str2);
return; } catch (IOException e) {
e.printStackTrace();
}
}
} }
System.out.println("failed");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment