This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
|
||||
import ch.psi.pshell.device.Readable;
|
||||
import ch.psi.pshell.serial.SerialPortDevice;
|
||||
import ch.psi.pshell.serial.SerialPortDeviceConfig;
|
||||
import static ch.psi.utils.BitMask.*;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -14,40 +13,64 @@ import java.util.logging.Logger;
|
||||
*
|
||||
*/
|
||||
public class LaserUE extends SerialPortDevice{
|
||||
|
||||
final Readable readable;
|
||||
static final double RANGE_MIN = 1.0;
|
||||
static final double RANGE_MAX = 30.0;
|
||||
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);
|
||||
readable = new Readable() {
|
||||
@Override
|
||||
public Object read() throws IOException, InterruptedException {
|
||||
return take();
|
||||
}
|
||||
@Override
|
||||
public String getName(){
|
||||
return LaserUE.this.getName()+"_readout";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInitialize() throws IOException, InterruptedException{
|
||||
super.doInitialize();
|
||||
//TODO: Start DAQ in ILD1320: http://www.micro-epsilon.com/download/manuals/man--optoNCDT-1320--en.pdf
|
||||
}
|
||||
|
||||
public Readable getReadable(){
|
||||
return readable;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
int count = 0;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onByte(int rx) {
|
||||
if (rx<0){
|
||||
rx+=256;
|
||||
rx|=BIT7;
|
||||
}
|
||||
System.out.println(rx);
|
||||
int index = ((rx&BIT7) > 0) ? 2 : (((rx&BIT6) > 0) ? 1 : 0);
|
||||
if (count==index){
|
||||
if (index ==0){
|
||||
value = rx & 0x3F;
|
||||
count = 1;
|
||||
} else if (index ==1){
|
||||
value = ((rx& 0x3F)<<6) + value;
|
||||
count = 2;
|
||||
} else if (index ==2){
|
||||
value = ((rx& 0x0F)<<12) + value;
|
||||
this.setCache(value);
|
||||
double val = ((double)value)/1000;
|
||||
if ((val<RANGE_MIN) ||(val>RANGE_MAX)){
|
||||
val = Double.NaN;
|
||||
}
|
||||
setCache(val);
|
||||
count = 0;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
count = 0;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user