This commit is contained in:
sfop
2016-09-01 10:12:30 +02:00
parent 4868dc379d
commit 7a0d74eb07
2 changed files with 158 additions and 132 deletions

View File

@@ -2,6 +2,7 @@
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.Readable;
import ch.psi.pshell.epics.*;
import java.io.IOException;
@@ -10,142 +11,167 @@ import java.util.ArrayList;
/**
*
*/
public class Camtool extends ArraySource {
final String prefix;
final String dataPrefix;
final boolean latch;
final public ChannelInteger channelRun;
final public ChannelInteger channelLatch;
final public ChannelDouble channelTimestamp;
final public ChannelDouble posX, posY;
final public ChannelDoubleArray profileX, profileY;
final public ChannelIntegerArray shape;
final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain;
final public CamToolPosX posMeanX;
final public CamToolPosY posMeanY;
final public CamToolVarX posVarX;
final public CamToolVarY posVarY;
public class Camtool extends ArraySource {
public Camtool(String name, String prefix) {
this(name, prefix, true, true);
}
public Camtool(String name, String prefix, boolean latch, boolean roi) {
super(name, prefix + (latch ? ":latch": ":pipeline") + (roi ? ".roi.output": ".image"));
this.prefix = prefix+":";
this.latch = latch;
dataPrefix = this.prefix + (latch ? "latch": "pipeline") + ".";
channelRun = new ChannelInteger(name + " run", this.prefix + "camera.run");
channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture");
channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp");
channelTimestamp.setMonitored(true);
final String prefix;
final String dataPrefix;
final boolean latch;
final public ChannelInteger channelRun;
final public ChannelInteger channelLatch;
final public ChannelDouble channelTimestamp;
final public ChannelDouble posX, posY;
final public ChannelDoubleArray profileX, profileY;
final public ChannelIntegerArray shape;
final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain;
final public CamToolPosX posMeanX;
final public CamToolPosY posMeanY;
final public CamToolVarX posVarX;
final public CamToolVarY posVarY;
public Camtool(String name, String prefix) {
this(name, prefix, false, true);
}
public Camtool(String name, String prefix, boolean latch, boolean roi) {
super(name, prefix + (latch ? ":latch" : ":pipeline") + (roi ? ".roi.output" : ".image"));
this.prefix = prefix + ":";
this.latch = latch;
dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + ".";
channelRun = new ChannelInteger(name + " run", this.prefix + "camera.run");
channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture");
channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp");
channelTimestamp.setMonitored(true);
//posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com");
//posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com");
posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu");
posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu");
profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x");
profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y");
shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape": "image.shape"));
bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled");
bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture");
bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain");
posMeanX = new CamToolPosX();
posMeanY = new CamToolPosY();
posVarX = new CamToolVarX();
posVarY = new CamToolVarY();
}
@Override
public void doSetMonitored(boolean value){
super.doSetMonitored(value);
getDevice().setMonitored(value);
}
@Override
public void doUpdate() throws IOException, InterruptedException{
super.doUpdate();
getDevice().update();
}
@Override
protected void doInitialize() throws IOException, InterruptedException {
try {
channelRun.initialize();
channelLatch.initialize();
channelTimestamp.initialize();
posX.initialize(); posY.initialize();
profileX.initialize(); profileY.initialize();
shape.initialize();
bgEnable.initialize(); bgCapture.initialize(); bgCaptureRemain.initialize();
int[] s = shape.read();
getConfig().imageHeight = s[0];
getConfig().imageWidth = s[1];
getConfig().save();
getDevice().setSize(s[0] * s[1]);
super.doInitialize();
} catch (InterruptedException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException(ex);
//posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com");
posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu");
posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu");
profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x");
profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y");
shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape" : "image.shape"));
bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled");
bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture");
bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain");
posMeanX = new CamToolPosX();
posMeanY = new CamToolPosY();
posVarX = new CamToolVarX();
posVarY = new CamToolVarY();
}
}
int numImages = 1;
public int getNumImages(){
return numImages;
}
public void setNumImages(int value){
numImages = value;
}
double grabTimeout = 3.0;
public double getGrabTimeout(){
return grabTimeout;
}
public void setGrabTimeou(double value){
grabTimeout = value;
}
public void capture() throws IOException, InterruptedException {
}
public void start() throws IOException, InterruptedException {
channelRun.write(-1);
}
public void stop() throws IOException, InterruptedException {
channelRun.write(0);
}
public void grabSingle() throws IOException, InterruptedException {
channelRun.write(1);
}
public void latch() throws IOException, InterruptedException {
channelLatch.write(1);
}
public void enableBackground(boolean value) throws IOException, InterruptedException {
bgEnable.write(value ? 1 : 0);
}
public void captureBackground(int images) throws IOException, InterruptedException {
start();
bgCapture.write(images);
Thread.sleep(200);
while( bgCaptureRemain.read() > 0){
Thread.sleep(10);
@Override
public void doSetMonitored(boolean value) {
super.doSetMonitored(value);
getDevice().setMonitored(value);
}
@Override
public void doUpdate() throws IOException, InterruptedException {
super.doUpdate();
getDevice().update();
}
void safeInitialize(Device dev, int timeout) throws IOException, InterruptedException{
for (int retries = 0; retries < 10; retries ++){
try{
dev.initialize();
break;
} catch (IOException ex){
if (retries==9){
throw ex;
}
Thread.sleep(timeout / 10);
}
}
}
@Override
protected void doInitialize() throws IOException, InterruptedException {
try {
safeInitialize (channelRun,3000);
channelLatch.initialize();
if (latch){
start();
latch();
}
safeInitialize (channelTimestamp,2000);
posX.initialize();
posY.initialize();
profileX.initialize();
profileY.initialize();
shape.initialize();
bgEnable.initialize();
bgCapture.initialize();
bgCaptureRemain.initialize();
int[] s = shape.read();
getConfig().imageHeight = s[0];
getConfig().imageWidth = s[1];
getConfig().save();
getDevice().setSize(s[0] * s[1]);
super.doInitialize();
} catch (InterruptedException ex) {
throw ex;
} catch (Exception ex) {
throw new IOException(ex);
}
}
int numImages = 1;
public int getNumImages() {
return numImages;
}
public void setNumImages(int value) {
numImages = value;
}
double grabTimeout = 3.0;
public double getGrabTimeout() {
return grabTimeout;
}
public void setGrabTimeou(double value) {
grabTimeout = value;
}
public void capture() throws IOException, InterruptedException {
}
public void start() throws IOException, InterruptedException {
channelRun.write(-1);
}
public void stop() throws IOException, InterruptedException {
channelRun.write(0);
}
public void grabSingle() throws IOException, InterruptedException {
channelRun.write(1);
}
public void latch() throws IOException, InterruptedException {
System.out.println("LATCH");
channelLatch.write(1);
System.out.println("Ret:" + channelLatch.read());
}
public void enableBackground(boolean value) throws IOException, InterruptedException {
bgEnable.write(value ? 1 : 0);
}
public void captureBackground(int images) throws IOException, InterruptedException {
start();
bgCapture.write(images);
Thread.sleep(200);
while (bgCaptureRemain.read() > 0) {
Thread.sleep(10);
}
}
}
//Statisticss pseudo devices