Fix UE Laser calculation
This commit is contained in:
@@ -7,7 +7,7 @@ mscan_pin=ch.psi.pshell.serial.TcpDevice|mscan-tell6s-pin:2001|||
|
||||
mscan_pin_cmd=ch.psi.pshell.serial.TcpDevice|mscan-tell6s-pin:2003|||
|
||||
mscan_puck=ch.psi.pshell.serial.TcpDevice|mscan-tell6s-puck:2001|||
|
||||
mscan_puck_cmd=ch.psi.pshell.serial.TcpDevice|mscan-tell6s-puck:2003|||
|
||||
ue=LaserUE|COM3|||true
|
||||
ue=LaserUE|COM3 50 35|||true
|
||||
puck_detection=ch.psi.mxsc.PuckDetection|tell6s-raspberrypi:5556|||
|
||||
wago=ch.psi.pshell.modbus.ModbusTCP|tell6s-wago:502|||
|
||||
led_ok_1=ch.psi.pshell.modbus.DigitalInput|wago 0||1000|
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#Tue Feb 04 09:33:51 CET 2020
|
||||
#Tue Feb 11 13:39:46 CET 2020
|
||||
dry_mount_counter=0
|
||||
room_temperature_enabled=false
|
||||
pin_offset=0.0
|
||||
puck_types=true
|
||||
imaging_enabled=false
|
||||
dry_timestamp=1.580771768364E9
|
||||
dry_timestamp=1.581416141564E9
|
||||
roi_h=1000
|
||||
led_level=0.0
|
||||
beamline_status_enabled=false
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Mon Feb 03 09:28:54 CET 2020
|
||||
FileSequentialNumber=149
|
||||
#Tue Feb 11 10:28:01 CET 2020
|
||||
FileSequentialNumber=154
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Tue Jan 21 11:05:02 CET 2020
|
||||
#Wed Feb 05 08:49:58 CET 2020
|
||||
minValue=0.0
|
||||
unit=V
|
||||
offset=0.0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Tue Jan 21 11:05:02 CET 2020
|
||||
#Wed Feb 05 08:49:58 CET 2020
|
||||
minValue=0.0
|
||||
unit=V
|
||||
offset=0.0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Tue Jan 21 11:05:02 CET 2020
|
||||
#Wed Feb 05 08:49:58 CET 2020
|
||||
minValue=0.0
|
||||
unit=V
|
||||
offset=0.0
|
||||
|
||||
@@ -1,79 +1,90 @@
|
||||
|
||||
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.Convert;
|
||||
import ch.psi.utils.State;
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public class LaserUE extends SerialPortDevice {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class LaserUE extends SerialPortDevice{
|
||||
final Readable readable;
|
||||
static final double RANGE_MIN = 1.0;
|
||||
static final double RANGE_MAX = 35.0;
|
||||
public LaserUE(String name, String port) {
|
||||
final double range;
|
||||
final double offset;
|
||||
|
||||
public LaserUE(String name, String port, double range, double offset) {
|
||||
super(name, port, 921600, SerialPortDeviceConfig.DataBits.DB_8, SerialPortDeviceConfig.StopBits.SB_1, SerialPortDeviceConfig.Parity.None);
|
||||
this.range = range;
|
||||
this.offset = offset;
|
||||
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";
|
||||
public String getName() {
|
||||
return LaserUE.this.getName() + "_readout";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doInitialize() throws IOException, InterruptedException{
|
||||
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(){
|
||||
|
||||
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){
|
||||
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;
|
||||
} 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)){
|
||||
} else if (index == 2) {
|
||||
value = ((rx & 0x0F) << 12) + value;
|
||||
//double val = ((double)value)/1000;
|
||||
double val = (0.01) * (102.0 * value / 65520.0 - 1) * range;
|
||||
if ((val <= 0.0) || (val > range)) {
|
||||
val = Double.NaN;
|
||||
} else {
|
||||
val+=offset;
|
||||
val = Convert.roundDouble(val, 3);
|
||||
}
|
||||
setCache(val);
|
||||
count = 0;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
else{
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
LaserUE l = new LaserUE("UE", "COM3", 50.0, 35.0);
|
||||
l.setMonitored(true);
|
||||
l.initialize();
|
||||
|
||||
Thread.sleep(10000);
|
||||
l.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user