This commit is contained in:
gac-S_Changer
2017-08-31 17:36:36 +02:00
parent afdb1cd781
commit 5b8662423f

View File

@@ -18,70 +18,39 @@ public class LaserUE extends SerialPortDevice{
public LaserUE(String name, String port) {
super(name, port, 921600, SerialPortDeviceConfig.DataBits.DB_8, SerialPortDeviceConfig.StopBits.SB_1, SerialPortDeviceConfig.Parity.None);
this.setMode(Mode.FullDuplex);
/*
System.out.println("XXX");
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Starting");
while(!isClosed()){
try{
if (isInitialized()){
int rx;
while ((rx = readByte()) >= 0) {
onByte((byte) rx);
}
}
} catch (Exception ex){
System.err.println(ex);
}
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(LaserUE.class.getName()).log(Level.SEVERE, null, ex);
}
}
System.out.println("Quiting");
}
}).start();
*/
}
int value = 0;
int count = 0;
/*
@Override
protected int readByte() throws IOException {
int ret = super.readByte();
System.out.print(ret);
return ret;
}
*/
@Override
protected void onByte(int rx) {
System.out.println(rx);
if (rx < 0) {
count = 0;
} else {
int index = ((rx&BIT7) > 0) ? 2 : (((rx&BIT6) > 0) ? 1 : 0);
if (count==index){
if (index ==0){
value = rx & 0x3F;
} else if (index ==1){
value = ((rx& 0x3F)<<6) + value;
} else if (index ==2){
value = ((rx& 0x0F)<<12) + value;
this.setCache(value);
count = 0;
} else {
count = 0;
}
}
else{
int index = ((rx&BIT7) > 0) ? 2 : (((rx&BIT6) > 0) ? 1 : 0);
if (count==index){
if (index ==0){
value = rx & 0x3F;
} else if (index ==1){
value = ((rx& 0x3F)<<6) + value;
} else if (index ==2){
value = ((rx& 0x0F)<<12) + value;
this.setCache(value);
count = 0;
} else {
count = 0;
}
}
else{
count = 0;
}
}
}