43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
|
|
import ch.psi.pshell.serial.SerialPortDevice;
|
|
import ch.psi.pshell.serial.SerialPortDeviceConfig;
|
|
import static ch.psi.utils.BitMask.*;
|
|
|
|
/*
|
|
*
|
|
*/
|
|
|
|
/**
|
|
*
|
|
*/
|
|
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);
|
|
}
|
|
|
|
int value = 0;
|
|
int count = 0;
|
|
@Override
|
|
protected void onByte(int rx) {
|
|
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;
|
|
}
|
|
}
|
|
}
|