Files
tell/plugins/LaserUE.java
gac-S_Changer bdf5049f96 Creation
2018-12-03 12:17:40 +01:00

80 lines
2.2 KiB
Java

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 ch.psi.utils.State;
import java.io.IOException;
/*
*
*/
/**
*
*/
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
setState(State.Ready);
write("OUTPUT RS422\n\r");
}
public Readable getReadable(){
return readable;
}
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;
count = 1;
} else if (index ==1){
value = ((rx& 0x3F)<<6) + value;
count = 2;
} else if (index ==2){
value = ((rx& 0x0F)<<12) + 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;
}
}
}