Exchanged Channel Access library with latest version
Fixing of the code is still going on!
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>jcae</artifactId>
|
||||
<version>1.0.30</version>
|
||||
<version>2.1.11</version>
|
||||
</dependency>
|
||||
<!-- Plotting library -->
|
||||
<dependency>
|
||||
|
||||
@@ -62,6 +62,7 @@ import ch.psi.fda.model.ModelManager;
|
||||
import ch.psi.fda.model.v1.Configuration;
|
||||
import ch.psi.fda.model.v1.Data;
|
||||
import ch.psi.fda.visualizer.Visualizer;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Entry class for command line based data acquisition
|
||||
@@ -253,7 +254,7 @@ public class AcquisitionMain {
|
||||
}
|
||||
|
||||
// Create/get acquisition engine
|
||||
final Acquisition acquisition = new Acquisition();
|
||||
final Acquisition acquisition = new Acquisition(new DefaultChannelService());
|
||||
|
||||
boolean vis = false;
|
||||
// Only register data visualization task/processor if there are visualizations
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
package ch.psi.fda.aq;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
@@ -30,7 +28,9 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
@@ -60,6 +60,7 @@ import ch.psi.fda.core.actors.PseudoActuatorSensor;
|
||||
import ch.psi.fda.core.guard.ChannelAccessGuard;
|
||||
import ch.psi.fda.core.guard.ChannelAccessGuardCondition;
|
||||
import ch.psi.fda.core.loops.ActorSensorLoop;
|
||||
import ch.psi.fda.core.loops.OTFBean;
|
||||
import ch.psi.fda.core.loops.OTFLoop;
|
||||
import ch.psi.fda.core.loops.cr.CrlogicLoop;
|
||||
import ch.psi.fda.core.loops.cr.ParallelCrlogic;
|
||||
@@ -118,7 +119,11 @@ import ch.psi.fda.model.v1.Variable;
|
||||
import ch.psi.fda.model.v1.VariableParameterMapping;
|
||||
import ch.psi.fda.notification.NotificationAgent;
|
||||
import ch.psi.fda.serializer.DataSerializerTXT;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.type.DoubleTimestamp;
|
||||
|
||||
/**
|
||||
* Data acquisition engine for performing scans
|
||||
@@ -144,16 +149,19 @@ public class Acquisition {
|
||||
private Handler logHandler = null;
|
||||
|
||||
private Collector col;
|
||||
|
||||
/**
|
||||
* Name of the datafile
|
||||
*/
|
||||
private File datafile;
|
||||
|
||||
public Acquisition(){
|
||||
configuration = AcquisitionConfiguration.getInstance();
|
||||
actionLoop = null;
|
||||
manipulations = new ArrayList<Manipulation>();
|
||||
|
||||
private ChannelService cservice;
|
||||
private List<Channel<?>> channels = new ArrayList<>();
|
||||
private List<Object> templates = new ArrayList<>();
|
||||
|
||||
|
||||
public Acquisition(ChannelService cservice){
|
||||
this.cservice = cservice;
|
||||
this.configuration = AcquisitionConfiguration.getInstance();
|
||||
this.actionLoop = null;
|
||||
this.manipulations = new ArrayList<Manipulation>();
|
||||
}
|
||||
|
||||
|
||||
@@ -345,21 +353,31 @@ public class Acquisition {
|
||||
catch(Exception e){
|
||||
logger.log(Level.SEVERE, "Unable to destroy action loop", e);
|
||||
}
|
||||
|
||||
// Destroy all managed channels
|
||||
for(Channel<?> c: channels){
|
||||
try {
|
||||
c.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel "+c.getName(),e);
|
||||
}
|
||||
}
|
||||
for(Object o: templates){
|
||||
try {
|
||||
cservice.destroyAnnotatedChannels(o);
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channels of template: "+o.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Clear global variables Jython
|
||||
JythonGlobalVariableDictionary.getInstance().clear();
|
||||
|
||||
// Destroy the CA context
|
||||
try {
|
||||
logger.fine("Destroy Channel Access context");
|
||||
ChannelBeanFactory.getFactory().getChannelFactory().destroyContext();
|
||||
} catch (IllegalStateException e) {
|
||||
logger.log(Level.SEVERE, "Unable to destroy channel access context", e);
|
||||
} catch (CAException e) {
|
||||
logger.log(Level.SEVERE, "Unable to destroy channel access context", e);
|
||||
}
|
||||
logger.fine("Context destroyed");
|
||||
cservice.destroy();
|
||||
logger.fine("ChannelService destroyed");
|
||||
|
||||
// Remove log handler
|
||||
if(logHandler!=null){
|
||||
@@ -474,13 +492,13 @@ public class Acquisition {
|
||||
else if(pm instanceof ChannelParameterMapping){
|
||||
ChannelParameterMapping cpm = (ChannelParameterMapping) pm;
|
||||
if(cpm.getType().equals("String")){
|
||||
mapping.add( new JythonParameterMappingChannel(cpm.getVariable(), cpm.getChannel(), String.class));
|
||||
mapping.add( new JythonParameterMappingChannel<String>(cpm.getVariable(), createChannel(String.class, cpm.getChannel())));
|
||||
}
|
||||
else if(cpm.getType().equals("Integer")){
|
||||
mapping.add( new JythonParameterMappingChannel(cpm.getVariable(), cpm.getChannel(), Integer.class));
|
||||
mapping.add( new JythonParameterMappingChannel<Integer>(cpm.getVariable(), createChannel(Integer.class, cpm.getChannel())));
|
||||
}
|
||||
else if(cpm.getType().equals("Double")){
|
||||
mapping.add( new JythonParameterMappingChannel(cpm.getVariable(), cpm.getChannel(), Double.class));
|
||||
mapping.add( new JythonParameterMappingChannel<Double>(cpm.getVariable(), createChannel(Double.class, cpm.getChannel())));
|
||||
}
|
||||
else{
|
||||
logger.warning("Channel type ["+cpm.getType()+"] is not supported for mapping");
|
||||
@@ -531,24 +549,24 @@ public class Acquisition {
|
||||
timeout = Math.round(ca.getTimeout()*1000);
|
||||
}
|
||||
if(type.equals("String")){
|
||||
alist.add(new ChannelAccessPut<String>(ca.getChannel(), ca.getValue(), false, timeout));
|
||||
alist.add(new ChannelAccessPut<String>(createChannel(String.class, ca.getChannel()), ca.getValue(), false, timeout));
|
||||
}
|
||||
else if(type.equals("Integer")){
|
||||
alist.add(new ChannelAccessPut<Integer>(ca.getChannel(), new Integer(ca.getValue()), false, timeout));
|
||||
alist.add(new ChannelAccessPut<Integer>(createChannel(Integer.class, ca.getChannel()), new Integer(ca.getValue()), false, timeout));
|
||||
}
|
||||
else if(type.equals("Double")){
|
||||
alist.add(new ChannelAccessPut<Double>(ca.getChannel(), new Double(ca.getValue()), false, timeout));
|
||||
alist.add(new ChannelAccessPut<Double>(createChannel(Double.class,ca.getChannel()), new Double(ca.getValue()), false, timeout));
|
||||
}
|
||||
}
|
||||
else if(operation.equals("putq")){
|
||||
if(type.equals("String")){
|
||||
alist.add(new ChannelAccessPut<String>(ca.getChannel(), ca.getValue(), true, null));
|
||||
alist.add(new ChannelAccessPut<String>(createChannel(String.class,ca.getChannel()), ca.getValue(), true, null));
|
||||
}
|
||||
else if(type.equals("Integer")){
|
||||
alist.add(new ChannelAccessPut<Integer>(ca.getChannel(), new Integer(ca.getValue()), true, null));
|
||||
alist.add(new ChannelAccessPut<Integer>(createChannel(Integer.class,ca.getChannel()), new Integer(ca.getValue()), true, null));
|
||||
}
|
||||
else if(type.equals("Double")){
|
||||
alist.add(new ChannelAccessPut<Double>(ca.getChannel(), new Double(ca.getValue()), true, null));
|
||||
alist.add(new ChannelAccessPut<Double>(createChannel(Double.class,ca.getChannel()), new Double(ca.getValue()), true, null));
|
||||
}
|
||||
}
|
||||
else if(operation.equals("wait")){
|
||||
@@ -557,13 +575,13 @@ public class Acquisition {
|
||||
timeout = Math.round(ca.getTimeout()*1000);
|
||||
}
|
||||
if(type.equals("String")){
|
||||
alist.add(new ChannelAccessCondition<String>(ca.getChannel(), ca.getValue(), timeout));
|
||||
alist.add(new ChannelAccessCondition<String>(createChannel(String.class,ca.getChannel()), ca.getValue(), timeout));
|
||||
}
|
||||
else if(type.equals("Integer")){
|
||||
alist.add(new ChannelAccessCondition<Integer>(ca.getChannel(), new Integer(ca.getValue()), timeout));
|
||||
alist.add(new ChannelAccessCondition<Integer>(createChannel(Integer.class,ca.getChannel()), new Integer(ca.getValue()), timeout));
|
||||
}
|
||||
else if(type.equals("Double")){
|
||||
alist.add(new ChannelAccessCondition<Double>(ca.getChannel(), new Double(ca.getValue()), timeout));
|
||||
alist.add(new ChannelAccessCondition<Double>(createChannel(Double.class,ca.getChannel()), new Double(ca.getValue()), timeout));
|
||||
}
|
||||
}
|
||||
else if(operation.equals("waitREGEX")){
|
||||
@@ -572,7 +590,7 @@ public class Acquisition {
|
||||
timeout = Math.round(ca.getTimeout()*1000);
|
||||
}
|
||||
if(type.equals("String")){
|
||||
alist.add(new ChannelAccessConditionRegex(ca.getChannel(), ca.getValue(), timeout));
|
||||
alist.add(new ChannelAccessConditionRegex(createChannel(String.class, ca.getChannel()), ca.getValue(), timeout));
|
||||
}
|
||||
else{
|
||||
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
|
||||
@@ -585,7 +603,7 @@ public class Acquisition {
|
||||
}
|
||||
|
||||
if(type.equals("Integer")){
|
||||
alist.add(new ChannelAccessConditionOr(ca.getChannel(), new Integer(ca.getValue()), timeout));
|
||||
alist.add(new ChannelAccessConditionOr(createChannel(Integer.class,ca.getChannel()), new Integer(ca.getValue()), timeout));
|
||||
}
|
||||
else{
|
||||
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
|
||||
@@ -597,7 +615,7 @@ public class Acquisition {
|
||||
timeout = Math.round(ca.getTimeout()*1000);
|
||||
}
|
||||
if(type.equals("Integer")){
|
||||
alist.add(new ChannelAccessConditionAnd(ca.getChannel(), new Integer(ca.getValue()), timeout));
|
||||
alist.add(new ChannelAccessConditionAnd(createChannel(Integer.class,ca.getChannel()), new Integer(ca.getValue()), timeout));
|
||||
}
|
||||
else {
|
||||
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
|
||||
@@ -631,22 +649,23 @@ public class Acquisition {
|
||||
// TODO set global variables DATAFILE and FILENAME
|
||||
|
||||
// TODO create Jython Action
|
||||
List<JythonParameterMappingChannel> mapping = new ArrayList<JythonParameterMappingChannel>();
|
||||
Map<String, Channel<?>> mapping = new HashMap<>();
|
||||
for(ChannelParameterMapping ma: sa.getMapping()){
|
||||
if(ma.getType().equals("String")){
|
||||
mapping.add(new JythonParameterMappingChannel(ma.getVariable(), ma.getChannel(), String.class));
|
||||
mapping.put(ma.getVariable(), createChannel(String.class, ma.getChannel()));
|
||||
}
|
||||
else if(ma.getType().equals("Integer")){
|
||||
mapping.add(new JythonParameterMappingChannel(ma.getVariable(), ma.getChannel(), Integer.class));
|
||||
mapping.put(ma.getVariable(), createChannel(Integer.class, ma.getChannel()));
|
||||
}
|
||||
else if(ma.getType().equals("Double")){
|
||||
mapping.add(new JythonParameterMappingChannel(ma.getVariable(), ma.getChannel(), Double.class));
|
||||
mapping.put(ma.getVariable(), createChannel(Double.class, ma.getChannel()));
|
||||
}
|
||||
else{
|
||||
logger.warning("Channel type ["+ma.getType()+"] is not supported for mapping");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ch.psi.fda.core.actions.JythonAction ja = new ch.psi.fda.core.actions.JythonAction(sa.getScript(), mapping);
|
||||
ja.setVariable("FILENAME", datafile.getName().replaceAll("\\.\\w*$", ""));
|
||||
ja.setVariable("DATAFILE", datafile.getAbsoluteFile());
|
||||
@@ -683,14 +702,14 @@ public class Acquisition {
|
||||
LinearPositioner lp =(LinearPositioner) p;
|
||||
ChannelAccessLinearActuator<?> a;
|
||||
if(lp.getType().equals("String")){
|
||||
a = new ChannelAccessLinearActuator<String>(lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessLinearActuator<String>(createChannel(Double.class, lp.getName()), createChannel(String.class, lp.getDone()), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
else if(lp.getType().equals("Double")){
|
||||
a = new ChannelAccessLinearActuator<Double>(lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessLinearActuator<Double>(createChannel(Double.class, lp.getName()), createChannel(Double.class,lp.getDone()), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
else{
|
||||
// Default
|
||||
a = new ChannelAccessLinearActuator<Integer>(lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessLinearActuator<Integer>(createChannel(Double.class, lp.getName()), createChannel(Integer.class,lp.getDone()), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
|
||||
a.setAsynchronous(lp.isAsynchronous());
|
||||
@@ -703,7 +722,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), name);
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof FunctionPositioner){
|
||||
@@ -716,14 +735,14 @@ public class Acquisition {
|
||||
// Create actuator
|
||||
ChannelAccessFunctionActuator<?> a;
|
||||
if(lp.getType().equals("String")){
|
||||
a = new ChannelAccessFunctionActuator<String>(lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessFunctionActuator<String>(createChannel(Double.class,lp.getName()), createChannel(String.class,lp.getDone()), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
else if(lp.getType().equals("Double")){
|
||||
a = new ChannelAccessFunctionActuator<Double>(lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessFunctionActuator<Double>(createChannel(Double.class, lp.getName()), createChannel(Double.class, lp.getDone()), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
else{
|
||||
// Default
|
||||
a = new ChannelAccessFunctionActuator<Integer>(lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
a = new ChannelAccessFunctionActuator<Integer>(createChannel(Double.class, lp.getName()), createChannel(Integer.class, lp.getDone()), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout);
|
||||
}
|
||||
|
||||
a.setAsynchronous(lp.isAsynchronous());
|
||||
@@ -736,7 +755,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), name);
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof ArrayPositioner){
|
||||
@@ -749,14 +768,14 @@ public class Acquisition {
|
||||
|
||||
ChannelAccessTableActuator<?> a;
|
||||
if(p.getType().equals("String")){
|
||||
a = new ChannelAccessTableActuator<String>(p.getName(), p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout);
|
||||
a = new ChannelAccessTableActuator<String>(createChannel(Double.class, p.getName()), createChannel(String.class, p.getDone()), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout);
|
||||
}
|
||||
else if(p.getType().equals("Double")){
|
||||
a = new ChannelAccessTableActuator<Double>(p.getName(), p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout);
|
||||
a = new ChannelAccessTableActuator<Double>(createChannel(Double.class, p.getName()), createChannel(Double.class, p.getDone()), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout);
|
||||
}
|
||||
else{
|
||||
// Default
|
||||
a = new ChannelAccessTableActuator<Integer>(p.getName(), p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout);
|
||||
a = new ChannelAccessTableActuator<Integer>(createChannel(Double.class, p.getName()), createChannel(Integer.class, p.getDone()), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout);
|
||||
}
|
||||
|
||||
a.setAsynchronous(p.isAsynchronous());
|
||||
@@ -769,7 +788,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = ap.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(ap.getId(), name);
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(ap.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof RegionPositioner){
|
||||
@@ -802,14 +821,13 @@ public class Acquisition {
|
||||
// Create actuator
|
||||
ChannelAccessLinearActuator<?> act;
|
||||
if(rp.getType().equals("String")){
|
||||
act = new ChannelAccessLinearActuator<String>(rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessLinearActuator<String>(createChannel(Double.class, rp.getName()), createChannel(String.class, rp.getDone()), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
else if(rp.getType().equals("Double")){
|
||||
act = new ChannelAccessLinearActuator<Double>(rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessLinearActuator<Double>(createChannel(Double.class, rp.getName()), createChannel(Double.class, rp.getDone()), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
else{
|
||||
// Default
|
||||
act = new ChannelAccessLinearActuator<Integer>(rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessLinearActuator<Integer>(createChannel(Double.class, rp.getName()), createChannel(Integer.class, rp.getDone()), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
|
||||
act.setAsynchronous(rp.isAsynchronous());
|
||||
@@ -830,14 +848,14 @@ public class Acquisition {
|
||||
JythonFunction function = mapFunction(r.getFunction());
|
||||
ChannelAccessFunctionActuator<?> act;
|
||||
if(rp.getType().equals("String")){
|
||||
act = new ChannelAccessFunctionActuator<String>(rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessFunctionActuator<String>(createChannel(Double.class,rp.getName()), createChannel(String.class,rp.getDone()), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
else if(rp.getType().equals("Double")){
|
||||
act = new ChannelAccessFunctionActuator<Double>(rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessFunctionActuator<Double>(createChannel(Double.class, rp.getName()), createChannel(Double.class, rp.getDone()), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
else{
|
||||
// Default
|
||||
act = new ChannelAccessFunctionActuator<Integer>(rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
act = new ChannelAccessFunctionActuator<Integer>(createChannel(Double.class, rp.getName()), createChannel(Integer.class, rp.getDone()), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout);
|
||||
}
|
||||
|
||||
act.setAsynchronous(rp.isAsynchronous());
|
||||
@@ -857,7 +875,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = rp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(rp.getId(), name);
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(rp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof PseudoPositioner){
|
||||
@@ -891,20 +909,17 @@ public class Acquisition {
|
||||
Guard g = dimension.getGuard();
|
||||
if(g != null){
|
||||
// Map conditions
|
||||
List<ChannelAccessGuardCondition> conditions = new ArrayList<ChannelAccessGuardCondition>();
|
||||
List<ChannelAccessGuardCondition<?>> conditions = new ArrayList<>();
|
||||
for(GuardCondition con: g.getCondition()){
|
||||
Object value = null;
|
||||
if(con.getType().equals("Integer")){
|
||||
value = new Integer(con.getValue());
|
||||
conditions.add(new ChannelAccessGuardCondition<Integer>(createChannel(Integer.class, con.getChannel()), new Integer(con.getValue())));
|
||||
}
|
||||
else if(con.getType().equals("Double")){
|
||||
value = new Double(con.getValue());
|
||||
conditions.add(new ChannelAccessGuardCondition<Double>(createChannel(Double.class, con.getChannel()), new Double(con.getValue())));
|
||||
}
|
||||
else{
|
||||
value = con.getValue();
|
||||
conditions.add(new ChannelAccessGuardCondition<String>(createChannel(String.class, con.getChannel()), con.getValue()));
|
||||
}
|
||||
|
||||
conditions.add(new ChannelAccessGuardCondition(con.getChannel(), value));
|
||||
}
|
||||
// Create guard and add to loop
|
||||
ChannelAccessGuard guard = new ChannelAccessGuard(conditions);
|
||||
@@ -955,10 +970,10 @@ public class Acquisition {
|
||||
// Add sensor
|
||||
Sensor sensor;
|
||||
if(sd.getType().equals("String")){
|
||||
sensor = new ChannelAccessStringSensor(sd.getId(), sd.getName());
|
||||
sensor = new ChannelAccessStringSensor(sd.getId(), createChannel(String.class,sd.getName()));
|
||||
}
|
||||
else{
|
||||
sensor = new ChannelAccessDoubleSensor(sd.getId(), sd.getName());
|
||||
sensor = new ChannelAccessDoubleSensor(sd.getId(), createChannel(Double.class,sd.getName()));
|
||||
}
|
||||
|
||||
aLoop.getSensors().add(sensor);
|
||||
@@ -970,7 +985,7 @@ public class Acquisition {
|
||||
aLoop.getPreSensorActions().addAll(mapActions(ad.getPreAction()));
|
||||
|
||||
// Ad sensor
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor(ad.getId(), ad.getName(), ad.getArraySize());
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize()));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (detector instanceof DetectorOfDetectors){
|
||||
@@ -1013,7 +1028,11 @@ public class Acquisition {
|
||||
// Create loop
|
||||
boolean zigZag = dimension.isZigzag(); // default value is false
|
||||
|
||||
OTFLoop actionLoop = new OTFLoop(configuration.getOtfChannelPrefix(), configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag);
|
||||
Map<String,String> macros = new HashMap<>();
|
||||
macros.put("PREFIX", configuration.getOtfChannelPrefix());
|
||||
OTFBean template = new OTFBean();
|
||||
createTemplateChannels(template, macros);
|
||||
OTFLoop actionLoop = new OTFLoop(template, configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag);
|
||||
|
||||
actionLoop.getPreActions().addAll(mapActions(dimension.getPreAction()));
|
||||
|
||||
@@ -1072,7 +1091,8 @@ public class Acquisition {
|
||||
// Create loop
|
||||
boolean zigZag = dimension.isZigzag(); // default value is false
|
||||
|
||||
CrlogicLoop actionLoop = new CrlogicLoop(configuration.getOtfCrlogicPrefix(), configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag);
|
||||
// TODO rework CrlogicLoop class to accept templates here instead of cservice
|
||||
CrlogicLoop actionLoop = new CrlogicLoop(cservice, configuration.getOtfCrlogicPrefix(), configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag);
|
||||
actionLoop.setKeepTmpFiles(configuration.isOtfCrlogicKeepTmpFiles());
|
||||
|
||||
actionLoop.getPreActions().addAll(mapActions(dimension.getPreAction()));
|
||||
@@ -1115,14 +1135,17 @@ public class Acquisition {
|
||||
aLoop = actionLoop;
|
||||
}
|
||||
else{
|
||||
List<Sensor> sensors = new ArrayList<Sensor>();
|
||||
List<Channel<DoubleTimestamp>> sensors = new ArrayList<>();
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
for(SimpleScalarDetector detector: dimension.getDetector()){
|
||||
if(detector.isScr()){
|
||||
sensors.add(new ChannelAccessDoubleSensor(detector.getId(), detector.getName()));
|
||||
ids.add(detector.getId());
|
||||
sensors.add(createChannel(DoubleTimestamp.class, detector.getName()));
|
||||
}
|
||||
}
|
||||
// Create soft(ware) based crlogic
|
||||
ScrlogicLoop scrlogic = new ScrlogicLoop(sensors);
|
||||
ScrlogicLoop scrlogic = new ScrlogicLoop(ids, sensors);
|
||||
|
||||
// Create parallel logic
|
||||
ParallelCrlogic pcrlogic = new ParallelCrlogic(actionLoop, scrlogic);
|
||||
@@ -1135,4 +1158,51 @@ public class Acquisition {
|
||||
return aLoop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create channel and remember to be able to destroy channels at the end
|
||||
* @param name
|
||||
* @param type
|
||||
* @return null if the name of the channel is null, otherwise the channel
|
||||
*/
|
||||
private <T> Channel<T> createChannel(Class<T> type, String name){
|
||||
try {
|
||||
if(name== null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Channel<T> c = cservice.createChannel(new ChannelDescriptor<T>(type, name) );
|
||||
channels.add(c);
|
||||
return c;
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException("Unable to create channel: "+name,e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private <T> Channel<T> createChannel(Class<T> type, String name, int size){
|
||||
try {
|
||||
if(name== null){
|
||||
return null;
|
||||
}
|
||||
|
||||
Channel<T> c = cservice.createChannel(new ChannelDescriptor<T>(type, name, false, size) );
|
||||
channels.add(c);
|
||||
return c;
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException("Unable to create channel: "+name,e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createTemplateChannels(Object o, Map<String,String> macro){
|
||||
try {
|
||||
cservice.createAnnotatedChannels(o, macro);
|
||||
templates.add(o);
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException("Unable to initialize template: "+o.getClass().getName(),e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ch.psi.fda.aq;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
@@ -9,10 +9,6 @@ public class AcquisitionModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
try {
|
||||
bind(ChannelBeanFactory.class).toInstance(ChannelBeanFactory.getFactory());
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
bind(ChannelService.class).toInstance(new DefaultChannelService());
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,13 @@
|
||||
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
@@ -34,18 +35,10 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessCondition<E> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessCondition.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final ChannelBean<E> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
private final E expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
@@ -53,45 +46,25 @@ public class ChannelAccessCondition<E> implements Action {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel Channel to wait value for
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
* @throws IllegalArgumentException Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessCondition(String channelName, E expectedValue, Long timeout){
|
||||
public ChannelAccessCondition(Channel<E> channel, E expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
if(timeout != null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = (ChannelBean<E>) ChannelBeanFactory.getFactory().createChannelBean( (Class<E>) expectedValue.getClass(), channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
this.timeout = channel.getWaitTimeout();
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
@@ -100,12 +73,18 @@ public class ChannelAccessCondition<E> implements Action {
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
try {
|
||||
if(timeout == null){
|
||||
channel.waitForValue(expectedValue);
|
||||
}
|
||||
else{
|
||||
channel.waitForValue(expectedValue, timeout);
|
||||
}
|
||||
} catch (ExecutionException | ChannelException | TimeoutException | InterruptedException e) {
|
||||
if(abort && e instanceof InterruptedException){
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
}
|
||||
}
|
||||
finally{
|
||||
@@ -113,9 +92,6 @@ public class ChannelAccessCondition<E> implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
@@ -124,19 +100,8 @@ public class ChannelAccessCondition<E> implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Condition a channnel needs to match
|
||||
@@ -36,18 +36,10 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessConditionAnd implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionAnd.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final ChannelBean<Integer> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final Channel<Integer> channel;
|
||||
private final Integer expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
@@ -55,45 +47,23 @@ public class ChannelAccessConditionAnd implements Action {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel Channel to wait for
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
* @throws IllegalArgumentException Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionAnd(String channelName, Integer expectedValue, Long timeout){
|
||||
|
||||
public ChannelAccessConditionAnd(Channel<Integer> channel, Integer expectedValue, Long timeout){
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = (ChannelBean<Integer>) ChannelBeanFactory.getFactory().createChannelBean( (Class<Integer>) expectedValue.getClass(), channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.channel=channel;
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
this.timeout = channel.getWaitTimeout();
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
@@ -102,24 +72,25 @@ public class ChannelAccessConditionAnd implements Action {
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<Integer>() {
|
||||
try {
|
||||
channel.waitForValue(expectedValue, new Comparator<Integer>() {
|
||||
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one & two) != 0){
|
||||
return 0;
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one & two) != 0){
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
, timeout);
|
||||
} catch (ExecutionException | ChannelException e) {
|
||||
if(abort && e instanceof ExecutionException){
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
}
|
||||
}
|
||||
finally{
|
||||
@@ -127,9 +98,6 @@ public class ChannelAccessConditionAnd implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
@@ -139,18 +107,8 @@ public class ChannelAccessConditionAnd implements Action {
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Or condition of a channel
|
||||
@@ -36,18 +36,10 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessConditionOr implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionOr.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final ChannelBean<Integer> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final Channel<Integer> channel;
|
||||
private final Integer expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
@@ -55,43 +47,23 @@ public class ChannelAccessConditionOr implements Action {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
* @throws IllegalArgumentException Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionOr(String channelName, Integer expectedValue, Long timeout){
|
||||
public ChannelAccessConditionOr(Channel<Integer> channel, Integer expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = (ChannelBean<Integer>) ChannelBeanFactory.getFactory().createChannelBean( (Class<Integer>) expectedValue.getClass(), channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
this.timeout = channel.getWaitTimeout();
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
@@ -102,24 +74,25 @@ public class ChannelAccessConditionOr implements Action {
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<Integer>() {
|
||||
try {
|
||||
channel.waitForValue(expectedValue, new Comparator<Integer>() {
|
||||
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one | two) != 0){
|
||||
return 0;
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one | two) != 0){
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
, timeout);
|
||||
} catch (ExecutionException | ChannelException e) {
|
||||
if(abort && e instanceof ExecutionException){
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
}
|
||||
}
|
||||
finally{
|
||||
@@ -127,9 +100,6 @@ public class ChannelAccessConditionOr implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
@@ -139,18 +109,8 @@ public class ChannelAccessConditionOr implements Action {
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Regex condition
|
||||
@@ -35,18 +35,10 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessConditionRegex implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionRegex.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final ChannelBean<String> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final Channel<String> channel;
|
||||
private final String expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
@@ -54,43 +46,24 @@ public class ChannelAccessConditionRegex implements Action {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
* @throws IllegalArgumentException Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionRegex(String channelName, String expectedValue, Long timeout){
|
||||
public ChannelAccessConditionRegex(Channel<String> channel, String expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = (ChannelBean<String>) ChannelBeanFactory.getFactory().createChannelBean( (Class<String>) expectedValue.getClass(), channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.channel=channel;
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
this.timeout = channel.getWaitTimeout();
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
@@ -101,28 +74,26 @@ public class ChannelAccessConditionRegex implements Action {
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<String>() {
|
||||
try {
|
||||
channel.waitForValue(expectedValue, new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.matches(o2) ? 0:1;
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.matches(o2) ? 0:1;
|
||||
}
|
||||
}, timeout);
|
||||
} catch (ExecutionException | ChannelException e) {
|
||||
if(abort && e instanceof ExecutionException){
|
||||
return;
|
||||
}
|
||||
}, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
}
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
}
|
||||
finally{
|
||||
waitT=null;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
@@ -131,19 +102,8 @@ public class ChannelAccessConditionRegex implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@
|
||||
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
@@ -36,42 +38,21 @@ public class ChannelAccessPut<E> implements Action {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessPut.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final ChannelBean<E> channel;
|
||||
/**
|
||||
* Value to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
private final E value;
|
||||
/**
|
||||
* Put mode, true = fire and forget, false = wait for response
|
||||
*/
|
||||
private final boolean asynchronous;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel
|
||||
* @param value Value to set
|
||||
* @param asynchronous Flag whether to set the value synchronous (wait for response) or asynchronously (fire and forget)
|
||||
* @param timeout Timeout used for set operation (time that set need to come back)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessPut(String channelName, E value, boolean asynchronous, Long timeout){
|
||||
public ChannelAccessPut(Channel<E> channel, E value, boolean asynchronous, Long timeout){
|
||||
|
||||
try {
|
||||
this.channel = ChannelBeanFactory.getFactory().createChannelBean((Class<E>)value.getClass(), channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.value = value;
|
||||
this.asynchronous = asynchronous;
|
||||
this.timeout = timeout;
|
||||
@@ -79,17 +60,14 @@ public class ChannelAccessPut<E> implements Action {
|
||||
|
||||
/**
|
||||
* Additional constructor for convenience. This constructor defaults the operation type to synchronous put.
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param channel
|
||||
* @param value Value to set
|
||||
*
|
||||
* @throws RuntimeException Unable to initialize channel
|
||||
*/
|
||||
public ChannelAccessPut(String channelName, E value){
|
||||
this(channelName, value, false, null);
|
||||
public ChannelAccessPut(Channel<E> channel, E value){
|
||||
this(channel, value, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Cannot set value on channel
|
||||
*/
|
||||
@Override
|
||||
@@ -104,28 +82,20 @@ public class ChannelAccessPut<E> implements Action {
|
||||
channel.setValue(value);
|
||||
}
|
||||
else{
|
||||
channel.setValue(value, timeout);
|
||||
channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
} catch (ExecutionException | TimeoutException | ChannelException e) {
|
||||
throw new RuntimeException("Unable to set channel [name:"+channel.getName()+"] to value "+value, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort() {
|
||||
// This action cannot be aborted, therefore this method is not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -33,10 +31,6 @@ import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
|
||||
/**
|
||||
* Executes a python script inside a Jython interpreter
|
||||
@@ -57,7 +51,7 @@ public class JythonAction implements Action {
|
||||
|
||||
private Map<String,Object> gvariables = new HashMap<String,Object>();
|
||||
|
||||
public JythonAction(String script, List<JythonParameterMappingChannel> mapping){
|
||||
public JythonAction(String script, Map<String, ?> mapping){
|
||||
|
||||
// Workaround for Jython memory leak
|
||||
// http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/
|
||||
@@ -72,6 +66,7 @@ public class JythonAction implements Action {
|
||||
String[] functionParameters = null;
|
||||
if(matcher.find() && matcher.groupCount()==1){
|
||||
logger.finest("Entry function '"+entryFunctionPattern+"' found - Identified parameters: "+matcher.group(1));
|
||||
jythonCall = entryFunction+"("+matcher.group(1)+")";
|
||||
if(matcher.group(1).matches(" *")){
|
||||
functionParameters = new String[0];
|
||||
}
|
||||
@@ -88,8 +83,8 @@ public class JythonAction implements Action {
|
||||
String p = functionParameters[i];
|
||||
p = p.trim();
|
||||
boolean found = false;
|
||||
for(JythonParameterMapping pm: mapping){
|
||||
if(pm.getVariable().equals(p)){
|
||||
for(String pm: mapping.keySet()){
|
||||
if(pm.equals(p)){
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
@@ -111,36 +106,12 @@ public class JythonAction implements Action {
|
||||
throw new RuntimeException("Unable to load manipulation script", e);
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(entryFunction);
|
||||
buffer.append("( "); // Need to have trailing space as otherwise there will be a problem if no paramters are specified
|
||||
for(JythonParameterMappingChannel b: mapping){
|
||||
// Create channel
|
||||
|
||||
ChannelBean<?> cb;
|
||||
try {
|
||||
cb = ChannelBeanFactory.getFactory().createChannelBean(b.getType(), b.getChannel(), true);
|
||||
} catch (CAException e) {
|
||||
throw new IllegalArgumentException("Unable to establish channel: "+b.getChannel(), e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to establish channel: "+b.getChannel(), e);
|
||||
}
|
||||
|
||||
for(String b: mapping.keySet()){
|
||||
// Assign channel bean to variable
|
||||
engine.put(b.getVariable(), cb);
|
||||
|
||||
buffer.append(b.getVariable());
|
||||
buffer.append(",");
|
||||
engine.put(b, mapping.get(b));
|
||||
}
|
||||
buffer.setCharAt(buffer.length()-1, ')');
|
||||
|
||||
jythonCall = buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
@@ -153,7 +124,7 @@ public class JythonAction implements Action {
|
||||
}
|
||||
|
||||
try {
|
||||
engine.eval(jythonCall);
|
||||
engine.eval(jythonCall+"\n");
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Action failed while executing the Jython script",e);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
|
||||
package ch.psi.fda.core.actors;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
|
||||
@@ -73,8 +74,8 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
private final double originalEnd;
|
||||
private final int originalDirection;
|
||||
|
||||
private ChannelBean<Double> channel;
|
||||
private ChannelBean<T> doneChannel = null;
|
||||
private Channel<Double> channel;
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final Function function;
|
||||
|
||||
@@ -86,14 +87,14 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
public ChannelAccessFunctionActuator(String channelName, Function function, double start, double end, double stepSize, Long timeout){
|
||||
this(channelName, null, null, 0, function, start, end, stepSize, timeout);
|
||||
public ChannelAccessFunctionActuator(Channel<Double> channel, Function function, double start, double end, double stepSize, Long timeout){
|
||||
this(channel, null, null, 0, function, start, end, stepSize, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName If null actor will not wait (for this channel) to continue
|
||||
* @param channel
|
||||
* @param doneChannel If null actor will not wait (for this channel) to continue
|
||||
* @param doneValue
|
||||
* @param doneDelay Delay in seconds before checking the done channel
|
||||
* @param start
|
||||
@@ -101,8 +102,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessFunctionActuator(String channelName, String doneChannelName, T doneValue, double doneDelay, Function function, double start, double end, double stepSize, Long timeout){
|
||||
public ChannelAccessFunctionActuator(Channel<Double> channel, Channel<T> doneChannel, T doneValue, double doneDelay, Function function, double start, double end, double stepSize, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
@@ -137,26 +137,8 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
this.originalEnd = end;
|
||||
this.originalDirection = direction;
|
||||
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class<T>)doneValue.getClass(), doneChannelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
this.channel = channel;
|
||||
this.doneChannel = doneChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,7 +159,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
channel.setValue(fvalue);
|
||||
}
|
||||
else{
|
||||
channel.setValue(fvalue, timeout);
|
||||
channel.setValueAsync(fvalue).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -198,8 +180,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
} catch (ExecutionException | TimeoutException | ChannelException e) {
|
||||
throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e);
|
||||
}
|
||||
|
||||
@@ -236,8 +217,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
if(start>end){
|
||||
direction=-1; // Move in negative direction
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set first set value to the start value
|
||||
this.value = start;
|
||||
this.next = true;
|
||||
@@ -266,23 +246,6 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
|
||||
package ch.psi.fda.core.actors;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel from a start to an end value by doing discrete steps.
|
||||
@@ -78,13 +79,13 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
|
||||
private Long timeout; // Set timeout
|
||||
|
||||
private final ChannelBean<Double> channel;
|
||||
private final ChannelBean<T> doneChannel;
|
||||
private final Channel<Double> channel;
|
||||
private final Channel<T> doneChannel;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName If null actor will not wait (for this channel) to continue
|
||||
* @param channel
|
||||
* @param doneChannel If null actor will not wait (for this channel) to continue
|
||||
* @param doneValue
|
||||
* @param doneDelay Delay in seconds before checking the done channel
|
||||
* @param start
|
||||
@@ -92,8 +93,7 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessLinearActuator(String channelName, String doneChannelName, T doneValue, double doneDelay, double start, double end, double stepSize, Long timeout){
|
||||
public ChannelAccessLinearActuator(Channel<Double> channel, Channel<T> doneChannel, T doneValue, double doneDelay, double start, double end, double stepSize, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
@@ -123,30 +123,8 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
this.originalEnd = end;
|
||||
this.originalDirection = direction;
|
||||
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class<T>) doneValue.getClass(), doneChannelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
doneChannel=null;
|
||||
}
|
||||
this.channel = channel;
|
||||
this.doneChannel = doneChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,7 +144,7 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
channel.setValue(value);
|
||||
}
|
||||
else{
|
||||
channel.setValue(value, timeout);
|
||||
channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -187,8 +165,7 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
} catch (ExecutionException | TimeoutException | ChannelException e) {
|
||||
throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e);
|
||||
}
|
||||
|
||||
@@ -251,23 +228,6 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
|
||||
package ch.psi.fda.core.actors;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel by using the positions from the given table.
|
||||
@@ -62,15 +63,8 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
private boolean next;
|
||||
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private ChannelBean<Double> channel;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private ChannelBean<T> doneChannel = null;
|
||||
private Channel<Double> channel;
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final T doneValue;
|
||||
private final long doneDelay;
|
||||
@@ -93,21 +87,20 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
* @param table Position table with the explicit positions for each step
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
public ChannelAccessTableActuator(String channelName, double[] table, Long timeout){
|
||||
this(channelName, null, null, 0, table, timeout);
|
||||
public ChannelAccessTableActuator(Channel<Double> channel, double[] table, Long timeout){
|
||||
this(channel, null, null, 0, table, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName
|
||||
* @param channel
|
||||
* @param doneChannel
|
||||
* @param doneValue
|
||||
* @param doneDelay
|
||||
* @param table
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessTableActuator(String channelName, String doneChannelName, T doneValue, double doneDelay, double[] table, Long timeout){
|
||||
public ChannelAccessTableActuator(Channel<Double> channel, Channel<T> doneChannel, T doneValue, double doneDelay, double[] table, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
@@ -134,26 +127,8 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
// Save the initial direction
|
||||
this.originalPositiveDirection = positiveDirection;
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class<T>)doneValue.getClass(), doneChannelName, false);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
this.channel = channel;
|
||||
this.doneChannel = doneChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,7 +147,7 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
channel.setValue(table[count]);
|
||||
}
|
||||
else{
|
||||
channel.setValue(table[count], timeout);
|
||||
channel.setValueAsync(table[count]).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -192,8 +167,7 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
} catch (ExecutionException | ChannelException | TimeoutException e) {
|
||||
throw new RuntimeException("Move actuator [channel: "+channel.getName()+"] to value "+table[count],e);
|
||||
}
|
||||
|
||||
@@ -257,23 +231,6 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
|
||||
@@ -19,15 +19,16 @@
|
||||
|
||||
package ch.psi.fda.core.guard;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Guard;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Guard checking channels to meet a certain condition
|
||||
@@ -37,7 +38,6 @@ import ch.psi.fda.core.Guard;
|
||||
public class ChannelAccessGuard implements Guard {
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessGuard.class.getName());
|
||||
|
||||
/**
|
||||
@@ -46,18 +46,18 @@ public class ChannelAccessGuard implements Guard {
|
||||
*/
|
||||
private boolean check = true;
|
||||
|
||||
private final List<ChannelAccessGuardCondition> conditions;
|
||||
private final List<ChannelAccessGuardCondition<?>> conditions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conditions
|
||||
*/
|
||||
public ChannelAccessGuard(List<ChannelAccessGuardCondition> conditions){
|
||||
public ChannelAccessGuard(List<ChannelAccessGuardCondition<?>> conditions){
|
||||
|
||||
this.conditions = conditions;
|
||||
|
||||
// Create channel that contribute to the status of the guard
|
||||
for(final ChannelAccessGuardCondition condition: conditions){
|
||||
for(final ChannelAccessGuardCondition<?> condition: conditions){
|
||||
condition.getChannel().addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
@@ -69,15 +69,12 @@ public class ChannelAccessGuard implements Guard {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
check = true;
|
||||
|
||||
// Check one time if all conditions are met
|
||||
for(ChannelAccessGuardCondition condition: conditions){
|
||||
for(ChannelAccessGuardCondition<?> condition: conditions){
|
||||
try{
|
||||
if(! (condition.getChannel().getValue(true)).equals(condition.getValue()) ){
|
||||
check=false;
|
||||
@@ -85,33 +82,22 @@ public class ChannelAccessGuard implements Guard {
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(CAException e){
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException("Guard interrupted ",e);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
logger.log(Level.WARNING, "Unable ", e);
|
||||
check=false;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Guard interrupted ",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#check()
|
||||
*/
|
||||
@Override
|
||||
public boolean check() {
|
||||
return check;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy Guard Conditions
|
||||
for(ChannelAccessGuardCondition condition: conditions){
|
||||
condition.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,78 +19,24 @@
|
||||
|
||||
package ch.psi.fda.core.guard;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import ch.psi.jcae.Channel;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
public class ChannelAccessGuardCondition<T> {
|
||||
|
||||
private final Channel<T> channel;
|
||||
private final T value; // Value of the channel to meet condition
|
||||
|
||||
/**
|
||||
* Channel and condition that need to be met.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessGuardCondition {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessGuardCondition.class.getName());
|
||||
|
||||
/**
|
||||
* Channel name
|
||||
*/
|
||||
private final ChannelBean<?> channel;
|
||||
|
||||
/**
|
||||
* Value of the channel to meet condition
|
||||
*/
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channel Name of the channel that contributes to a guard
|
||||
* @param value
|
||||
*/
|
||||
public ChannelAccessGuardCondition(String channel, Object value){
|
||||
try {
|
||||
this.channel = ChannelBeanFactory.getFactory().createChannelBean(value.getClass(), channel, true);
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channel+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channel+"]",e);
|
||||
}
|
||||
public ChannelAccessGuardCondition(Channel<T> channel, T value){
|
||||
this.channel = channel;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channel
|
||||
*/
|
||||
public ChannelBean<?> getChannel() {
|
||||
public Channel<T> getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy guard condition.
|
||||
* Can be used for the cleanup of used resources of the guard condition (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the guard condition must not be used any more!
|
||||
*/
|
||||
public void destroy(){
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy guard condition channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
|
||||
package ch.psi.fda.core.loops;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Bean holding all OTF channels and functionality
|
||||
@@ -39,101 +40,101 @@ public class OTFBean {
|
||||
private long timeoutMotorOk = 8000;
|
||||
private long commandTimeout = 20000; // Maximum time until a command should take effect
|
||||
|
||||
@CaChannel(type=String.class, name =":UMOT")
|
||||
private ChannelBean<String> motor;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:UMOT")
|
||||
private Channel<String> motor;
|
||||
|
||||
@CaChannel(type=String.class, name=":MENC")
|
||||
private ChannelBean<String> encoder;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:MENC")
|
||||
private Channel<String> encoder;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UBEG")
|
||||
private ChannelBean<Double> begin;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG")
|
||||
private Channel<Double> begin;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UBEG.DRVL")
|
||||
private ChannelBean<Double> beginMin;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVL")
|
||||
private Channel<Double> beginMin;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UBEG.DRVH")
|
||||
private ChannelBean<Double> beginMax;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVH")
|
||||
private Channel<Double> beginMax;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UEND")
|
||||
private ChannelBean<Double> end;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UEND")
|
||||
private Channel<Double> end;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UEND.DRVL")
|
||||
private ChannelBean<Double> endMin;
|
||||
private Channel<Double> endMin;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UEND.DRVH")
|
||||
private ChannelBean<Double> endMax;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UEND.DRVH")
|
||||
private Channel<Double> endMax;
|
||||
|
||||
@CaChannel(type=Double.class, name=":USSIZ")
|
||||
private ChannelBean<Double> stepSize;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:USSIZ")
|
||||
private Channel<Double> stepSize;
|
||||
|
||||
@CaChannel(type=Double.class, name=":USSIZ.DRVL")
|
||||
private ChannelBean<Double> stepSizeMin;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:USSIZ.DRVL")
|
||||
private Channel<Double> stepSizeMin;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UITIM")
|
||||
private ChannelBean<Double> integrationTime;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM")
|
||||
private Channel<Double> integrationTime;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UITIM.DRVL")
|
||||
private ChannelBean<Double> integrationTimeMin;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVL")
|
||||
private Channel<Double> integrationTimeMin;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UITIM.DRVH")
|
||||
private ChannelBean<Double> integrationTimeMax;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVH")
|
||||
private Channel<Double> integrationTimeMax;
|
||||
|
||||
@CaChannel(type=Double.class, name=":UBCL")
|
||||
private ChannelBean<Double> userBacklash;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBCL")
|
||||
private Channel<Double> userBacklash;
|
||||
|
||||
@CaChannel(type=String.class, name=":NFSSE")
|
||||
private ChannelBean<String> nfsServer;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:NFSSE")
|
||||
private Channel<String> nfsServer;
|
||||
|
||||
@CaChannel(type=String.class, name=":NFSSH")
|
||||
private ChannelBean<String> nfsShare;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:NFSSH")
|
||||
private Channel<String> nfsShare;
|
||||
|
||||
@CaChannel(type=String.class, name=":DFNAM")
|
||||
private ChannelBean<String> fileName;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:DFNAM")
|
||||
private Channel<String> fileName;
|
||||
|
||||
@CaChannel(type=String.class, name=":FFORM")
|
||||
private ChannelBean<String> fileNameFormat;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:FFORM")
|
||||
private Channel<String> fileNameFormat;
|
||||
|
||||
@CaChannel(type=Integer.class, name=":FCNT")
|
||||
private ChannelBean<Integer> fileCount;
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:FCNT")
|
||||
private Channel<Integer> fileCount;
|
||||
|
||||
@CaChannel(type=Integer.class, name=":FCNT.B")
|
||||
private ChannelBean<Integer> resetFileCounter;
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:FCNT.B")
|
||||
private Channel<Integer> resetFileCounter;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":FAPPE")
|
||||
private ChannelBean<Boolean> appendFile;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:FAPPE")
|
||||
private Channel<Boolean> appendFile;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":FUSE")
|
||||
private ChannelBean<Boolean> fileNameGeneration;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:FUSE")
|
||||
private Channel<Boolean> fileNameGeneration;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":UZIGZ")
|
||||
private ChannelBean<Boolean> zigZag;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:UZIGZ")
|
||||
private Channel<Boolean> zigZag;
|
||||
|
||||
@CaChannel(type=Integer.class, name=":UCOM")
|
||||
private ChannelBean<Integer> command;
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:UCOM")
|
||||
private Channel<Integer> command;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":SCRU", monitor=true)
|
||||
private ChannelBean<Boolean> scanRunning;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:SCRU", monitor=true)
|
||||
private Channel<Boolean> scanRunning;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":MUENC")
|
||||
private ChannelBean<Boolean> useEncoder;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:MUENC")
|
||||
private Channel<Boolean> useEncoder;
|
||||
|
||||
@CaChannel(type=String.class, name={":CTM0",":CTM1",":CTM2",":CTM3",":CTM4",":CTM5",":CTM6",":CTM7"})
|
||||
private List<ChannelBean<String>> monitoredChannels;
|
||||
@CaChannel(type=String.class, name={"${PREFIX}:CTM0","${PREFIX}:CTM1","${PREFIX}:CTM2","${PREFIX}:CTM3","${PREFIX}:CTM4","${PREFIX}:CTM5","${PREFIX}:CTM6","${PREFIX}:CTM7"})
|
||||
private List<Channel<String>> monitoredChannels;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":OTF", monitor=true)
|
||||
private ChannelBean<Boolean> running;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:OTF", monitor=true)
|
||||
private Channel<Boolean> running;
|
||||
|
||||
@CaChannel(type=Integer.class, name=":USTAT", monitor=true)
|
||||
private ChannelBean<Integer> status;
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:USTAT", monitor=true)
|
||||
private Channel<Integer> status;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":MOK", monitor=true)
|
||||
private ChannelBean<Boolean> motorOk;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:MOK", monitor=true)
|
||||
private Channel<Boolean> motorOk;
|
||||
|
||||
@CaChannel(type=Boolean.class, name=":EOK", monitor=true)
|
||||
private ChannelBean<Boolean> encoderOk;
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:EOK", monitor=true)
|
||||
private Channel<Boolean> encoderOk;
|
||||
|
||||
@CaChannel(type=String.class, name=":MSG")
|
||||
private ChannelBean<String> message;
|
||||
@CaChannel(type=String.class, name="${PREFIX}:MSG")
|
||||
private Channel<String> message;
|
||||
|
||||
/**
|
||||
* Get the trigger name that can be used by the sscan record to trigger an OTFScan
|
||||
@@ -210,7 +211,7 @@ public class OTFBean {
|
||||
throw new RuntimeException("OTFSCAN failed with message: "+message.getValue());
|
||||
}
|
||||
|
||||
} catch (CAException e) {
|
||||
} catch (ExecutionException | ChannelException | TimeoutException e) {
|
||||
throw new RuntimeException("An error occurred while waiting for the OTF logic to finish.", e);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +230,7 @@ public class OTFBean {
|
||||
throw new RuntimeException("OTFSCAN failed with message: "+message.getValue());
|
||||
}
|
||||
|
||||
} catch (CAException e) {
|
||||
} catch (ExecutionException | ChannelException | TimeoutException e) {
|
||||
throw new RuntimeException("An error occurred while waiting for the OTF logic to finish.", e);
|
||||
}
|
||||
|
||||
@@ -242,7 +243,8 @@ public class OTFBean {
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void resetToDefaults() throws CAException, InterruptedException{
|
||||
public void resetToDefaults() throws InterruptedException{
|
||||
try{
|
||||
setMonitoredChannels(new String[]{});
|
||||
setMotor("");
|
||||
begin.setValue(0d);
|
||||
@@ -262,6 +264,10 @@ public class OTFBean {
|
||||
// setNfsShare("");
|
||||
|
||||
waitUntilMotorNotOk(timeoutMotorOk);
|
||||
}
|
||||
catch(ExecutionException | ChannelException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,8 +275,12 @@ public class OTFBean {
|
||||
* @return Name of the OTF motor
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getMotor() throws CAException, InterruptedException {
|
||||
return(this.motor.getValue());
|
||||
public String getMotor() throws InterruptedException {
|
||||
try {
|
||||
return(this.motor.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,8 +288,12 @@ public class OTFBean {
|
||||
* @param motor
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setMotor(String motor) throws CAException, InterruptedException {
|
||||
this.motor.setValue(motor);
|
||||
public void setMotor(String motor) throws InterruptedException {
|
||||
try{
|
||||
this.motor.setValue(motor);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,8 +301,12 @@ public class OTFBean {
|
||||
* @return Name of the used encoder
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getEncoder() throws CAException, InterruptedException {
|
||||
return(this.encoder.getValue());
|
||||
public String getEncoder() throws InterruptedException {
|
||||
try{
|
||||
return(this.encoder.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,8 +314,12 @@ public class OTFBean {
|
||||
* @param encoder
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setEncoder(String encoder) throws CAException, InterruptedException {
|
||||
this.encoder.setValue(encoder);
|
||||
public void setEncoder(String encoder) throws InterruptedException {
|
||||
try{
|
||||
this.encoder.setValue(encoder);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,8 +327,12 @@ public class OTFBean {
|
||||
* @return Begin position scan
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getBegin() throws CAException, InterruptedException {
|
||||
return(this.begin.getValue());
|
||||
public Double getBegin() throws InterruptedException {
|
||||
try{
|
||||
return(this.begin.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,17 +340,20 @@ public class OTFBean {
|
||||
* @param begin
|
||||
* @throws Exception
|
||||
*/
|
||||
public void setBegin(Double begin) throws CAException, InterruptedException {
|
||||
|
||||
if(begin==null){
|
||||
throw new IllegalArgumentException("Begin position must not be null");
|
||||
public void setBegin(Double begin) throws InterruptedException {
|
||||
try{
|
||||
if(begin==null){
|
||||
throw new IllegalArgumentException("Begin position must not be null");
|
||||
}
|
||||
|
||||
if(begin < beginMin.getValue() || begin > beginMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set begin value to "+begin+ ". Value is outside range [min: "+beginMin.getValue()+" max: "+beginMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.begin.setValue(begin);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if(begin < beginMin.getValue() || begin > beginMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set begin value to "+begin+ ". Value is outside range [min: "+beginMin.getValue()+" max: "+beginMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.begin.setValue(begin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,8 +361,12 @@ public class OTFBean {
|
||||
* @return Min value for begin
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMinBegin() throws CAException, InterruptedException {
|
||||
return(this.beginMin.getValue());
|
||||
public Double getMinBegin() throws InterruptedException {
|
||||
try{
|
||||
return(this.beginMin.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,8 +374,12 @@ public class OTFBean {
|
||||
* @return Max value for begin
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMaxBegin() throws CAException, InterruptedException {
|
||||
return(this.beginMax.getValue());
|
||||
public Double getMaxBegin() throws InterruptedException {
|
||||
try{
|
||||
return(this.beginMax.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,8 +387,12 @@ public class OTFBean {
|
||||
* @return End position scan
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getEnd() throws CAException, InterruptedException {
|
||||
return(this.end.getValue());
|
||||
public Double getEnd() throws InterruptedException {
|
||||
try{
|
||||
return(this.end.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,17 +400,20 @@ public class OTFBean {
|
||||
* @param end
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setEnd(Double end) throws CAException, InterruptedException {
|
||||
|
||||
if(end==null){
|
||||
throw new IllegalArgumentException("End position must not be null");
|
||||
public void setEnd(Double end) throws InterruptedException {
|
||||
try{
|
||||
if(end==null){
|
||||
throw new IllegalArgumentException("End position must not be null");
|
||||
}
|
||||
|
||||
if(end < endMin.getValue() || end > endMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set end value to "+end+ ". Value is outside range [min: "+endMin.getValue()+" max: "+endMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.end.setValue(end);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if(end < endMin.getValue() || end > endMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set end value to "+end+ ". Value is outside range [min: "+endMin.getValue()+" max: "+endMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.end.setValue(end);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,16 +421,24 @@ public class OTFBean {
|
||||
* @return Min value for end
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMinEnd() throws CAException, InterruptedException {
|
||||
return(this.endMin.getValue());
|
||||
public Double getMinEnd() throws InterruptedException {
|
||||
try{
|
||||
return(this.endMin.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get maximum value of end position
|
||||
* @return Max value for end
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMaxEnd() throws CAException, InterruptedException {
|
||||
return(this.endMax.getValue());
|
||||
public Double getMaxEnd() throws InterruptedException {
|
||||
try{
|
||||
return(this.endMax.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,8 +446,12 @@ public class OTFBean {
|
||||
* @return Step size
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getStepSize() throws CAException, InterruptedException {
|
||||
return(this.stepSize.getValue());
|
||||
public Double getStepSize() throws InterruptedException {
|
||||
try{
|
||||
return(this.stepSize.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,21 +459,24 @@ public class OTFBean {
|
||||
* @param stepSize
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setStepSize(Double stepSize) throws CAException, InterruptedException {
|
||||
|
||||
if(integrationTime==null){
|
||||
throw new IllegalArgumentException("Step size must not be null");
|
||||
public void setStepSize(Double stepSize) throws InterruptedException {
|
||||
try{
|
||||
if(integrationTime==null){
|
||||
throw new IllegalArgumentException("Step size must not be null");
|
||||
}
|
||||
|
||||
// Check if step size is greater than min step size
|
||||
if(stepSizeMin.getValue() != 0 && stepSize < stepSizeMin.getValue()){
|
||||
throw new IllegalArgumentException("Step size value ["+stepSize+"] is less than minimum step size ["+stepSizeMin.getValue()+"]!");
|
||||
}
|
||||
|
||||
this.stepSize.setValue(stepSize);
|
||||
|
||||
// TODO WORKAROUND - Wait to "ensure" that step size related fields are updated (i.e. min/max integration time)
|
||||
Thread.sleep(1);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Check if step size is greater than min step size
|
||||
if(stepSizeMin.getValue() != 0 && stepSize < stepSizeMin.getValue()){
|
||||
throw new IllegalArgumentException("Step size value ["+stepSize+"] is less than minimum step size ["+stepSizeMin.getValue()+"]!");
|
||||
}
|
||||
|
||||
this.stepSize.setValue(stepSize);
|
||||
|
||||
// TODO WORKAROUND - Wait to "ensure" that step size related fields are updated (i.e. min/max integration time)
|
||||
Thread.sleep(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,8 +484,12 @@ public class OTFBean {
|
||||
* @return Min value for step size
|
||||
* @throws CAException
|
||||
*/
|
||||
public double getMinStepSize() throws CAException, InterruptedException {
|
||||
return(this.stepSizeMin.getValue());
|
||||
public double getMinStepSize() throws InterruptedException {
|
||||
try{
|
||||
return(this.stepSizeMin.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,8 +497,12 @@ public class OTFBean {
|
||||
* @return Integration time
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getIntegrationTime() throws CAException, InterruptedException {
|
||||
return(this.integrationTime.getValue());
|
||||
public Double getIntegrationTime() throws InterruptedException {
|
||||
try{
|
||||
return(this.integrationTime.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,8 +510,8 @@ public class OTFBean {
|
||||
* @param integrationTime
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setIntegrationTime(Double integrationTime) throws CAException, InterruptedException {
|
||||
|
||||
public void setIntegrationTime(Double integrationTime) throws InterruptedException {
|
||||
try{
|
||||
if(integrationTime==null){
|
||||
throw new IllegalArgumentException("Integration time must not be null");
|
||||
}
|
||||
@@ -467,6 +534,9 @@ public class OTFBean {
|
||||
}
|
||||
|
||||
this.integrationTime.setValue(integrationTime);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -474,16 +544,24 @@ public class OTFBean {
|
||||
* @return Min value for integration time
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMinIntegrationTime() throws CAException, InterruptedException {
|
||||
public Double getMinIntegrationTime() throws InterruptedException {
|
||||
try{
|
||||
return(this.integrationTimeMin.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get maximum integration time
|
||||
* @return Max value for integration time
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getMaxIntegrationTime() throws CAException, InterruptedException {
|
||||
public Double getMaxIntegrationTime() throws InterruptedException {
|
||||
try{
|
||||
return(this.integrationTimeMax.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,8 +569,12 @@ public class OTFBean {
|
||||
* @return User backlash
|
||||
* @throws CAException
|
||||
*/
|
||||
public Double getUserBacklash() throws CAException, InterruptedException {
|
||||
public Double getUserBacklash() throws InterruptedException {
|
||||
try{
|
||||
return(this.userBacklash.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,12 +582,16 @@ public class OTFBean {
|
||||
* @param userBacklash
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setUserBacklash(Double userBacklash) throws CAException, InterruptedException {
|
||||
if(userBacklash==null){
|
||||
throw new IllegalArgumentException("User backlash must not be null");
|
||||
public void setUserBacklash(Double userBacklash) throws InterruptedException {
|
||||
try{
|
||||
if(userBacklash==null){
|
||||
throw new IllegalArgumentException("User backlash must not be null");
|
||||
}
|
||||
|
||||
this.userBacklash.setValue(userBacklash);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
this.userBacklash.setValue(userBacklash);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,8 +599,12 @@ public class OTFBean {
|
||||
* @return Name of NFS server
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getNfsServer() throws CAException, InterruptedException {
|
||||
public String getNfsServer() throws InterruptedException {
|
||||
try{
|
||||
return(this.nfsServer.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,8 +612,12 @@ public class OTFBean {
|
||||
* @param nfsServer
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setNfsServer(String nfsServer) throws CAException, InterruptedException {
|
||||
public void setNfsServer(String nfsServer) throws InterruptedException {
|
||||
try{
|
||||
this.nfsServer.setValue(nfsServer);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,8 +625,12 @@ public class OTFBean {
|
||||
* @return Name of NFS share
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getNfsShare() throws CAException, InterruptedException {
|
||||
return(this.nfsShare.getValue());
|
||||
public String getNfsShare() throws InterruptedException {
|
||||
try{
|
||||
return(this.nfsShare.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,8 +638,12 @@ public class OTFBean {
|
||||
* @param nfsShare
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setNfsShare(String nfsShare) throws CAException, InterruptedException {
|
||||
this.nfsShare.setValue(nfsShare);
|
||||
public void setNfsShare(String nfsShare) throws InterruptedException {
|
||||
try{
|
||||
this.nfsShare.setValue(nfsShare);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,8 +651,12 @@ public class OTFBean {
|
||||
* @return Name of data file name
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getFileName() throws CAException, InterruptedException {
|
||||
public String getFileName() throws InterruptedException {
|
||||
try{
|
||||
return(this.fileName.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,8 +664,12 @@ public class OTFBean {
|
||||
* @param filename
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setFileName(String filename) throws CAException, InterruptedException {
|
||||
this.fileName.setValue(filename);
|
||||
public void setFileName(String filename) throws InterruptedException {
|
||||
try{
|
||||
this.fileName.setValue(filename);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -567,8 +677,12 @@ public class OTFBean {
|
||||
* @return Get format for file name
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getFileNameFormat() throws CAException, InterruptedException {
|
||||
return(this.fileNameFormat.getValue());
|
||||
public String getFileNameFormat() throws InterruptedException {
|
||||
try{
|
||||
return(this.fileNameFormat.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,8 +690,12 @@ public class OTFBean {
|
||||
* @param fileNameFormat
|
||||
* @throws Exception
|
||||
*/
|
||||
public void setFileNameFormat(String fileNameFormat) throws CAException, InterruptedException {
|
||||
this.fileNameFormat.setValue(fileNameFormat);
|
||||
public void setFileNameFormat(String fileNameFormat) throws InterruptedException {
|
||||
try{
|
||||
this.fileNameFormat.setValue(fileNameFormat);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,16 +703,24 @@ public class OTFBean {
|
||||
* @return File counter
|
||||
* @throws CAException
|
||||
*/
|
||||
public int getFileCounter() throws CAException, InterruptedException {
|
||||
public int getFileCounter() throws InterruptedException {
|
||||
try{
|
||||
return(this.fileCount.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the IOC based file counter
|
||||
* @throws CAException
|
||||
*/
|
||||
public void resetFileCounter() throws CAException, InterruptedException {
|
||||
public void resetFileCounter() throws InterruptedException {
|
||||
try{
|
||||
this.resetFileCounter.setValue(1);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,8 +728,12 @@ public class OTFBean {
|
||||
* @return Append file flag
|
||||
* @throws CAException
|
||||
*/
|
||||
public boolean isAppendFile() throws CAException, InterruptedException {
|
||||
public boolean isAppendFile() throws InterruptedException {
|
||||
try{
|
||||
return(this.appendFile.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -611,8 +741,12 @@ public class OTFBean {
|
||||
* @param append
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setAppendFile(boolean append) throws CAException, InterruptedException {
|
||||
public void setAppendFile(boolean append) throws InterruptedException {
|
||||
try{
|
||||
this.appendFile.setValue(append);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -620,8 +754,12 @@ public class OTFBean {
|
||||
* @return File name generation flag
|
||||
* @throws CAException
|
||||
*/
|
||||
public boolean isFileNameGeneration() throws CAException, InterruptedException {
|
||||
public boolean isFileNameGeneration() throws InterruptedException {
|
||||
try{
|
||||
return(this.fileNameGeneration.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -629,8 +767,12 @@ public class OTFBean {
|
||||
* @param generation
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setFileNameGeneration(boolean generation) throws CAException, InterruptedException {
|
||||
this.fileNameGeneration.setValue(generation);
|
||||
public void setFileNameGeneration(boolean generation) throws InterruptedException {
|
||||
try{
|
||||
this.fileNameGeneration.setValue(generation);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -638,8 +780,12 @@ public class OTFBean {
|
||||
* @return ZigZag flag
|
||||
* @throws CAException
|
||||
*/
|
||||
public boolean isZigZag() throws CAException, InterruptedException {
|
||||
return(this.zigZag.getValue());
|
||||
public boolean isZigZag() throws InterruptedException {
|
||||
try{
|
||||
return(this.zigZag.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -647,23 +793,35 @@ public class OTFBean {
|
||||
* @param zigZag ZigZag mode on = true, ZigZag mode off = false
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setZigZag(boolean zigZag) throws CAException, InterruptedException {
|
||||
this.zigZag.setValue(zigZag);
|
||||
public void setZigZag(boolean zigZag) throws InterruptedException {
|
||||
try{
|
||||
this.zigZag.setValue(zigZag);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether encoder is used
|
||||
*/
|
||||
public boolean isUseEncoder() throws CAException, InterruptedException {
|
||||
return(this.useEncoder.getValue());
|
||||
public boolean isUseEncoder() throws InterruptedException {
|
||||
try{
|
||||
return(this.useEncoder.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag to use encoder
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setUseEncoder(boolean flag) throws CAException, InterruptedException {
|
||||
public void setUseEncoder(boolean flag) throws InterruptedException {
|
||||
try{
|
||||
this.useEncoder.setValue(flag);
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -671,14 +829,18 @@ public class OTFBean {
|
||||
* @return Names of the monitored channels
|
||||
* @throws CAException
|
||||
*/
|
||||
public String[] getMonitoredChannels() throws CAException, InterruptedException {
|
||||
String[] values = new String[this.monitoredChannels.size()];
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size();i++){
|
||||
values[i] = monitoredChannels.get(i).getValue();
|
||||
public String[] getMonitoredChannels() throws InterruptedException {
|
||||
try{
|
||||
String[] values = new String[this.monitoredChannels.size()];
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size();i++){
|
||||
values[i] = monitoredChannels.get(i).getValue();
|
||||
}
|
||||
|
||||
return(values);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return(values);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,19 +850,23 @@ public class OTFBean {
|
||||
* @param values Array of channel names to be monitored
|
||||
* @throws CAException
|
||||
*/
|
||||
public void setMonitoredChannels(String[] values) throws CAException, InterruptedException {
|
||||
public void setMonitoredChannels(String[] values) throws InterruptedException {
|
||||
|
||||
if(values.length>monitoredChannels.size()){
|
||||
throw new IllegalArgumentException("Only up to "+monitoredChannels.size()+" monitored channels are supported by OTF");
|
||||
}
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size(); i++){
|
||||
if(values != null && i<values.length){
|
||||
this.monitoredChannels.get(i).setValue(values[i]);
|
||||
try{
|
||||
if(values.length>monitoredChannels.size()){
|
||||
throw new IllegalArgumentException("Only up to "+monitoredChannels.size()+" monitored channels are supported by OTF");
|
||||
}
|
||||
else{
|
||||
this.monitoredChannels.get(i).setValue("");
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size(); i++){
|
||||
if(values != null && i<values.length){
|
||||
this.monitoredChannels.get(i).setValue(values[i]);
|
||||
}
|
||||
else{
|
||||
this.monitoredChannels.get(i).setValue("");
|
||||
}
|
||||
}
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,8 +875,12 @@ public class OTFBean {
|
||||
* @return Running flag
|
||||
* @throws CAException
|
||||
*/
|
||||
public boolean isRunning() throws CAException, InterruptedException {
|
||||
return(running.getValue());
|
||||
public boolean isRunning() throws InterruptedException {
|
||||
try{
|
||||
return(running.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -718,8 +888,12 @@ public class OTFBean {
|
||||
* @return Status of the scan
|
||||
* @throws CAException
|
||||
*/
|
||||
public Status getStatus() throws CAException, InterruptedException {
|
||||
return(Status.values()[this.status.getValue()]);
|
||||
public Status getStatus() throws InterruptedException {
|
||||
try{
|
||||
return(Status.values()[this.status.getValue()]);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -727,8 +901,12 @@ public class OTFBean {
|
||||
* @return Message from OTF C logic
|
||||
* @throws CAException
|
||||
*/
|
||||
public String getMessage() throws CAException, InterruptedException {
|
||||
return(message.getValue());
|
||||
public String getMessage() throws InterruptedException {
|
||||
try{
|
||||
return(message.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -736,8 +914,12 @@ public class OTFBean {
|
||||
* @return Flag whether motor is ok
|
||||
* @throws CAException
|
||||
*/
|
||||
public boolean isMotorOk() throws CAException, InterruptedException {
|
||||
return(motorOk.getValue());
|
||||
public boolean isMotorOk() throws InterruptedException {
|
||||
try{
|
||||
return(motorOk.getValue());
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -746,8 +928,12 @@ public class OTFBean {
|
||||
*
|
||||
* @throws CAException If motor ok flag does not switch to ok within the specified timeout
|
||||
*/
|
||||
public void waitUntilMotorOk(long timeout) throws CAException, InterruptedException {
|
||||
public void waitUntilMotorOk(long timeout) throws InterruptedException {
|
||||
try{
|
||||
motorOk.waitForValue(true, timeout);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -756,15 +942,23 @@ public class OTFBean {
|
||||
*
|
||||
* @throws CAException If motor ok flag does not switch to ok within the specified timeout
|
||||
*/
|
||||
public void waitUntilMotorNotOk(long timeout) throws CAException, InterruptedException {
|
||||
public void waitUntilMotorNotOk(long timeout) throws InterruptedException {
|
||||
try{
|
||||
motorOk.waitForValue(false, timeout);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void waitUntilEncoderOk(long timeout) throws CAException, InterruptedException {
|
||||
public void waitUntilEncoderOk(long timeout) throws InterruptedException {
|
||||
try{
|
||||
if(!useEncoder.getValue()){
|
||||
return;
|
||||
}
|
||||
encoderOk.waitForValue(true, timeout);
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,6 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
//import jcifs.smb.SmbException;
|
||||
//import jcifs.smb.SmbFile;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
@@ -47,7 +43,6 @@ import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFReadbackSensor;
|
||||
import ch.psi.fda.core.sensors.OTFScalerChannelSensor;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
|
||||
/**
|
||||
* ActionLoop that is implementing the OTF Scan logic.
|
||||
@@ -151,17 +146,9 @@ public class OTFLoop implements ActionLoop {
|
||||
* @param smbShare SMB share to get the data written by the OTF C Logic
|
||||
* @param zigZag Operate loop in zig zag mode
|
||||
*/
|
||||
public OTFLoop(String channelPrefix, String server, String share, String smbShare, boolean zigZag){
|
||||
public OTFLoop(OTFBean obean, String server, String share, String smbShare, boolean zigZag){
|
||||
|
||||
// Initialize connection to the OTF records
|
||||
try {
|
||||
this.obean = new OTFBean();
|
||||
ChannelBeanFactory.getFactory().createChannelBeans(obean, channelPrefix);
|
||||
} catch (CAException e) {
|
||||
throw new IllegalArgumentException("Unable to connect to the OTF channels",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to connect to the OTF channels",e);
|
||||
}
|
||||
this.obean = obean;
|
||||
|
||||
// Store loop configuration
|
||||
this.server = server;
|
||||
@@ -311,9 +298,7 @@ public class OTFLoop implements ActionLoop {
|
||||
// Set monitored channels
|
||||
obean.setMonitoredChannels(monitoredChannels.toArray(new String[monitoredChannels.size()]));
|
||||
}
|
||||
catch(CAException e){
|
||||
throw new RuntimeException("Unable to set OTF configuration parameters",e);
|
||||
} catch (InterruptedException e) {
|
||||
catch(Exception e){
|
||||
throw new RuntimeException("Unable to set OTF configuration parameters",e);
|
||||
}
|
||||
|
||||
@@ -342,41 +327,19 @@ public class OTFLoop implements ActionLoop {
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Close all connections used by the OTFBean
|
||||
try {
|
||||
ChannelBeanFactory.getFactory().destroyChannelBeans(obean);
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channels",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to destroy channels",e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#getPreActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPreActions() {
|
||||
return preActions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#getPostActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPostActions() {
|
||||
return postActions;
|
||||
@@ -479,43 +442,19 @@ public class OTFLoop implements ActionLoop {
|
||||
}
|
||||
|
||||
|
||||
// Getter functions for variable parts
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the sensors
|
||||
*/
|
||||
public List<Sensor> getSensors() {
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actor
|
||||
*/
|
||||
public OTFActuator getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actor the actor to set
|
||||
*/
|
||||
public void setActor(OTFActuator actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataGroup
|
||||
*/
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataGroup the dataGroup to set
|
||||
*/
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package ch.psi.fda.core.loops.cr;
|
||||
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
@@ -37,120 +37,120 @@ public class CrlogicChannelsTemplate {
|
||||
* Ticks per second - IOC setting
|
||||
* ATTENTION - This field must only be set bu the IOC - ATTENTION
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =":TPS")
|
||||
private ChannelBean<Integer> ticksPerSecond;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}:TPS")
|
||||
private Channel<Integer> ticksPerSecond;
|
||||
|
||||
/**
|
||||
* Status of the OTFSCAN IOC logic
|
||||
*/
|
||||
@CaChannel(type=String.class, name =":STATUS")
|
||||
private ChannelBean<String> status;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:STATUS")
|
||||
private Channel<String> status;
|
||||
|
||||
/**
|
||||
* Message from the OTFSCAN IOC logic
|
||||
*/
|
||||
@CaChannel(type=String.class, name =":MSG")
|
||||
private ChannelBean<String> message;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:MSG")
|
||||
private Channel<String> message;
|
||||
|
||||
/**
|
||||
* IOC ticks between data acquisition interrupts
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =":TBINT")
|
||||
private ChannelBean<Integer> ticksBetweenInterrupts;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}:TBINT")
|
||||
private Channel<Integer> ticksBetweenInterrupts;
|
||||
|
||||
/**
|
||||
* Name or ip address of the NFS server to save the data to
|
||||
* (depending on the IOC setup)
|
||||
*/
|
||||
@CaChannel(type=String.class, name =":NFSSE")
|
||||
private ChannelBean<String> nfsServer;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:NFSSE")
|
||||
private Channel<String> nfsServer;
|
||||
|
||||
/**
|
||||
* Name of the NFS share on the NFS server
|
||||
*/
|
||||
@CaChannel(type=String.class, name =":NFSSH")
|
||||
private ChannelBean<String> nfsShare;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:NFSSH")
|
||||
private Channel<String> nfsShare;
|
||||
|
||||
/**
|
||||
* Name of the data file
|
||||
*/
|
||||
@CaChannel(type=String.class, name =":DFNAM")
|
||||
private ChannelBean<String> dataFile;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:DFNAM")
|
||||
private Channel<String> dataFile;
|
||||
|
||||
/**
|
||||
* Flag to identify whether the data file should be appended
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name =":FAPPE")
|
||||
private ChannelBean<Boolean> appendFile;
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}:FAPPE")
|
||||
private Channel<Boolean> appendFile;
|
||||
|
||||
|
||||
/**
|
||||
* Readout resources
|
||||
*/
|
||||
@CaChannel(type=String[].class, name =":RRES")
|
||||
private ChannelBean<String[]> readoutResources;
|
||||
@CaChannel(type=String[].class, name ="${PREFIX}:RRES")
|
||||
private Channel<String[]> readoutResources;
|
||||
|
||||
|
||||
/**
|
||||
* @return the ticksPerSecond
|
||||
*/
|
||||
public ChannelBean<Integer> getTicksPerSecond() {
|
||||
public Channel<Integer> getTicksPerSecond() {
|
||||
return ticksPerSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the status
|
||||
*/
|
||||
public ChannelBean<String> getStatus() {
|
||||
public Channel<String> getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public ChannelBean<String> getMessage() {
|
||||
public Channel<String> getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ticksBetweenInterrupts
|
||||
*/
|
||||
public ChannelBean<Integer> getTicksBetweenInterrupts() {
|
||||
public Channel<Integer> getTicksBetweenInterrupts() {
|
||||
return ticksBetweenInterrupts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nfsServer
|
||||
*/
|
||||
public ChannelBean<String> getNfsServer() {
|
||||
public Channel<String> getNfsServer() {
|
||||
return nfsServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nfsShare
|
||||
*/
|
||||
public ChannelBean<String> getNfsShare() {
|
||||
public Channel<String> getNfsShare() {
|
||||
return nfsShare;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataFile
|
||||
*/
|
||||
public ChannelBean<String> getDataFile() {
|
||||
public Channel<String> getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the appendFile
|
||||
*/
|
||||
public ChannelBean<Boolean> getAppendFile() {
|
||||
public Channel<Boolean> getAppendFile() {
|
||||
return appendFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readoutResources
|
||||
*/
|
||||
public ChannelBean<String[]> getReadoutResources() {
|
||||
public Channel<String[]> getReadoutResources() {
|
||||
return readoutResources;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jcifs.smb.SmbFile;
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
@@ -46,7 +48,8 @@ import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFScalerChannelSensor;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
@@ -150,8 +153,11 @@ public class CrlogicLoop implements ActionLoop {
|
||||
private boolean abortForce = false;
|
||||
private Thread executionThread = null;
|
||||
|
||||
private final ChannelService cservice;
|
||||
|
||||
public CrlogicLoop(String prefix, String server, String share, String smbShare, boolean zigZag){
|
||||
|
||||
public CrlogicLoop(ChannelService cservice, String prefix, String server, String share, String smbShare, boolean zigZag){
|
||||
this.cservice = cservice;
|
||||
this.prefix = prefix;
|
||||
this.server = server;
|
||||
this.share = share;
|
||||
@@ -462,7 +468,7 @@ public class CrlogicLoop implements ActionLoop {
|
||||
|
||||
// Move to start
|
||||
logger.info("Move motor to start ["+realStart+"]");
|
||||
motortemplate.getSetValue().setValue(realStart, timeout); // Will block until move is done
|
||||
motortemplate.getSetValue().setValueAsync(realStart).get(timeout, TimeUnit.MILLISECONDS); // Will block until move is done
|
||||
|
||||
|
||||
// Set motor paramters
|
||||
@@ -500,7 +506,7 @@ public class CrlogicLoop implements ActionLoop {
|
||||
try{
|
||||
template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.ACTIVE.toString(), startStopTimeout);
|
||||
}
|
||||
catch(CAException e){
|
||||
catch(ChannelException | ExecutionException | TimeoutException e){
|
||||
logger.info( "Failed to start CRLOGIC. Logic in status: "+template.getStatus().getValue() );
|
||||
if(template.getStatus().getValue().equals(CrlogicChannelsTemplate.Status.FAULT.toString())){
|
||||
logger.info("Error message: "+template.getMessage().getValue());
|
||||
@@ -515,7 +521,7 @@ public class CrlogicLoop implements ActionLoop {
|
||||
// Move motor(s) to end / wait until motor is stopped
|
||||
logger.info("Move motor to end ["+realEnd+"]");
|
||||
try{
|
||||
motortemplate.getSetValue().setValue(realEnd, timeout); // Will block until move is done
|
||||
motortemplate.getSetValue().setValueAsync(realEnd).get(timeout, TimeUnit.MILLISECONDS); // Will block until move is done
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
if(abort & (!abortForce)){
|
||||
@@ -537,7 +543,7 @@ public class CrlogicLoop implements ActionLoop {
|
||||
try{
|
||||
template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.INACTIVE.toString(), startStopTimeout);
|
||||
}
|
||||
catch(CAException e){
|
||||
catch(ChannelException | ExecutionException | TimeoutException e){
|
||||
logger.info( "Failed to stop CRLOGIC. Logic in status: "+template.getStatus().getValue() );
|
||||
// TODO Improve error handling
|
||||
throw new RuntimeException("Failed to stop CRLOGIC. Logic in status: "+template.getStatus().getValue(), e);
|
||||
@@ -562,22 +568,6 @@ public class CrlogicLoop implements ActionLoop {
|
||||
// Request read of data file
|
||||
readQueue.put(tmpFileName);
|
||||
|
||||
// // Read data
|
||||
// Thread t = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// collectData(smbShare, tmpFileName);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// t.start();
|
||||
|
||||
if(zigZag){
|
||||
actuator.reverse();
|
||||
}
|
||||
@@ -586,23 +576,16 @@ public class CrlogicLoop implements ActionLoop {
|
||||
executionThread = null;
|
||||
}
|
||||
}
|
||||
catch(CAException e){
|
||||
catch(ChannelException | ExecutionException | TimeoutException e){
|
||||
throw new RuntimeException("Unable to execute crloop", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort logic
|
||||
* @param force
|
||||
*/
|
||||
public synchronized void abort(boolean force){
|
||||
abort = true;
|
||||
abortForce = force;
|
||||
@@ -613,9 +596,6 @@ public class CrlogicLoop implements ActionLoop {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
stopReadoutThread = true;
|
||||
@@ -624,8 +604,8 @@ public class CrlogicLoop implements ActionLoop {
|
||||
|
||||
try {
|
||||
|
||||
ChannelBeanFactory.getFactory().destroyChannelBeans(template);
|
||||
ChannelBeanFactory.getFactory().destroyChannelBeans(motortemplate);
|
||||
cservice.destroyAnnotatedChannels(template);
|
||||
cservice.destroyAnnotatedChannels(motortemplate);
|
||||
template = null;
|
||||
motortemplate = null;
|
||||
|
||||
@@ -674,11 +654,15 @@ public class CrlogicLoop implements ActionLoop {
|
||||
// Connect crlogic channels
|
||||
template = new CrlogicChannelsTemplate();
|
||||
logger.info("Connect channels");
|
||||
ChannelBeanFactory.getFactory().createChannelBeans(template, prefix);
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("PREFIX", prefix);
|
||||
cservice.createAnnotatedChannels(template, map);
|
||||
|
||||
// Connect motor channels
|
||||
motortemplate = new MotorChannelsTemplate();
|
||||
ChannelBeanFactory.getFactory().createChannelBeans(motortemplate, actuator.getName());
|
||||
map = new HashMap<>();
|
||||
map.put("PREFIX", actuator.getName());
|
||||
cservice.createAnnotatedChannels(motortemplate, map);
|
||||
|
||||
useReadback = motortemplate.getUseReadback().getValue();
|
||||
useEncoder = motortemplate.getUseEncoder().getValue();
|
||||
@@ -720,7 +704,9 @@ public class CrlogicLoop implements ActionLoop {
|
||||
// Fill readback encoder settings
|
||||
// Connect to encoder
|
||||
EncoderChannelsTemplate encodertemplate = new EncoderChannelsTemplate();
|
||||
ChannelBeanFactory.getFactory().createChannelBeans(encodertemplate, readback);
|
||||
map = new HashMap<>();
|
||||
map.put("PREFIX", readback);
|
||||
cservice.createAnnotatedChannels(encodertemplate, map);
|
||||
|
||||
// Read encoder settings
|
||||
if(encodertemplate.getDirection().getValue()==EncoderChannelsTemplate.Direction.Positive.ordinal()){
|
||||
@@ -733,7 +719,7 @@ public class CrlogicLoop implements ActionLoop {
|
||||
crlogicDataFilter.setEncoderResolution(encodertemplate.getResolution().getValue());
|
||||
|
||||
// Disconnect from encoder
|
||||
ChannelBeanFactory.getFactory().destroyChannelBeans(encodertemplate);
|
||||
cservice.destroyAnnotatedChannels(encodertemplate);
|
||||
|
||||
}
|
||||
else if (useEncoder && (!useReadback)){
|
||||
|
||||
@@ -19,53 +19,38 @@
|
||||
|
||||
package ch.psi.fda.core.loops.cr;
|
||||
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class EncoderChannelsTemplate {
|
||||
|
||||
/**
|
||||
* Resolution - $(P)$(E)_SCL
|
||||
*/
|
||||
@CaChannel(type=Double.class, name="_SCL")
|
||||
private ChannelBean<Double> resolution;
|
||||
@CaChannel(type=Double.class, name="${PREFIX}_SCL")
|
||||
private Channel<Double> resolution;
|
||||
|
||||
/**
|
||||
* Offset - $(P)$(E)_OFF
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="_OFF")
|
||||
private ChannelBean<Double> offset;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}_OFF")
|
||||
private Channel<Double> offset;
|
||||
|
||||
/**
|
||||
* Direction - $(P)$(E)_DIR
|
||||
*/
|
||||
public enum Direction {Negative, Positive};
|
||||
@CaChannel(type=Integer.class, name ="_DIR")
|
||||
private ChannelBean<Integer> direction;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}_DIR")
|
||||
private Channel<Integer> direction;
|
||||
|
||||
|
||||
/**
|
||||
* @return the resolution
|
||||
*/
|
||||
public ChannelBean<Double> getResolution() {
|
||||
public Channel<Double> getResolution() {
|
||||
return resolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offset
|
||||
*/
|
||||
public ChannelBean<Double> getOffset() {
|
||||
public Channel<Double> getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public ChannelBean<Integer> getDirection() {
|
||||
public Channel<Integer> getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package ch.psi.fda.core.loops.cr;
|
||||
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
@@ -38,92 +38,92 @@ public class MotorChannelsTemplate {
|
||||
/**
|
||||
* .HLM High limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".HLM")
|
||||
private ChannelBean<Double> highLimit;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.HLM")
|
||||
private Channel<Double> highLimit;
|
||||
|
||||
/**
|
||||
* .LLM Low limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".LLM")
|
||||
private ChannelBean<Double> lowLimit;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.LLM")
|
||||
private Channel<Double> lowLimit;
|
||||
|
||||
/**
|
||||
* .RBV Readback value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".RBV", monitor=true)
|
||||
private ChannelBean<Double> readbackValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RBV", monitor=true)
|
||||
private Channel<Double> readbackValue;
|
||||
|
||||
/**
|
||||
* .VAL Set value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".VAL", monitor=true)
|
||||
private ChannelBean<Double> setValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VAL", monitor=true)
|
||||
private Channel<Double> setValue;
|
||||
|
||||
/**
|
||||
* .RLV Relative move value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".RLV")
|
||||
private ChannelBean<Double> relativeMoveValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RLV")
|
||||
private Channel<Double> relativeMoveValue;
|
||||
|
||||
/**
|
||||
* .TWV Teak value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".TWV")
|
||||
private ChannelBean<Double> tweakValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.TWV")
|
||||
private Channel<Double> tweakValue;
|
||||
|
||||
/**
|
||||
* .TWR Tweak reverse - move left - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".TWR")
|
||||
private ChannelBean<Integer> tweakReverse;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.TWR")
|
||||
private Channel<Integer> tweakReverse;
|
||||
|
||||
/**
|
||||
* .TWF Tweak forward - move right - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".TWF")
|
||||
private ChannelBean<Integer> tweakForward;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.TWF")
|
||||
private Channel<Integer> tweakForward;
|
||||
|
||||
/**
|
||||
* .JOGR Jog reverse - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".JOGR")
|
||||
private ChannelBean<Integer> jogReverse;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.JOGR")
|
||||
private Channel<Integer> jogReverse;
|
||||
|
||||
/**
|
||||
* .JOGF Jog forward - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".JOGF")
|
||||
private ChannelBean<Integer> jogForward;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.JOGF")
|
||||
private Channel<Integer> jogForward;
|
||||
|
||||
/**
|
||||
* .HOMR Home reverse - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".HOMR")
|
||||
private ChannelBean<Integer> homeReverse;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.HOMR")
|
||||
private Channel<Integer> homeReverse;
|
||||
|
||||
/**
|
||||
* .HOMF Home forward - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".HOMF")
|
||||
private ChannelBean<Integer> homeForward;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.HOMF")
|
||||
private Channel<Integer> homeForward;
|
||||
|
||||
/**
|
||||
* .EGU Engineering unit - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name =".EGU")
|
||||
private ChannelBean<String> engineeringUnit;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.EGU")
|
||||
private Channel<String> engineeringUnit;
|
||||
|
||||
/**
|
||||
* .DTYP Type - String (e.g. "OMS MAXv") see enum Type
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".DTYP")
|
||||
private ChannelBean<Integer> type;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.DTYP")
|
||||
private Channel<Integer> type;
|
||||
|
||||
/**
|
||||
* .DESC Description - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name =".DESC")
|
||||
private ChannelBean<String> description;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.DESC")
|
||||
private Channel<String> description;
|
||||
|
||||
|
||||
/**
|
||||
@@ -133,45 +133,45 @@ public class MotorChannelsTemplate {
|
||||
/**
|
||||
* .DHLM Dial high limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".DHLM")
|
||||
private ChannelBean<Double> dialHighLimit;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DHLM")
|
||||
private Channel<Double> dialHighLimit;
|
||||
|
||||
/**
|
||||
* .DLLM Dial low limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".DLLM")
|
||||
private ChannelBean<Double> dialLowLimit;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DLLM")
|
||||
private Channel<Double> dialLowLimit;
|
||||
|
||||
/**
|
||||
* .DRBV Dial readback value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".DRBV", monitor=true)
|
||||
private ChannelBean<Double> dialReadbackValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DRBV", monitor=true)
|
||||
private Channel<Double> dialReadbackValue;
|
||||
|
||||
/**
|
||||
* .DVAL Dial set value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".DVAL", monitor=true)
|
||||
private ChannelBean<Double> dialSetValue;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DVAL", monitor=true)
|
||||
private Channel<Double> dialSetValue;
|
||||
|
||||
/**
|
||||
* .RVAL Raw value - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".RVAL", monitor=true)
|
||||
private ChannelBean<Integer> rawValue;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RVAL", monitor=true)
|
||||
private Channel<Integer> rawValue;
|
||||
|
||||
/**
|
||||
* .RRBV Raw readback value - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".RRBV", monitor=true)
|
||||
private ChannelBean<Integer> rawReadbackValue;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RRBV", monitor=true)
|
||||
private Channel<Integer> rawReadbackValue;
|
||||
|
||||
/**
|
||||
* .SPMG Stop/Pause/Move/Go - (0:"Stop", 1:"Pause", 2:"Move", 3:"Go") - 3
|
||||
*/
|
||||
public enum Commands { Stop, Pause, Move, Go };
|
||||
@CaChannel(type=Integer.class, name =".SPMG")
|
||||
private ChannelBean<Integer> command;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.SPMG")
|
||||
private Channel<Integer> command;
|
||||
|
||||
|
||||
/**
|
||||
@@ -182,28 +182,28 @@ public class MotorChannelsTemplate {
|
||||
* .SET Set/Use Switch - (0:"Use", 1:"Set") - 0
|
||||
*/
|
||||
public enum Calibration {Use, Set};
|
||||
@CaChannel(type=Integer.class, name =".SET")
|
||||
private ChannelBean<Integer> calibration;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.SET")
|
||||
private Channel<Integer> calibration;
|
||||
|
||||
/**
|
||||
* .OFF User offset (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".OFF")
|
||||
private ChannelBean<Double> offset;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.OFF")
|
||||
private Channel<Double> offset;
|
||||
|
||||
/**
|
||||
* .FOFF Offset-Freeze Switch - (0:"Variable", 1:"Frozen") - 1
|
||||
*/
|
||||
public enum OffsetMode {Variable, Frozen};
|
||||
@CaChannel(type=Integer.class, name =".FOFF")
|
||||
private ChannelBean<Integer> offsetMode;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.FOFF")
|
||||
private Channel<Integer> offsetMode;
|
||||
|
||||
/**
|
||||
* .DIR User direction - (0:"Pos", 1:"Neg")
|
||||
*/
|
||||
public enum Direction {Positive, Negative};
|
||||
@CaChannel(type=Integer.class, name =".DIR")
|
||||
private ChannelBean<Integer> direction;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.DIR")
|
||||
private Channel<Integer> direction;
|
||||
|
||||
|
||||
/**
|
||||
@@ -213,44 +213,44 @@ public class MotorChannelsTemplate {
|
||||
/**
|
||||
* .VELO Velocity (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".VELO")
|
||||
private ChannelBean<Double> velocity;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VELO")
|
||||
private Channel<Double> velocity;
|
||||
|
||||
/**
|
||||
* .BVEL Backlash velocity (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".BVEL")
|
||||
private ChannelBean<Double> backlashVelocity;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BVEL")
|
||||
private Channel<Double> backlashVelocity;
|
||||
|
||||
/**
|
||||
* .VBAS Base speed (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".VBAS")
|
||||
private ChannelBean<Double> baseSpeed;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VBAS")
|
||||
private Channel<Double> baseSpeed;
|
||||
|
||||
/**
|
||||
* .ACCL Acceleration time / seconds to velocity - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".ACCL")
|
||||
private ChannelBean<Double> accelerationTime;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.ACCL")
|
||||
private Channel<Double> accelerationTime;
|
||||
|
||||
/**
|
||||
* .BACC Backlash acceleration time / seconds to velocity - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".BACC")
|
||||
private ChannelBean<Double> backlashAccelerationTime;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BACC")
|
||||
private Channel<Double> backlashAccelerationTime;
|
||||
|
||||
/**
|
||||
* .BDST Backlash distance (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".BDST")
|
||||
private ChannelBean<Double> backlashDistance;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BDST")
|
||||
private Channel<Double> backlashDistance;
|
||||
|
||||
/**
|
||||
* .FRAC Move fraction - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".FRAC")
|
||||
private ChannelBean<Double> moveFracion;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.FRAC")
|
||||
private Channel<Double> moveFracion;
|
||||
|
||||
|
||||
/**
|
||||
@@ -260,69 +260,69 @@ public class MotorChannelsTemplate {
|
||||
/**
|
||||
* .MRES Motor resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".MRES")
|
||||
private ChannelBean<Double> motorResolution;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.MRES")
|
||||
private Channel<Double> motorResolution;
|
||||
|
||||
/**
|
||||
* .ERES Encoder resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".ERES")
|
||||
private ChannelBean<Double> encoderResolution;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.ERES")
|
||||
private Channel<Double> encoderResolution;
|
||||
|
||||
/**
|
||||
* .RRES Readback resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".RRES")
|
||||
private ChannelBean<Double> readbackResolution;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RRES")
|
||||
private Channel<Double> readbackResolution;
|
||||
|
||||
/**
|
||||
* .RDBD Retry deadband (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".RDBD")
|
||||
private ChannelBean<Double> retryDeadband;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RDBD")
|
||||
private Channel<Double> retryDeadband;
|
||||
|
||||
/**
|
||||
* .RTRY Max retry count - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".RTRY")
|
||||
private ChannelBean<Integer> maxRetryCount;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RTRY")
|
||||
private Channel<Integer> maxRetryCount;
|
||||
|
||||
/**
|
||||
* .RCNT Retry count - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".RCNT", monitor=true)
|
||||
private ChannelBean<Integer> retryCount;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RCNT", monitor=true)
|
||||
private Channel<Integer> retryCount;
|
||||
|
||||
/**
|
||||
* .UEIP Use encoder (if present) - (0:"No", 1:"Yes")
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name =".UEIP")
|
||||
private ChannelBean<Boolean> useEncoder;
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.UEIP")
|
||||
private Channel<Boolean> useEncoder;
|
||||
|
||||
/**
|
||||
* .URIP Use readback link (if present) - (0:"No", 1:"Yes")
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name =".URIP")
|
||||
private ChannelBean<Boolean> useReadback;
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.URIP")
|
||||
private Channel<Boolean> useReadback;
|
||||
|
||||
/**
|
||||
* .DLY Readback delay (s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name =".DLY")
|
||||
private ChannelBean<Double> readbackDelay;
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DLY")
|
||||
private Channel<Double> readbackDelay;
|
||||
|
||||
/**
|
||||
* .RDBL Readback link - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name =".RDBL")
|
||||
private ChannelBean<String> readbackLink;
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.RDBL")
|
||||
private Channel<String> readbackLink;
|
||||
|
||||
/**
|
||||
* .OMSL Output mode select - (0:"supervisory", 1:"closed_loop")
|
||||
*/
|
||||
public enum OutputMode {Supervisory, Closed_Loop};
|
||||
@CaChannel(type=Integer.class, name =".OMSL")
|
||||
private ChannelBean<Integer> outputMode;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.OMSL")
|
||||
private Channel<Integer> outputMode;
|
||||
|
||||
/**
|
||||
* ## Status ##
|
||||
@@ -331,321 +331,321 @@ public class MotorChannelsTemplate {
|
||||
/**
|
||||
* .DMOV Done move - int
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name =".DMOV", monitor=true)
|
||||
private ChannelBean<Boolean> moveDone;
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.DMOV", monitor=true)
|
||||
private Channel<Boolean> moveDone;
|
||||
|
||||
/**
|
||||
* @return the highLimit
|
||||
*/
|
||||
public ChannelBean<Double> getHighLimit() {
|
||||
public Channel<Double> getHighLimit() {
|
||||
return highLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lowLimit
|
||||
*/
|
||||
public ChannelBean<Double> getLowLimit() {
|
||||
public Channel<Double> getLowLimit() {
|
||||
return lowLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackValue
|
||||
*/
|
||||
public ChannelBean<Double> getReadbackValue() {
|
||||
public Channel<Double> getReadbackValue() {
|
||||
return readbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the setValue
|
||||
*/
|
||||
public ChannelBean<Double> getSetValue() {
|
||||
public Channel<Double> getSetValue() {
|
||||
return setValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relativeMoveValue
|
||||
*/
|
||||
public ChannelBean<Double> getRelativeMoveValue() {
|
||||
public Channel<Double> getRelativeMoveValue() {
|
||||
return relativeMoveValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakValue
|
||||
*/
|
||||
public ChannelBean<Double> getTweakValue() {
|
||||
public Channel<Double> getTweakValue() {
|
||||
return tweakValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakReverse
|
||||
*/
|
||||
public ChannelBean<Integer> getTweakReverse() {
|
||||
public Channel<Integer> getTweakReverse() {
|
||||
return tweakReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakForward
|
||||
*/
|
||||
public ChannelBean<Integer> getTweakForward() {
|
||||
public Channel<Integer> getTweakForward() {
|
||||
return tweakForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jogReverse
|
||||
*/
|
||||
public ChannelBean<Integer> getJogReverse() {
|
||||
public Channel<Integer> getJogReverse() {
|
||||
return jogReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jogForward
|
||||
*/
|
||||
public ChannelBean<Integer> getJogForward() {
|
||||
public Channel<Integer> getJogForward() {
|
||||
return jogForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the homeReverse
|
||||
*/
|
||||
public ChannelBean<Integer> getHomeReverse() {
|
||||
public Channel<Integer> getHomeReverse() {
|
||||
return homeReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the homeForward
|
||||
*/
|
||||
public ChannelBean<Integer> getHomeForward() {
|
||||
public Channel<Integer> getHomeForward() {
|
||||
return homeForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the engineeringUnit
|
||||
*/
|
||||
public ChannelBean<String> getEngineeringUnit() {
|
||||
public Channel<String> getEngineeringUnit() {
|
||||
return engineeringUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public ChannelBean<Integer> getType() {
|
||||
public Channel<Integer> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public ChannelBean<String> getDescription() {
|
||||
public Channel<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialHighLimit
|
||||
*/
|
||||
public ChannelBean<Double> getDialHighLimit() {
|
||||
public Channel<Double> getDialHighLimit() {
|
||||
return dialHighLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialLowLimit
|
||||
*/
|
||||
public ChannelBean<Double> getDialLowLimit() {
|
||||
public Channel<Double> getDialLowLimit() {
|
||||
return dialLowLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialReadbackValue
|
||||
*/
|
||||
public ChannelBean<Double> getDialReadbackValue() {
|
||||
public Channel<Double> getDialReadbackValue() {
|
||||
return dialReadbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialSetValue
|
||||
*/
|
||||
public ChannelBean<Double> getDialSetValue() {
|
||||
public Channel<Double> getDialSetValue() {
|
||||
return dialSetValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rawValue
|
||||
*/
|
||||
public ChannelBean<Integer> getRawValue() {
|
||||
public Channel<Integer> getRawValue() {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rawReadbackValue
|
||||
*/
|
||||
public ChannelBean<Integer> getRawReadbackValue() {
|
||||
public Channel<Integer> getRawReadbackValue() {
|
||||
return rawReadbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the command
|
||||
*/
|
||||
public ChannelBean<Integer> getCommand() {
|
||||
public Channel<Integer> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the calibration
|
||||
*/
|
||||
public ChannelBean<Integer> getCalibration() {
|
||||
public Channel<Integer> getCalibration() {
|
||||
return calibration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userOffset
|
||||
*/
|
||||
public ChannelBean<Double> getOffset() {
|
||||
public Channel<Double> getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offsetMode
|
||||
*/
|
||||
public ChannelBean<Integer> getOffsetMode() {
|
||||
public Channel<Integer> getOffsetMode() {
|
||||
return offsetMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public ChannelBean<Integer> getDirection() {
|
||||
public Channel<Integer> getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the velocity
|
||||
*/
|
||||
public ChannelBean<Double> getVelocity() {
|
||||
public Channel<Double> getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashVelocity
|
||||
*/
|
||||
public ChannelBean<Double> getBacklashVelocity() {
|
||||
public Channel<Double> getBacklashVelocity() {
|
||||
return backlashVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the baseSpeed
|
||||
*/
|
||||
public ChannelBean<Double> getBaseSpeed() {
|
||||
public Channel<Double> getBaseSpeed() {
|
||||
return baseSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accelerationTime
|
||||
*/
|
||||
public ChannelBean<Double> getAccelerationTime() {
|
||||
public Channel<Double> getAccelerationTime() {
|
||||
return accelerationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashAccelerationTime
|
||||
*/
|
||||
public ChannelBean<Double> getBacklashAccelerationTime() {
|
||||
public Channel<Double> getBacklashAccelerationTime() {
|
||||
return backlashAccelerationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashDistance
|
||||
*/
|
||||
public ChannelBean<Double> getBacklashDistance() {
|
||||
public Channel<Double> getBacklashDistance() {
|
||||
return backlashDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the moveFracion
|
||||
*/
|
||||
public ChannelBean<Double> getMoveFracion() {
|
||||
public Channel<Double> getMoveFracion() {
|
||||
return moveFracion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorResolution
|
||||
*/
|
||||
public ChannelBean<Double> getMotorResolution() {
|
||||
public Channel<Double> getMotorResolution() {
|
||||
return motorResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoderResolution
|
||||
*/
|
||||
public ChannelBean<Double> getEncoderResolution() {
|
||||
public Channel<Double> getEncoderResolution() {
|
||||
return encoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackResolution
|
||||
*/
|
||||
public ChannelBean<Double> getReadbackResolution() {
|
||||
public Channel<Double> getReadbackResolution() {
|
||||
return readbackResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the retryDeadband
|
||||
*/
|
||||
public ChannelBean<Double> getRetryDeadband() {
|
||||
public Channel<Double> getRetryDeadband() {
|
||||
return retryDeadband;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxRetryCount
|
||||
*/
|
||||
public ChannelBean<Integer> getMaxRetryCount() {
|
||||
public Channel<Integer> getMaxRetryCount() {
|
||||
return maxRetryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the retryCount
|
||||
*/
|
||||
public ChannelBean<Integer> getRetryCount() {
|
||||
public Channel<Integer> getRetryCount() {
|
||||
return retryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the useEncoder
|
||||
*/
|
||||
public ChannelBean<Boolean> getUseEncoder() {
|
||||
public Channel<Boolean> getUseEncoder() {
|
||||
return useEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the useReadback
|
||||
*/
|
||||
public ChannelBean<Boolean> getUseReadback() {
|
||||
public Channel<Boolean> getUseReadback() {
|
||||
return useReadback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackDelay
|
||||
*/
|
||||
public ChannelBean<Double> getReadbackDelay() {
|
||||
public Channel<Double> getReadbackDelay() {
|
||||
return readbackDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackLink
|
||||
*/
|
||||
public ChannelBean<String> getReadbackLink() {
|
||||
public Channel<String> getReadbackLink() {
|
||||
return readbackLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the outputMode
|
||||
*/
|
||||
public ChannelBean<Integer> getOutputMode() {
|
||||
public Channel<Integer> getOutputMode() {
|
||||
return outputMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the moveDone
|
||||
*/
|
||||
public ChannelBean<Boolean> getMoveDone() {
|
||||
public Channel<Boolean> getMoveDone() {
|
||||
return moveDone;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,34 +19,27 @@
|
||||
|
||||
package ch.psi.fda.core.loops.cr;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import gov.aps.jca.Monitor;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.MonitorListenerDoubleTimestamp;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.impl.type.DoubleTimestamp;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
* Assumptions: - The delay between the monitor writing the value to the
|
||||
* monitor queue and the readout of all the queues is sufficient to
|
||||
* prevent the situation that some monitors of events close to each
|
||||
@@ -82,16 +75,14 @@ public class ScrlogicLoop implements ActionLoop {
|
||||
private final List<Action> preActions = new ArrayList<Action>();
|
||||
private final List<Action> postActions = new ArrayList<Action>();
|
||||
|
||||
/**
|
||||
* Sensors to read out
|
||||
*/
|
||||
private List<Sensor> sensors;
|
||||
private List<String> sensorIds;
|
||||
private List<Channel<DoubleTimestamp>> sensors;
|
||||
|
||||
/**
|
||||
* List of monitors that were attached to the sensor channels (i.e
|
||||
* workaround)
|
||||
*/
|
||||
private final List<Monitor> monitors = new ArrayList<Monitor>();
|
||||
private final List<PropertyChangeListener> monitors = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of blocking queues that hold the data for one sensor (channel)
|
||||
@@ -100,7 +91,8 @@ public class ScrlogicLoop implements ActionLoop {
|
||||
|
||||
private CountDownLatch latch;
|
||||
|
||||
public ScrlogicLoop(List<Sensor> sensors) {
|
||||
public ScrlogicLoop(List<String> sensorIds, List<Channel<DoubleTimestamp>> sensors) {
|
||||
this.sensorIds = sensorIds;
|
||||
this.sensors = sensors;
|
||||
}
|
||||
|
||||
@@ -116,57 +108,32 @@ public class ScrlogicLoop implements ActionLoop {
|
||||
queues.clear();
|
||||
latch = new CountDownLatch(1);
|
||||
|
||||
try {
|
||||
// Attach monitors to the channels (this is actually a workaround)
|
||||
for (Sensor sensor : sensors) {
|
||||
if (sensor instanceof ChannelAccessDoubleSensor) {
|
||||
ChannelAccessDoubleSensor s = (ChannelAccessDoubleSensor) sensor;
|
||||
ChannelBean<Double> b = s.getChannel();
|
||||
// Create data queue for the channel
|
||||
final BlockingQueue<TimestampedValue> q = new LinkedBlockingQueue<TimestampedValue>();
|
||||
queues.add(q);
|
||||
|
||||
Monitor m = b
|
||||
.attachMonitor(new MonitorListenerDoubleTimestamp() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(Double value, Date timestamp, long nanosecondsOffset) {
|
||||
// Add values to channel queue
|
||||
q.add(new TimestampedValue(value, timestamp.getTime(), nanosecondsOffset));
|
||||
}
|
||||
});
|
||||
monitors.add(m);
|
||||
}
|
||||
for (Channel<DoubleTimestamp> sensor : sensors) {
|
||||
final BlockingQueue<TimestampedValue> q = new LinkedBlockingQueue<TimestampedValue>();
|
||||
queues.add(q);
|
||||
PropertyChangeListener listener = new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
DoubleTimestamp v = (DoubleTimestamp) evt.getNewValue();
|
||||
q.add(new TimestampedValue(v.getValue(), v.getTimestamp().getTime(), v.getNanosecondOffset()));
|
||||
}
|
||||
};
|
||||
sensor.addPropertyChangeListener(listener);
|
||||
monitors.add(listener);
|
||||
|
||||
}
|
||||
} catch (CAException e) {
|
||||
new RuntimeException("Unable to create monitor for channels", e);
|
||||
}
|
||||
|
||||
logger.info("Start data acquisition");
|
||||
|
||||
latch.await();
|
||||
|
||||
// Remove monitors
|
||||
try {
|
||||
for (int i = 0; i < sensors.size(); i++) {
|
||||
Sensor sensor = sensors.get(i);
|
||||
if (sensor instanceof ChannelAccessDoubleSensor) {
|
||||
ChannelAccessDoubleSensor s = (ChannelAccessDoubleSensor) sensor;
|
||||
ChannelBean<Double> b = s.getChannel();
|
||||
try{
|
||||
b.removeMonitor(monitors.get(i));
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
logger.log(Level.SEVERE, "Unable to detach monitor", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CAException e) {
|
||||
new RuntimeException(e);
|
||||
}
|
||||
finally{
|
||||
// Clear all monitors in the list
|
||||
monitors.clear();
|
||||
|
||||
for (int i = 0; i < sensors.size(); i++) {
|
||||
Channel<DoubleTimestamp> sensor = sensors.get(i);
|
||||
sensor.removePropertyChangeListener(monitors.get(i));
|
||||
}
|
||||
|
||||
// Merge data
|
||||
@@ -183,85 +150,38 @@ public class ScrlogicLoop implements ActionLoop {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy all sensors
|
||||
for (Sensor s : sensors) {
|
||||
s.destroy();
|
||||
}
|
||||
sensors.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#getPreActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPreActions() {
|
||||
return preActions;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#getPostActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPostActions() {
|
||||
return postActions;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#isDataGroup()
|
||||
*/
|
||||
@Override
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#setDataGroup(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
@@ -280,8 +200,8 @@ public class ScrlogicLoop implements ActionLoop {
|
||||
m.getComponents().add(new ComponentMetadata(ID_TIMESTAMP_MILLISECONDS));
|
||||
m.getComponents().add(
|
||||
new ComponentMetadata(ID_TIMESTAMP_OFFSET_NANOSECONDS));
|
||||
for (Sensor s : sensors) {
|
||||
m.getComponents().add(new ComponentMetadata(s.getId()));
|
||||
for (String id : sensorIds) {
|
||||
m.getComponents().add(new ComponentMetadata(id));
|
||||
}
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package ch.psi.fda.core.loops.cr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
@@ -35,68 +35,68 @@ public class VSC16ScalerChannelsTemplate {
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".CNT")
|
||||
private ChannelBean<Integer> command;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.CNT")
|
||||
private Channel<Integer> command;
|
||||
|
||||
|
||||
public enum Mode {OneShot, AutoCount};
|
||||
/**
|
||||
* Count mode
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name =".CONT")
|
||||
private ChannelBean<Integer> mode;
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.CONT")
|
||||
private Channel<Integer> mode;
|
||||
|
||||
/**
|
||||
* Channel description
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name={".NM1", ".NM2", ".NM3", ".NM4", ".NM5", ".NM6", ".NM7", ".NM8", ".NM9", ".NM10", ".NM11", ".NM12", ".NM13", ".NM14", ".NM15", ".NM16"})
|
||||
private List<ChannelBean<Boolean>> channelDescription;
|
||||
@CaChannel(type=Boolean.class, name={"${PREFIX}.NM1", "${PREFIX}.NM2", "${PREFIX}.NM3", "${PREFIX}.NM4", "${PREFIX}.NM5", "${PREFIX}.NM6", "${PREFIX}.NM7", "${PREFIX}.NM8", "${PREFIX}.NM9", "${PREFIX}.NM10", "${PREFIX}.NM11", "${PREFIX}.NM12", "${PREFIX}.NM13", "${PREFIX}.NM14", "${PREFIX}.NM15", "${PREFIX}.NM16"})
|
||||
private List<Channel<Boolean>> channelDescription;
|
||||
|
||||
/**
|
||||
* Channel gate
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name={".G1", ".G2", ".G3", ".G4", ".G5", ".G6", ".G7", ".G8", ".G9", ".G10", ".G11", ".G12", ".G13", ".G14", ".G15", ".G16"})
|
||||
private List<ChannelBean<Boolean>> channelGate;
|
||||
@CaChannel(type=Boolean.class, name={"${PREFIX}.G1", "${PREFIX}.G2", "${PREFIX}.G3", "${PREFIX}.G4", "${PREFIX}.G5", "${PREFIX}.G6", "${PREFIX}.G7", "${PREFIX}.G8", "${PREFIX}.G9", "${PREFIX}.G10", "${PREFIX}.G11", "${PREFIX}.G12", "${PREFIX}.G13", "${PREFIX}.G14", "${PREFIX}.G15", "${PREFIX}.G16"})
|
||||
private List<Channel<Boolean>> channelGate;
|
||||
|
||||
/**
|
||||
* Channel preset count
|
||||
* If gate is on scaler will only count until this value
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name={".PR1", ".PR2", ".PR3", ".PR4", ".PR5", ".PR6", ".PR7", ".PR8", ".PR9", ".PR10", ".PR11", ".PR12", ".PR13", ".PR14", ".PR15", ".PR16"})
|
||||
private List<ChannelBean<Integer>> channelPresetCount;
|
||||
@CaChannel(type=Integer.class, name={"${PREFIX}.PR1", "${PREFIX}.PR2", "${PREFIX}.PR3", "${PREFIX}.PR4", "${PREFIX}.PR5", "${PREFIX}.PR6", "${PREFIX}.PR7", "${PREFIX}.PR8", "${PREFIX}.PR9", "${PREFIX}.PR10", "${PREFIX}.PR11", "${PREFIX}.PR12", "${PREFIX}.PR13", "${PREFIX}.PR14", "${PREFIX}.PR15", "${PREFIX}.PR16"})
|
||||
private List<Channel<Integer>> channelPresetCount;
|
||||
|
||||
/**
|
||||
* @return the command
|
||||
*/
|
||||
public ChannelBean<Integer> getCommand() {
|
||||
public Channel<Integer> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mode
|
||||
*/
|
||||
public ChannelBean<Integer> getMode() {
|
||||
public Channel<Integer> getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelDescription
|
||||
*/
|
||||
public List<ChannelBean<Boolean>> getChannelDescription() {
|
||||
public List<Channel<Boolean>> getChannelDescription() {
|
||||
return channelDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelGate
|
||||
*/
|
||||
public List<ChannelBean<Boolean>> getChannelGate() {
|
||||
public List<Channel<Boolean>> getChannelGate() {
|
||||
return channelGate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelPresetCount
|
||||
*/
|
||||
public List<ChannelBean<Integer>> getChannelPresetCount() {
|
||||
public List<Channel<Integer>> getChannelPresetCount() {
|
||||
return channelPresetCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
package ch.psi.fda.core.manipulator;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,17 +37,9 @@ import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingGlobalVariable;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingID;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
|
||||
/**
|
||||
* Manipulation
|
||||
* @author ebner
|
||||
*/
|
||||
public class JythonManipulation implements Manipulation{
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(JythonManipulation.class.getName());
|
||||
|
||||
/**
|
||||
@@ -195,19 +185,9 @@ public class JythonManipulation implements Manipulation{
|
||||
parameterIndex[i] = metadata.getIndex(pm.getRefid());
|
||||
}
|
||||
else if (jpm instanceof JythonParameterMappingChannel){
|
||||
JythonParameterMappingChannel pm = (JythonParameterMappingChannel)jpm;
|
||||
JythonParameterMappingChannel<?> pm = (JythonParameterMappingChannel<?>) jpm;
|
||||
parameterIndex[i] = null;
|
||||
|
||||
ChannelBean<?> cb;
|
||||
try {
|
||||
cb = ChannelBeanFactory.getFactory().createChannelBean(pm.getType(), pm.getChannel(), true);
|
||||
} catch (CAException e) {
|
||||
throw new IllegalArgumentException("Unable to establish channel: "+pm.getChannel(), e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to establish channel: "+pm.getChannel(), e);
|
||||
}
|
||||
|
||||
engine.put(pm.getVariable(), cb);
|
||||
engine.put(pm.getVariable(), pm.getChannel());
|
||||
}
|
||||
else if (jpm instanceof JythonParameterMappingGlobalVariable){
|
||||
JythonParameterMappingGlobalVariable pm = (JythonParameterMappingGlobalVariable)jpm;
|
||||
|
||||
@@ -19,57 +19,24 @@
|
||||
|
||||
package ch.psi.fda.core.scripting;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
|
||||
|
||||
/**
|
||||
* Mapping of a script parameter to a channel bean.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class JythonParameterMappingChannel extends JythonParameterMapping {
|
||||
public class JythonParameterMappingChannel<T> extends JythonParameterMapping {
|
||||
|
||||
/**
|
||||
* Id of the component to map to this variable
|
||||
*/
|
||||
private String channel;
|
||||
private Class<?> type;
|
||||
private Channel<T> channel;
|
||||
|
||||
/**
|
||||
* Constructor accepting varible/id pair
|
||||
* @param variable
|
||||
* @param channel
|
||||
* @param type
|
||||
*/
|
||||
public JythonParameterMappingChannel(String variable, String channel, Class<?> type){
|
||||
public JythonParameterMappingChannel(String variable, Channel<T> channel){
|
||||
super(variable);
|
||||
this.channel = channel;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channel
|
||||
*/
|
||||
public String getChannel() {
|
||||
public Channel<T> getChannel() {
|
||||
return channel;
|
||||
}
|
||||
/**
|
||||
* @param channel
|
||||
*/
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(Class<?> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
@@ -34,111 +35,46 @@ import ch.psi.jcae.ChannelBean;
|
||||
*/
|
||||
public class ChannelAccessDoubleArraySensor implements Sensor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensor.class.getName());
|
||||
|
||||
/**
|
||||
* Channel Access channel of this sensor
|
||||
*/
|
||||
private final ChannelBean<double[]> channel;
|
||||
|
||||
/**
|
||||
* Number of elements to read from the waveform
|
||||
*/
|
||||
private final int numberOfElements;
|
||||
|
||||
/**
|
||||
* Global id of the sensor
|
||||
*/
|
||||
private final Channel<double[]> channel;
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
* @param channelName Name of the Channel Access channel of this sensor
|
||||
* @param numberOfElements Number of elements to read out of the waveform
|
||||
* @param channel
|
||||
*/
|
||||
public ChannelAccessDoubleArraySensor(String id, String channelName, int numberOfElements){
|
||||
try {
|
||||
this.channel = ChannelBeanFactory.getFactory().createChannelBean(double[].class, channelName, false);
|
||||
this.numberOfElements = numberOfElements;
|
||||
this.id = id;
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
}
|
||||
public ChannelAccessDoubleArraySensor(String id, Channel<double[]> channel){
|
||||
this.channel = channel;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#readout()
|
||||
*/
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
|
||||
double[] v;
|
||||
try {
|
||||
v = channel.getValue(numberOfElements);
|
||||
} catch (IllegalStateException e) {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw e;
|
||||
}
|
||||
v = new double[numberOfElements];
|
||||
for(int i =0;i<v.length;i++){
|
||||
v[i] = Double.NaN;
|
||||
}
|
||||
} catch (CAException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
// return null
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
v = new double[numberOfElements];
|
||||
for(int i =0;i<v.length;i++){
|
||||
v[i] = Double.NaN;
|
||||
}
|
||||
|
||||
// } catch (InterruptedException e) {
|
||||
// // Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// // return NaN (Not a Number)
|
||||
// if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
// }
|
||||
//
|
||||
// v = new double[numberOfElements];
|
||||
// for(int i =0;i<v.length;i++){
|
||||
// v[i] = Double.NaN;
|
||||
// }
|
||||
v = null;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy sensor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
@@ -34,40 +35,21 @@ import ch.psi.jcae.ChannelBean;
|
||||
*/
|
||||
public class ChannelAccessDoubleSensor implements Sensor {
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensor.class.getName());
|
||||
|
||||
/**
|
||||
* Channel Access channel of this sensor
|
||||
*/
|
||||
private ChannelBean<Double> channel;
|
||||
|
||||
/**
|
||||
* Global id of the sensor
|
||||
*/
|
||||
private Channel<Double> channel;
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
* @param channelName Name of the Channel Access channel of this sensor
|
||||
* @param channel
|
||||
*/
|
||||
public ChannelAccessDoubleSensor(String id, String channelName){
|
||||
try {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
this.id = id;
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
}
|
||||
public ChannelAccessDoubleSensor(String id, Channel<Double> channel){
|
||||
this.channel = channel;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#readout()
|
||||
*/
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
@@ -75,58 +57,25 @@ public class ChannelAccessDoubleSensor implements Sensor {
|
||||
Double v;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (IllegalStateException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw e;
|
||||
}
|
||||
v = Double.NaN;
|
||||
} catch (CAException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = Double.NaN;
|
||||
// } catch (InterruptedException e) {
|
||||
// if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
// }
|
||||
// v = Double.NaN;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy sensor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get channel object of sensor
|
||||
* @return
|
||||
*/
|
||||
public ChannelBean<Double> getChannel(){
|
||||
public Channel<Double> getChannel(){
|
||||
return channel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
@@ -35,90 +36,44 @@ import ch.psi.jcae.ChannelBean;
|
||||
public class ChannelAccessStringSensor implements Sensor {
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessStringSensor.class.getName());
|
||||
|
||||
/**
|
||||
* Channel Access channel of this sensor
|
||||
*/
|
||||
private ChannelBean<String> channel;
|
||||
|
||||
/**
|
||||
* Global id of the sensor
|
||||
*/
|
||||
private final String id;
|
||||
private Channel<String> channel;
|
||||
private final String id; // Global id of the sensor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
* @param channelName Name of the Channel Access channel of this sensor
|
||||
*/
|
||||
public ChannelAccessStringSensor(String id, String channelName){
|
||||
try {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, channelName, false);
|
||||
this.id = id;
|
||||
} catch (CAException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize sensor channel [name:"+channelName+"]",e);
|
||||
}
|
||||
public ChannelAccessStringSensor(String id, Channel<String> channel){
|
||||
this.id = id;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#readout()
|
||||
*/
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
|
||||
String v;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (IllegalStateException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw e;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = null;
|
||||
}
|
||||
v = null;
|
||||
} catch (CAException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return NaN (Not a Number)
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = null;
|
||||
// } catch (InterruptedException e) {
|
||||
// if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
// }
|
||||
// v = null;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy sensor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (CAException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ package ch.psi.fda.core.actions;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
@@ -31,8 +33,11 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actions.ChannelAccessCondition;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
@@ -40,63 +45,60 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessConditionTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionTest.class.getName());
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringCondition#ChannelAccessStringCondition(java.lang.String, java.lang.String, long)}.
|
||||
* @throws InterruptedException
|
||||
* @throws CAException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessStringCondition() throws InterruptedException, CAException {
|
||||
final ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
public void testChannelAccessStringCondition() throws InterruptedException, CAException, ChannelException, TimeoutException, ExecutionException {
|
||||
final Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
channel.setValue("SomeValue");
|
||||
ChannelAccessCondition<String> c = new ChannelAccessCondition<String>(TestChannels.STRING_OUT, "SomeValue", 1000l);
|
||||
ChannelAccessCondition<String> c = new ChannelAccessCondition<String>(channel, "SomeValue", 1000l);
|
||||
c.execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelAccessStringConditionRegex() throws InterruptedException, CAException {
|
||||
final ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
public void testChannelAccessStringConditionRegex() throws InterruptedException, CAException, ExecutionException, ChannelException, TimeoutException {
|
||||
final Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
channel.setValue("SomeValue");
|
||||
ChannelAccessConditionRegex c = new ChannelAccessConditionRegex(TestChannels.STRING_OUT, "Some.*", 1000l);
|
||||
ChannelAccessConditionRegex c = new ChannelAccessConditionRegex(channel, "Some.*", 1000l);
|
||||
c.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringCondition#ChannelAccessStringCondition(java.lang.String, java.lang.String, long)}.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessStringConditionNotExist() {
|
||||
new ChannelAccessCondition<String>(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue", 1000l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringCondition#execute()}.
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() throws CAException, InterruptedException {
|
||||
public void testExecute() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
String value = "SomeValue";
|
||||
|
||||
final ChannelAccessCondition<String> action = new ChannelAccessCondition<String>(TestChannels.STRING_OUT, value, 10000l);
|
||||
final ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
final Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
final ChannelAccessCondition<String> action = new ChannelAccessCondition<String>(channel, value, 10000l);
|
||||
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@@ -131,11 +133,12 @@ public class ChannelAccessConditionTest {
|
||||
}
|
||||
|
||||
@Test(expected=RuntimeException.class)
|
||||
public void testExecuteFail() throws CAException, InterruptedException {
|
||||
public void testExecuteFail() throws CAException, InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
String value = "SomeValue";
|
||||
|
||||
final ChannelAccessCondition<String> action = new ChannelAccessCondition<String>(TestChannels.STRING_OUT, value, 9000l);
|
||||
final ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
final Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
final ChannelAccessCondition<String> action = new ChannelAccessCondition<String>(channel, value, 9000l);
|
||||
|
||||
|
||||
|
||||
// Set the value to something else than the expected value
|
||||
@@ -148,13 +151,17 @@ public class ChannelAccessConditionTest {
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringCondition#execute()}.
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteInteger() throws CAException, InterruptedException {
|
||||
public void testExecuteInteger() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
Integer value = 12;
|
||||
|
||||
final ChannelAccessCondition<Integer> action = new ChannelAccessCondition<Integer>(TestChannels.STRING_OUT, value, 10000l);
|
||||
final ChannelBean<Integer> channel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, TestChannels.STRING_OUT, false);
|
||||
final Channel<Integer> channel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, TestChannels.STRING_OUT));
|
||||
final ChannelAccessCondition<Integer> action = new ChannelAccessCondition<Integer>(channel, value, 10000l);
|
||||
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@@ -192,11 +199,16 @@ public class ChannelAccessConditionTest {
|
||||
* Test to ensure that the abort function is working correctly
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testWaitAbort() throws CAException, InterruptedException {
|
||||
final ChannelAccessCondition<Integer> action = new ChannelAccessCondition<Integer>(TestChannels.BINARY_OUT, 1, 10000l);
|
||||
final ChannelBean<Integer> channel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, TestChannels.BINARY_OUT, false);
|
||||
public void testWaitAbort() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
final Channel<Integer> channel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, TestChannels.BINARY_OUT));
|
||||
final ChannelAccessCondition<Integer> action = new ChannelAccessCondition<Integer>(channel, 1, 10000l);
|
||||
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -32,80 +32,79 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actions.ChannelAccessPut;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for ChannelAccessStringPut
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessPutTest {
|
||||
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#ChannelAccessStringPut(java.lang.String, java.lang.String, boolean)}.
|
||||
* Test correct initialization
|
||||
* @throws TimeoutException
|
||||
* @throws InterruptedException
|
||||
* @throws ChannelException
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessStringPutStringStringBoolean() {
|
||||
new ChannelAccessPut<String>(TestChannels.STRING_OUT, "SomeValue", true, null);
|
||||
public void testChannelAccessStringPutStringStringBoolean() throws ChannelException, InterruptedException, TimeoutException {
|
||||
new ChannelAccessPut<String>(cservice.createChannel(new ChannelDescriptor<>(String.class,TestChannels.STRING_OUT)), "SomeValue", true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#ChannelAccessStringPut(java.lang.String, java.lang.String, boolean)}.
|
||||
* Test whether the correct Exception is thrown if a non existing channel is specified at creation time
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessStringPutStringStringBooleanNotExist() {
|
||||
new ChannelAccessPut<String>(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue", true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#ChannelAccessStringPut(java.lang.String, java.lang.String)}.
|
||||
* Test correct initialization
|
||||
* @throws TimeoutException
|
||||
* @throws InterruptedException
|
||||
* @throws ChannelException
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessStringPutStringString() {
|
||||
new ChannelAccessPut<String>(TestChannels.STRING_OUT, "SomeValue");
|
||||
public void testChannelAccessStringPutStringString() throws ChannelException, InterruptedException, TimeoutException {
|
||||
new ChannelAccessPut<String>(cservice.createChannel(new ChannelDescriptor<>(String.class,TestChannels.STRING_OUT)), "SomeValue");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#ChannelAccessStringPut(java.lang.String, java.lang.String)}.
|
||||
* Test whether the correct Exception is thrown if a non existing channel is specified at creation time
|
||||
* @throws TimeoutException
|
||||
* @throws InterruptedException
|
||||
* @throws ChannelException
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessStringPutStringStringNotExist() {
|
||||
new ChannelAccessPut<String>(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue");
|
||||
@Test(expected=ChannelException.class)
|
||||
public void testChannelAccessStringPutStringStringNotExist() throws ChannelException, InterruptedException, TimeoutException {
|
||||
new ChannelAccessPut<String>(cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT_NOT_EXIST)), "SomeValue");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#execute()}.
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() throws CAException, InterruptedException {
|
||||
public void testExecute() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
String setValue = "MyTestString";
|
||||
ChannelAccessPut<String> action = new ChannelAccessPut<String>(TestChannels.STRING_OUT, setValue);
|
||||
Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
ChannelAccessPut<String> action = new ChannelAccessPut<String>(channel, setValue);
|
||||
action.execute();
|
||||
|
||||
ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
String value = channel.getValue();
|
||||
|
||||
if(!value.equals(setValue)){
|
||||
@@ -116,17 +115,20 @@ public class ChannelAccessPutTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#execute()}.
|
||||
* @throws CAException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteString() throws CAException, InterruptedException {
|
||||
public void testExecuteString() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
String setValue = "MyTestString";
|
||||
|
||||
ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
|
||||
Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT));
|
||||
// Set channel to something else
|
||||
channel.setValue(setValue+"test");
|
||||
|
||||
ChannelAccessPut<String> action = new ChannelAccessPut<String>(TestChannels.STRING_OUT, setValue);
|
||||
ChannelAccessPut<String> action = new ChannelAccessPut<String>(channel, setValue);
|
||||
action.execute();
|
||||
|
||||
|
||||
@@ -141,13 +143,15 @@ public class ChannelAccessPutTest {
|
||||
* Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#execute()}.
|
||||
* @throws CAException
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteMulti() throws CAException, InterruptedException {
|
||||
public void testExecuteMulti() throws InterruptedException, ChannelException, TimeoutException {
|
||||
|
||||
List<ChannelAccessPut<String>> actions = new ArrayList<ChannelAccessPut<String>>();
|
||||
for(int i=0;i<20;i++){
|
||||
actions.add(new ChannelAccessPut<String>(TestChannels.STRING_OUT, i+""));
|
||||
actions.add(new ChannelAccessPut<String>(cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT)), i+""));
|
||||
}
|
||||
|
||||
for(ChannelAccessPut<String> action: actions){
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
|
||||
package ch.psi.fda.core.actions;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -30,73 +29,61 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actions.JythonAction;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class JythonActionTest {
|
||||
|
||||
private static String SCRIPT = "import math\ndef process(o):\n print o.getValue()\n o.setValue(-1.0)\n print o.getValue()\n val=math.cos(10.0) + math.sin(o.getValue())\n print val\n o.setValue(val)";
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actions.JythonAction#execute()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() throws CAException {
|
||||
public void testExecute() throws ChannelException, InterruptedException, TimeoutException {
|
||||
try{
|
||||
Map<String,Object> mapping = new HashMap<>();
|
||||
mapping.put("o", cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)));
|
||||
|
||||
JythonAction action = new JythonAction(SCRIPT, mapping);
|
||||
|
||||
action.execute();
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWrongMapping1() throws ChannelException, InterruptedException, TimeoutException {
|
||||
Map<String,Object> mapping = new HashMap<>();
|
||||
mapping.put("o", cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)));
|
||||
mapping.put("b", cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)));
|
||||
|
||||
String script = "import math\ndef process(o):\n print o.getValue()\n o.setValue(-1.0)\n print o.getValue()\n val=math.cos(10.0) + math.sin(o.getValue())\n print val\n o.setValue(val)";
|
||||
List<JythonParameterMappingChannel> mapping = new ArrayList<JythonParameterMappingChannel>();
|
||||
mapping.add(new JythonParameterMappingChannel("o", TestChannels.ANALOG_OUT, Double.class));
|
||||
JythonAction action = new JythonAction(script, mapping);
|
||||
|
||||
// Execute action
|
||||
action.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether too much mappings are detected
|
||||
* Test method for {@link ch.psi.fda.core.actions.JythonAction#execute()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWrongMapping1() throws CAException {
|
||||
public void testWrongMapping2() {
|
||||
Map<String,Object> mapping = new HashMap<>();
|
||||
mapping.put("ooo", new String());
|
||||
String script = "import math\ndef process(o):\n print o.getValue()\n o.setValue(-1.0)\n print o.getValue()\n val=math.cos(10.0) + math.sin(o.getValue())\n print val\n o.setValue(val)";
|
||||
List<JythonParameterMappingChannel> mapping = new ArrayList<JythonParameterMappingChannel>();
|
||||
mapping.add(new JythonParameterMappingChannel("o", TestChannels.ANALOG_OUT, Double.class));
|
||||
mapping.add(new JythonParameterMappingChannel("b", TestChannels.ANALOG_OUT, Double.class));
|
||||
JythonAction action = new JythonAction(script, mapping);
|
||||
|
||||
// Execute action
|
||||
action.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a mapping to a wrong variable is detected
|
||||
* Test method for {@link ch.psi.fda.core.actions.JythonAction#execute()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWrongMapping2() throws CAException {
|
||||
String script = "import math\ndef process(o):\n print o.getValue()\n o.setValue(-1.0)\n print o.getValue()\n val=math.cos(10.0) + math.sin(o.getValue())\n print val\n o.setValue(val)";
|
||||
List<JythonParameterMappingChannel> mapping = new ArrayList<JythonParameterMappingChannel>();
|
||||
mapping.add(new JythonParameterMappingChannel("ooo", TestChannels.ANALOG_OUT, Double.class));
|
||||
JythonAction action = new JythonAction(script, mapping);
|
||||
|
||||
// Execute action
|
||||
action.execute();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,12 @@ package ch.psi.fda.core.actors;
|
||||
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -34,8 +35,11 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actors.ChannelAccessFunctionActuator;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class specific for the FunctionActuatorChannelAccess implementation.
|
||||
@@ -44,7 +48,6 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessFunctionActuatorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT;
|
||||
@@ -53,18 +56,17 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
private static final double doneDelay = 0;
|
||||
private static final Long timeout = 1800000l; // 30 minutes
|
||||
|
||||
private ChannelBean<Double> channel;
|
||||
private ChannelBean<Integer> doneChannel;
|
||||
private ChannelService cservice;
|
||||
private Channel<Double> channel;
|
||||
private Channel<Integer> doneChannel;
|
||||
|
||||
private Function function;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, channelNameDone, false);
|
||||
cservice = new DefaultChannelService();
|
||||
channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone));
|
||||
|
||||
function = new Function() {
|
||||
|
||||
@@ -75,11 +77,9 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,22 +87,22 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
* Check whether Exception is thrown if a negative step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessFunctionActuatorNegativeStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessFunctionActuatorNegativeStepSize() throws SocketException, Exception {
|
||||
// Need to throw exception because of negative step size
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function,0, 1, -0.1, timeout);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function,0, 1, -0.1, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#FunctionActuatorChannelAccess(String, double, double, double)}.
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessFunctionActuatorTimeout() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessFunctionActuatorTimeout() throws SocketException, Exception {
|
||||
|
||||
// Negative timeout
|
||||
boolean flag = false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException due to negative Timeout
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 1, 0.1, -1l);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 1, 0.1, -1l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -115,7 +115,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
flag=false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 1, 0.1, -0l);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 1, 0.1, -0l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -125,10 +125,10 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
}
|
||||
|
||||
// Accept null timeout
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 1, 0.1, null);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 1, 0.1, null);
|
||||
|
||||
// Accept positive timeout
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 1, 0.1, 1l);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 1, 0.1, 1l);
|
||||
|
||||
}
|
||||
|
||||
@@ -137,18 +137,18 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
* Check whether Exception is thrown if a zero step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessFunctionActuatorZeroStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessFunctionActuatorZeroStepSize() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 1, 0, timeout);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 1, 0, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#FunctionActuatorChannelAccess(String, double, double, double)}.
|
||||
* Check correct initialization
|
||||
*/
|
||||
public void testChannelAccessFunctionActuator() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessFunctionActuator() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 10, 1, timeout);
|
||||
new ChannelAccessFunctionActuator<Object>(channel, function, 0, 10, 1, timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSet() throws InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, 0, 0.09999, 0.1, timeout);
|
||||
actuator.set();
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testSetNoNext() throws InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, 0, 0.09999, 0.1, timeout);
|
||||
actuator.set();
|
||||
actuator.set();
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testHasNextOneStep() throws InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, 0, 0.09999, 0.1, timeout);
|
||||
// Execute first set (because there is always a first move)
|
||||
actuator.set();
|
||||
|
||||
@@ -197,7 +197,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testHasNext() throws InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, 0, 10, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, 0, 10, 0.1, timeout);
|
||||
|
||||
int count = 0;
|
||||
int steps = (int) ((10-0)/0.1)+1;
|
||||
@@ -227,7 +227,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
|
||||
int count =0;
|
||||
while(actuator.hasNext()){
|
||||
@@ -246,10 +246,13 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverse() throws CAException, InterruptedException {
|
||||
public void testReverse() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -258,7 +261,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
actuator.init();
|
||||
|
||||
int count =0;
|
||||
@@ -328,10 +331,13 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverseReset() throws CAException, InterruptedException {
|
||||
public void testReverseReset() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -340,7 +346,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channel, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
actuator.init();
|
||||
|
||||
int count =0;
|
||||
@@ -417,9 +423,9 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
* Check whether Exception is thrown if a negative step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessGPFunctionActuatorNegativeStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPFunctionActuatorNegativeStepSize() throws SocketException, Exception {
|
||||
// Need to throw exception because of negative step size
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, 0, 1, -0.1, timeout);
|
||||
new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, 0, 1, -0.1, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,29 +433,31 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
* Check whether Exception is thrown if a zero step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessGPFunctionActuatorZeroStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPFunctionActuatorZeroStepSize() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, 0, 1, 0, timeout);
|
||||
new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, 0, 1, 0, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#FunctionActuatorChannelAccess(String, double, double, double)}.
|
||||
* Check correct initialization
|
||||
*/
|
||||
public void testChannelAccessGPFunctionActuator() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPFunctionActuator() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, 0, 10, 1, timeout);
|
||||
new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, 0, 10, 1, timeout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneSet() throws CAException, InterruptedException {
|
||||
public void testDoneSet() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
@@ -472,12 +480,14 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneDelay() throws CAException, InterruptedException {
|
||||
public void testDoneDelay() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, 1.5, function, 0, 1, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, 1.5, function, 0, 1, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(1);
|
||||
@@ -510,12 +520,14 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#hasNext()}.
|
||||
* Check whether the actuator throws an Exception if there is no next point but set() is called
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testDoneSetNoNext() throws CAException, InterruptedException {
|
||||
public void testDoneSetNoNext() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function,0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function,0, 0.09999, 0.1, timeout);
|
||||
|
||||
|
||||
// Simulate done channel
|
||||
@@ -558,11 +570,13 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#hasNext()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneHasNextOneStep() throws CAException, InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout);
|
||||
public void testDoneHasNextOneStep() throws InterruptedException, ExecutionException, ChannelException {
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
@@ -592,11 +606,13 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#hasNext()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneHasNext() throws CAException, InterruptedException {
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function,0, 10, 0.1, timeout);
|
||||
public void testDoneHasNext() throws InterruptedException, ExecutionException, ChannelException {
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function,0, 10, 0.1, timeout);
|
||||
|
||||
int count = 0;
|
||||
int steps = (int) ((10-0)/0.1)+1;
|
||||
@@ -633,10 +649,12 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneSetLoop() throws CAException, InterruptedException {
|
||||
public void testDoneSetLoop() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -645,7 +663,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
|
||||
int count =0;
|
||||
while(actuator.hasNext()){
|
||||
@@ -682,10 +700,13 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#set()}.
|
||||
* Test whether the actuator returns if the actuator is already on the position it should be before the move ...
|
||||
* (see issue XASEC-278)
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testMoveToActualPosition() throws CAException, InterruptedException {
|
||||
public void testMoveToActualPosition() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
double start = 0;
|
||||
double end = 2;
|
||||
@@ -697,7 +718,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
logger.info("Current channel value: "+channel.getValue());
|
||||
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, function, start, end, stepSize, timeout);
|
||||
ChannelAccessFunctionActuator<Integer> actuator = new ChannelAccessFunctionActuator<>(channel, doneChannel, doneValue, doneDelay, function, start, end, stepSize, timeout);
|
||||
while(actuator.hasNext()){
|
||||
|
||||
// Simulate done channel
|
||||
@@ -740,7 +761,7 @@ public class ChannelAccessFunctionActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<Object>(channelName, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessFunctionActuator<Object> actuator = new ChannelAccessFunctionActuator<>(channel, function, svalue[0], svalue[1], svalue[2], timeout);
|
||||
|
||||
int count =0;
|
||||
while(actuator.hasNext()){
|
||||
|
||||
@@ -21,11 +21,12 @@ package ch.psi.fda.core.actors;
|
||||
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -34,8 +35,11 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actors.ChannelAccessLinearActuator;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class specific for the LinearActuatorChannelAccess implementation.
|
||||
@@ -53,23 +57,20 @@ public class ChannelAccessLinearActuatorTest {
|
||||
private static final double doneDelay = 0;
|
||||
private static final Long timeout = 1800000l; // 30 minutes
|
||||
|
||||
private ChannelBean<Double> channel;
|
||||
private ChannelBean<Integer> doneChannel;
|
||||
private ChannelService cservice;
|
||||
private Channel<Double> channel;
|
||||
private Channel<Integer> doneChannel;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, channelNameDone, false);
|
||||
cservice = new DefaultChannelService();
|
||||
channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,22 +78,22 @@ public class ChannelAccessLinearActuatorTest {
|
||||
* Check whether Exception is thrown if a negative step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessLinearActuatorNegativeStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessLinearActuatorNegativeStepSize() throws SocketException, Exception {
|
||||
// Need to throw exception because of negative step size
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, -0.1, timeout);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, -0.1, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#LinearActuatorChannelAccess(String, double, double, double)}.
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessLinearActuatorTimeout() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessLinearActuatorTimeout() throws SocketException, Exception {
|
||||
|
||||
// Negative timeout
|
||||
boolean flag = false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException due to negative Timeout
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, 0.1, -1l);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, 0.1, -1l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -105,7 +106,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
flag=false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, 0.1, -0l);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, 0.1, -0l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -115,10 +116,10 @@ public class ChannelAccessLinearActuatorTest {
|
||||
}
|
||||
|
||||
// Accept null timeout
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, 0.1, null);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, 0.1, null);
|
||||
|
||||
// Accept positive timeout
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, 0.1, 1l);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, 0.1, 1l);
|
||||
|
||||
}
|
||||
|
||||
@@ -127,18 +128,18 @@ public class ChannelAccessLinearActuatorTest {
|
||||
* Check whether Exception is thrown if a zero step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessLinearActuatorZeroStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessLinearActuatorZeroStepSize() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 1, 0, timeout);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 1, 0, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#LinearActuatorChannelAccess(String, double, double, double)}.
|
||||
* Check correct initialization
|
||||
*/
|
||||
public void testChannelAccessLinearActuator() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessLinearActuator() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 10, 1, timeout);
|
||||
new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 10, 1, timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +149,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSet() throws InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
actuator.set();
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testSetNoNext() throws InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
actuator.set();
|
||||
actuator.set();
|
||||
}
|
||||
@@ -170,7 +171,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testHasNextOneStep() throws InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 0.09999, 0.1, timeout);
|
||||
// Execute first set (because there is always a first move)
|
||||
actuator.set();
|
||||
|
||||
@@ -187,7 +188,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testHasNext() throws InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, 0, 10, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, 0, 10, 0.1, timeout);
|
||||
|
||||
int count = 0;
|
||||
int steps = (int) ((10-0)/0.1)+1;
|
||||
@@ -217,7 +218,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<Integer>(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<Integer>(channel, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
|
||||
int count =0;
|
||||
while(actuator.hasNext()){
|
||||
@@ -236,10 +237,13 @@ public class ChannelAccessLinearActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverse() throws CAException, InterruptedException {
|
||||
public void testReverse() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -248,7 +252,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
actuator.init();
|
||||
|
||||
int count =0;
|
||||
@@ -316,10 +320,13 @@ public class ChannelAccessLinearActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverseReset() throws CAException, InterruptedException {
|
||||
public void testReverseReset() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -328,7 +335,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channel, null, 1,0, svalue[0], svalue[1], svalue[2], timeout);
|
||||
actuator.init();
|
||||
|
||||
int count =0;
|
||||
@@ -403,9 +410,9 @@ public class ChannelAccessLinearActuatorTest {
|
||||
* Check whether Exception is thrown if a negative step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessGPLinearActuatorNegativeStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPLinearActuatorNegativeStepSize() throws SocketException, Exception {
|
||||
// Need to throw exception because of negative step size
|
||||
new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 1, -0.1, timeout);
|
||||
new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 1, -0.1, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,29 +420,31 @@ public class ChannelAccessLinearActuatorTest {
|
||||
* Check whether Exception is thrown if a zero step size is specified.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessGPLinearActuatorZeroStepSize() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPLinearActuatorZeroStepSize() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 1, 0, timeout);
|
||||
new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 1, 0, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#LinearActuatorChannelAccess(String, double, double, double)}.
|
||||
* Check correct initialization
|
||||
*/
|
||||
public void testChannelAccessGPLinearActuator() throws SocketException, CAException, Exception {
|
||||
public void testChannelAccessGPLinearActuator() throws SocketException, Exception {
|
||||
// Zero step size need to cause an exception
|
||||
new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 10, 1, timeout);
|
||||
new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 10, 1, timeout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneSet() throws CAException, InterruptedException {
|
||||
public void testDoneSet() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
@@ -458,12 +467,14 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneDelay() throws CAException, InterruptedException {
|
||||
public void testDoneDelay() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, 1.5, 0, 1, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, 1.5, 0, 1, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(1);
|
||||
@@ -496,12 +507,14 @@ public class ChannelAccessLinearActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#hasNext()}.
|
||||
* Check whether the actuator throws an Exception if there is no next point but set() is called
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testDoneSetNoNext() throws CAException, InterruptedException {
|
||||
public void testDoneSetNoNext() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
|
||||
|
||||
// Simulate done channel
|
||||
@@ -544,11 +557,13 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#hasNext()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneHasNextOneStep() throws CAException, InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
public void testDoneHasNextOneStep() throws InterruptedException, ExecutionException, ChannelException {
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 0.09999, 0.1, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
@@ -578,11 +593,13 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#hasNext()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneHasNext() throws CAException, InterruptedException {
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, 0, 10, 0.1, timeout);
|
||||
public void testDoneHasNext() throws InterruptedException, ExecutionException, ChannelException {
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, 0, 10, 0.1, timeout);
|
||||
|
||||
int count = 0;
|
||||
int steps = (int) ((10-0)/0.1)+1;
|
||||
@@ -619,10 +636,12 @@ public class ChannelAccessLinearActuatorTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#set()}.
|
||||
* Test actuator move start<end and start>end ...
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneSetLoop() throws CAException, InterruptedException {
|
||||
public void testDoneSetLoop() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
List<double[]> settings = new ArrayList<double[]>();
|
||||
// start end stepsize
|
||||
@@ -631,7 +650,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
|
||||
for(double[] svalue: settings){
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, svalue[0], svalue[1], svalue[2], timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, svalue[0], svalue[1], svalue[2], timeout);
|
||||
|
||||
int count =0;
|
||||
while(actuator.hasNext()){
|
||||
@@ -668,10 +687,13 @@ public class ChannelAccessLinearActuatorTest {
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#set()}.
|
||||
* Test whether the actuator returns if the actuator is already on the position it should be before the move ...
|
||||
* (see issue XASEC-278)
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testMoveToActualPosition() throws CAException, InterruptedException {
|
||||
public void testMoveToActualPosition() throws InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
|
||||
double start = 0;
|
||||
double end = 2;
|
||||
@@ -683,7 +705,7 @@ public class ChannelAccessLinearActuatorTest {
|
||||
|
||||
logger.info("Current channel value: "+channel.getValue());
|
||||
|
||||
ChannelAccessLinearActuator<Object> actuator = new ChannelAccessLinearActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, start, end, stepSize, timeout);
|
||||
ChannelAccessLinearActuator<Integer> actuator = new ChannelAccessLinearActuator<>(channel, doneChannel, doneValue, doneDelay, start, end, stepSize, timeout);
|
||||
while(actuator.hasNext()){
|
||||
|
||||
// Simulate done channel
|
||||
|
||||
@@ -21,26 +21,24 @@ package ch.psi.fda.core.actors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actors.ChannelAccessTableActuator;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessTableActuatorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessTableActuatorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.BINARY_OUT;
|
||||
@@ -50,23 +48,20 @@ public class ChannelAccessTableActuatorTest {
|
||||
private static final double doneDelay = 0;
|
||||
private static final Long timeout = 1800000l; // 30 minutes
|
||||
|
||||
private ChannelBean<Double> channel;
|
||||
private ChannelBean<Integer> doneChannel;
|
||||
private ChannelService cservice;
|
||||
private Channel<Double> channel;
|
||||
private Channel<Integer> doneChannel;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
doneChannel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, channelNameDone, false);
|
||||
cservice = new DefaultChannelService();
|
||||
channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +69,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testChannelAccessTableActuator() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[]{1}, timeout);
|
||||
new ChannelAccessTableActuator<>(channel, new double[]{1}, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +81,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
boolean flag = false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException due to negative Timeout
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[]{1}, -1l);
|
||||
new ChannelAccessTableActuator<>(channel, new double[]{1}, -1l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -99,7 +94,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
flag=false;
|
||||
try{
|
||||
// Need to return IllegalArgumentException
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[]{1}, 0l);
|
||||
new ChannelAccessTableActuator<>(channel, new double[]{1}, 0l);
|
||||
}
|
||||
catch(IllegalArgumentException e){
|
||||
flag=true;
|
||||
@@ -109,10 +104,10 @@ public class ChannelAccessTableActuatorTest {
|
||||
}
|
||||
|
||||
// Accept null timeout
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[]{1}, null);
|
||||
new ChannelAccessTableActuator<>(channel, new double[]{1}, null);
|
||||
|
||||
// Accept positive timeout
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[]{1}, 1l);
|
||||
new ChannelAccessTableActuator<>(channel, new double[]{1}, 1l);
|
||||
|
||||
}
|
||||
|
||||
@@ -122,7 +117,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessTableActuatorNull() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, null, timeout);
|
||||
new ChannelAccessTableActuator<>(channel, null, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,17 +126,20 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testChannelAccessTableActuatorEmptyTable() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, new double[0], timeout);
|
||||
new ChannelAccessTableActuator<>(channel, new double[0], timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testSet() throws CAException, InterruptedException {
|
||||
public void testSet() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
double[] table = new double[]{1,2,3,4,5,6};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, table, timeout);
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<>(channel, table, timeout);
|
||||
|
||||
int count=0;
|
||||
while(actor.hasNext()){
|
||||
@@ -166,7 +164,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
@Test(expected=RuntimeException.class)
|
||||
public void testSetFail() throws InterruptedException {
|
||||
double[] table = new double[]{1};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, table, timeout);
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<>(channel, table, timeout);
|
||||
actor.set();
|
||||
|
||||
// This set() call has to fail with an RuntimeException
|
||||
@@ -181,7 +179,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
public void testHasNext() throws InterruptedException {
|
||||
|
||||
double[] table = new double[]{1};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, table, timeout);
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<>(channel, table, timeout);
|
||||
actor.set();
|
||||
|
||||
boolean next = actor.hasNext();
|
||||
@@ -192,12 +190,15 @@ public class ChannelAccessTableActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverse() throws CAException, InterruptedException {
|
||||
public void testReverse() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
double[] table = new double[]{1,2,3,4,5,6};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, table, timeout);
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channel, table, timeout);
|
||||
actor.init();
|
||||
|
||||
int count=0;
|
||||
@@ -237,12 +238,15 @@ public class ChannelAccessTableActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testReverseReset() throws CAException, InterruptedException {
|
||||
public void testReverseReset() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
double[] table = new double[]{1,2,3,4,5,6};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, table, timeout);
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channel, table, timeout);
|
||||
actor.init();
|
||||
|
||||
int count=0;
|
||||
@@ -287,7 +291,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDoneChannelAccessTableActuator() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, new double[]{1}, timeout);
|
||||
new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, new double[]{1}, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,7 +300,7 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDoneChannelAccessTableActuatorNull() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, null, timeout);
|
||||
new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, null, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,17 +309,20 @@ public class ChannelAccessTableActuatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDoneChannelAccessTableActuatorEmptyTable() {
|
||||
new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, new double[0], timeout);
|
||||
new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, new double[0], timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneSet() throws CAException, InterruptedException {
|
||||
public void testDoneSet() throws InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
double[] table = new double[]{1,2,3,4,5,6};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, table, timeout);
|
||||
ChannelAccessTableActuator<Integer> actor = new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, table, timeout);
|
||||
|
||||
int count=0;
|
||||
while(actor.hasNext()){
|
||||
@@ -349,12 +356,15 @@ public class ChannelAccessTableActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneDelay() throws CAException, InterruptedException {
|
||||
public void testDoneDelay() throws InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
double[] table = new double[]{1,2,3,4,5,6};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, 0.1, table, timeout);
|
||||
ChannelAccessTableActuator<Integer> actor = new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, 0.1, table, timeout);
|
||||
|
||||
int count=0;
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -398,12 +408,14 @@ public class ChannelAccessTableActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#set()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test(expected=RuntimeException.class)
|
||||
public void testDoneSetFail() throws CAException, InterruptedException {
|
||||
public void testDoneSetFail() throws InterruptedException, ExecutionException, ChannelException {
|
||||
double[] table = new double[]{1};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, table, timeout);
|
||||
ChannelAccessTableActuator<Integer> actor = new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, table, timeout);
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
new Thread(new Runnable() {
|
||||
@@ -442,13 +454,15 @@ public class ChannelAccessTableActuatorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ChannelAccessTableActuator#hasNext()}.
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testDoneHasNext() throws CAException, InterruptedException {
|
||||
public void testDoneHasNext() throws InterruptedException, ExecutionException, ChannelException {
|
||||
|
||||
double[] table = new double[]{1};
|
||||
ChannelAccessTableActuator<Object> actor = new ChannelAccessTableActuator<Object>(channelName, channelNameDone, doneValue, doneDelay, table, timeout);
|
||||
ChannelAccessTableActuator<Integer> actor = new ChannelAccessTableActuator<>(channel, doneChannel, doneValue, doneDelay, table, timeout);
|
||||
|
||||
// Simulate done channel
|
||||
doneChannel.setValue(0);
|
||||
|
||||
@@ -22,6 +22,7 @@ package ch.psi.fda.core.actors;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -31,6 +32,10 @@ import org.junit.Test;
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.actors.ChannelAccessLinearActuator;
|
||||
import ch.psi.fda.core.actors.ComplexActuator;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Prerequisites for this test are:
|
||||
@@ -41,37 +46,29 @@ import ch.psi.fda.core.actors.ComplexActuator;
|
||||
*/
|
||||
public class ComplexActorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ComplexActorTest.class.getName());
|
||||
|
||||
private static final Long timeout = 1800000l;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.actors.ComplexActuator#set()}.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testSet() throws InterruptedException {
|
||||
public void testSet() throws InterruptedException, ChannelException, TimeoutException {
|
||||
|
||||
ComplexActuator actuator = new ComplexActuator();
|
||||
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(TestChannels.ANALOG_OUT, null, 1,0, 0, 0.09999, 0.1, timeout));
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(TestChannels.ANALOG_OUT, null, 1,0, 1, 2, 0.1, timeout));
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(TestChannels.ANALOG_OUT, null, 1,0, -1, -2, 0.1, timeout));
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)), null, 1,0, 0, 0.09999, 0.1, timeout));
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)), null, 1,0, 1, 2, 0.1, timeout));
|
||||
actuator.getActors().add(new ChannelAccessLinearActuator<Object>(cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT)), null, 1,0, -1, -2, 0.1, timeout));
|
||||
|
||||
// Initialize actuator
|
||||
actuator.init();
|
||||
|
||||
@@ -21,10 +21,10 @@ package ch.psi.fda.core.guard;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -34,44 +34,48 @@ import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.Guard;
|
||||
import ch.psi.fda.core.guard.ChannelAccessGuard;
|
||||
import ch.psi.fda.core.guard.ChannelAccessGuardCondition;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessGuardTest {
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.guard.ChannelAccessGuard#check()}.
|
||||
* @throws InterruptedException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testCheck() throws InterruptedException, CAException {
|
||||
String guardChannel = TestChannels.ANALOG_OUT;
|
||||
Integer channelOkValue = 10;
|
||||
List<ChannelAccessGuardCondition> conditions = new ArrayList<ChannelAccessGuardCondition>();
|
||||
conditions.add(new ChannelAccessGuardCondition(guardChannel, channelOkValue));
|
||||
Guard guard = new ChannelAccessGuard(conditions );
|
||||
public void testCheck() throws InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
|
||||
ChannelBean<Integer> b = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, guardChannel, false);
|
||||
b.setValue(channelOkValue);
|
||||
String guardChannel = TestChannels.ANALOG_OUT;
|
||||
Channel<Integer> channel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, guardChannel));
|
||||
|
||||
|
||||
Integer channelOkValue = 10;
|
||||
List<ChannelAccessGuardCondition<?>> conditions = new ArrayList<>();
|
||||
conditions.add(new ChannelAccessGuardCondition<>(channel, channelOkValue));
|
||||
Guard guard = new ChannelAccessGuard(conditions);
|
||||
|
||||
|
||||
channel.setValue(channelOkValue);
|
||||
|
||||
guard.init();
|
||||
|
||||
@@ -79,8 +83,8 @@ public class ChannelAccessGuardTest {
|
||||
fail("Guard not in correct state");
|
||||
}
|
||||
|
||||
b.setValue(channelOkValue+1);
|
||||
b.setValue(channelOkValue);
|
||||
channel.setValue(channelOkValue+1);
|
||||
channel.setValue(channelOkValue);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
@@ -89,7 +93,7 @@ public class ChannelAccessGuardTest {
|
||||
fail("Guard not in correct state");
|
||||
}
|
||||
|
||||
b.setValue(channelOkValue);
|
||||
channel.setValue(channelOkValue);
|
||||
|
||||
// Check if after init the guard is ok again
|
||||
guard.init();
|
||||
@@ -99,7 +103,7 @@ public class ChannelAccessGuardTest {
|
||||
}
|
||||
|
||||
// Check if after init the guard is not ok
|
||||
b.setValue(channelOkValue+1);
|
||||
channel.setValue(channelOkValue+1);
|
||||
guard.init();
|
||||
|
||||
if(guard.check()){
|
||||
|
||||
@@ -21,12 +21,12 @@ package ch.psi.fda.core.loops;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -48,8 +48,11 @@ import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessStringSensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
@@ -65,21 +68,21 @@ public class ActorSensorLoopTest {
|
||||
private static final String wfChannel = TestChannels.DOUBLE_WAVEFORM;
|
||||
private static final Long timeout = 1800000l; // 30 minutes
|
||||
|
||||
|
||||
private ChannelService cservice;
|
||||
private ActorSensorLoop loopOne;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
|
||||
loopOne = new ActorSensorLoop();
|
||||
|
||||
ChannelAccessLinearActuator<Object> a = new ChannelAccessLinearActuator<Object>(aoChannel, null, 1,0, 0, 10, 0.1, timeout); // Positioner
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", boChannel); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", aoChannel); // Scalar Detector
|
||||
ChannelAccessStringSensor s1string = new ChannelAccessStringSensor("id3", boChannel+".NAME"); // Scalar String Detector
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", wfChannel, 10);
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 10, 0.1, timeout); // Positioner
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); // Scalar Detector
|
||||
ChannelAccessStringSensor s1string = new ChannelAccessStringSensor("id3", cservice.createChannel(new ChannelDescriptor<>(String.class, boChannel+".NAME"))); // Scalar String Detector
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class, wfChannel,false, 10)));
|
||||
|
||||
loopOne.getActors().add(a);
|
||||
loopOne.getSensors().add(s);
|
||||
@@ -90,12 +93,10 @@ public class ActorSensorLoopTest {
|
||||
loopOne.prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
loopOne.destroy();
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,14 +135,17 @@ public class ActorSensorLoopTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.loops.ActorSensorLoop#getDataMessageMetadata()}.
|
||||
* @throws TimeoutException
|
||||
* @throws InterruptedException
|
||||
* @throws ChannelException
|
||||
*/
|
||||
@Test
|
||||
public void testGetDataMessageMetadata(){
|
||||
public void testGetDataMessageMetadata() throws ChannelException, InterruptedException, TimeoutException{
|
||||
ActorSensorLoop loop = new ActorSensorLoop();
|
||||
|
||||
int numberOfSensors = 2;
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", boChannel); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("id1", aoChannel); // Scalar Detector
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
loop.getSensors().add(s1);
|
||||
loop.getSensors().add(s2);
|
||||
|
||||
@@ -167,18 +171,21 @@ public class ActorSensorLoopTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.loops.ActorSensorLoop#execute()}.
|
||||
* @throws InterruptedException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteGuard() throws InterruptedException, CAException {
|
||||
public void testExecuteGuard() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
ActorSensorLoop loop = new ActorSensorLoop();
|
||||
|
||||
ChannelAccessLinearActuator<Object> a = new ChannelAccessLinearActuator<Object>(aoChannel, null, 1,0, 0, 1.5, 0.1,timeout); // Positioner
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 1.5, 0.1,timeout); // Positioner
|
||||
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", aoChannel); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", boChannel); // Scalar Detector
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", wfChannel, 10);
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class,wfChannel, false,10)));
|
||||
|
||||
loop.getActors().add(a);
|
||||
loop.getPostActorActions().add(new Delay(500));
|
||||
@@ -188,12 +195,13 @@ public class ActorSensorLoopTest {
|
||||
|
||||
// Guard
|
||||
final Integer okValue = 0;
|
||||
List<ChannelAccessGuardCondition> conditions = new ArrayList<ChannelAccessGuardCondition>();
|
||||
conditions.add(new ChannelAccessGuardCondition(boChannel, new Integer(0)));
|
||||
final Channel<Integer> b = cservice.createChannel(new ChannelDescriptor<>(Integer.class, boChannel));
|
||||
List<ChannelAccessGuardCondition<?>> conditions = new ArrayList<>();
|
||||
conditions.add(new ChannelAccessGuardCondition<Integer>(b, 0));
|
||||
Guard guard = new ChannelAccessGuard(conditions);
|
||||
loop.setGuard(guard);
|
||||
|
||||
final ChannelBean<Integer> b = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, boChannel, false);
|
||||
|
||||
|
||||
Thread tguard = new Thread(new Runnable() {
|
||||
|
||||
@@ -253,16 +261,16 @@ public class ActorSensorLoopTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testParallelSet() throws InterruptedException, CAException {
|
||||
public void testParallelSet() throws InterruptedException, ChannelException, TimeoutException {
|
||||
|
||||
final int steps = 2;
|
||||
final HashMap<String,Long> timestamps = new HashMap<String, Long>();
|
||||
|
||||
ActorSensorLoop loop = new ActorSensorLoop();
|
||||
|
||||
ChannelAccessLinearActuator<Object> a = new ChannelAccessLinearActuator<Object>(aoChannel, null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner
|
||||
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", aoChannel); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
|
||||
loop.getActors().add(a);
|
||||
loop.getActors().add(new Actor() {
|
||||
|
||||
@@ -21,9 +21,11 @@ package ch.psi.fda.core.loops;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -42,61 +44,31 @@ import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFReadbackSensor;
|
||||
import ch.psi.fda.core.sensors.OTFScalerChannelSensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class OTFLoopTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(OTFLoopTest.class.getName());
|
||||
|
||||
class TestCollector implements Runnable{
|
||||
|
||||
private final BlockingQueue<Message> queue;
|
||||
public TestCollector(BlockingQueue<Message> queue){
|
||||
this.queue = queue;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while(true){
|
||||
Message m = queue.take();
|
||||
if(m instanceof DataMessage){
|
||||
DataMessage x = (DataMessage) m;
|
||||
logger.fine( x.toString() );
|
||||
}
|
||||
else if(m instanceof ControlMessage){
|
||||
logger.fine("---- "+m.toString()+" ----");
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, "An Exception occured while reading data from the data queue", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private ChannelService cservice;
|
||||
|
||||
|
||||
|
||||
private static final TestConfiguration configuration = TestConfiguration.getInstance();
|
||||
|
||||
|
||||
private OTFLoop loopZigZag;
|
||||
private OTFLoop loop;
|
||||
private ChannelBean<Integer> statusChannel;
|
||||
private Channel<Integer> statusChannel;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
statusChannel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, configuration.getOtfPrefix()+":USTAT", false);
|
||||
cservice = new DefaultChannelService();
|
||||
statusChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getOtfPrefix()+":USTAT"));
|
||||
|
||||
OTFActuator actor = new OTFActuator("id", configuration.getMotor1(), null, 0, 8, 0.5, 0.5, 0);
|
||||
OTFReadbackSensor s1 = new OTFReadbackSensor("id0");
|
||||
@@ -105,9 +77,14 @@ public class OTFLoopTest {
|
||||
MillisecondTimestampSensor s4 = new MillisecondTimestampSensor("id3");
|
||||
OTFNamedChannelSensor s5 = new OTFNamedChannelSensor("id4", configuration.getAnalogIn1());
|
||||
|
||||
Map<String, String> macros = new HashMap<>();
|
||||
macros.put("PREFIX", configuration.getOtfPrefix());
|
||||
OTFBean template = new OTFBean();
|
||||
cservice.createAnnotatedChannels(template);
|
||||
|
||||
|
||||
// ZigZag loop
|
||||
loopZigZag = new OTFLoop(configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), true);
|
||||
loopZigZag = new OTFLoop(template, configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), true);
|
||||
loopZigZag.setActor(actor);
|
||||
loopZigZag.getSensors().add(s1);
|
||||
loopZigZag.getSensors().add(s2);
|
||||
@@ -117,7 +94,7 @@ public class OTFLoopTest {
|
||||
|
||||
|
||||
// Normal loop
|
||||
loop = new OTFLoop(configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), false);
|
||||
loop = new OTFLoop(template, configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), false);
|
||||
loop.setActor(actor);
|
||||
loop.getSensors().add(s1);
|
||||
loop.getSensors().add(s2);
|
||||
@@ -126,20 +103,21 @@ public class OTFLoopTest {
|
||||
loop.getSensors().add(s5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.loops.OTFLoop#execute()}.
|
||||
* Test ordinary 1D OTF scan
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() throws CAException, InterruptedException {
|
||||
public void testExecute() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
Thread t = new Thread(new TestCollector(loop.getDataQueue().getQueue()));
|
||||
t.start();
|
||||
@@ -158,10 +136,13 @@ public class OTFLoopTest {
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.loops.OTFLoop#execute()}.
|
||||
* Test OTF ZigZag mode
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteZigZag() throws CAException, InterruptedException {
|
||||
public void testExecuteZigZag() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
Thread t = new Thread(new TestCollector(loopZigZag.getDataQueue().getQueue()));
|
||||
t.start();
|
||||
@@ -184,7 +165,7 @@ public class OTFLoopTest {
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteAbort() throws CAException, InterruptedException {
|
||||
public void testExecuteAbort() throws InterruptedException {
|
||||
|
||||
// Data collector thread
|
||||
Thread t = new Thread(new TestCollector(loop.getDataQueue().getQueue()));
|
||||
@@ -239,4 +220,33 @@ public class OTFLoopTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestCollector implements Runnable{
|
||||
|
||||
private final BlockingQueue<Message> queue;
|
||||
public TestCollector(BlockingQueue<Message> queue){
|
||||
this.queue = queue;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while(true){
|
||||
Message m = queue.take();
|
||||
if(m instanceof DataMessage){
|
||||
DataMessage x = (DataMessage) m;
|
||||
logger.fine( x.toString() );
|
||||
}
|
||||
else if(m instanceof ControlMessage){
|
||||
logger.fine("---- "+m.toString()+" ----");
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, "An Exception occured while reading data from the data queue", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -46,28 +48,28 @@ import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingID;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
public class ManipulatorTest {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ManipulatorTest.class.getName());
|
||||
|
||||
private EventBus bus;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
bus = new EventBus();
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,13 +393,17 @@ public class ManipulatorTest {
|
||||
* Test method for {@link ch.psi.fda.core.manipulator.Manipulator#run()}.
|
||||
* @throws InterruptedException
|
||||
* @throws CAException
|
||||
* @throws TimeoutException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
*/
|
||||
@Test
|
||||
public void testRunMultipleParameterAndChannel() throws InterruptedException, CAException {
|
||||
public void testRunMultipleParameterAndChannel() throws InterruptedException, CAException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
Double setValue = 12.22;
|
||||
|
||||
ChannelBean<Double> cbean = ChannelBeanFactory.getFactory().createChannelBean(Double.class, TestChannels.ANALOG_OUT, false);
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, TestChannels.ANALOG_OUT));
|
||||
|
||||
|
||||
DataMessageMetadata dmm = new DataMessageMetadata();
|
||||
dmm.getComponents().add(new ComponentMetadata("myid"));
|
||||
@@ -408,7 +414,7 @@ public class ManipulatorTest {
|
||||
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
|
||||
mapping.add(new JythonParameterMappingID("o", "myid"));
|
||||
mapping.add(new JythonParameterMappingID("c", "myid2"));
|
||||
mapping.add(new JythonParameterMappingChannel("d", TestChannels.ANALOG_OUT, Double.class));
|
||||
mapping.add(new JythonParameterMappingChannel<Double>("d", channel));
|
||||
JythonManipulation manipulation = new JythonManipulation(id, script, mapping);
|
||||
|
||||
List<Manipulation> manipulations = new ArrayList<Manipulation>();
|
||||
@@ -438,7 +444,7 @@ public class ManipulatorTest {
|
||||
}
|
||||
|
||||
// Change something different on the channel than the value that will be set in the manipulator script
|
||||
cbean.setValue(setValue+1);
|
||||
channel.setValue(setValue+1);
|
||||
|
||||
bus.register(new Object(){
|
||||
@Subscribe
|
||||
@@ -468,7 +474,7 @@ public class ManipulatorTest {
|
||||
logger.info(""+(Math.cos(0.2)+Math.sin(10)));
|
||||
|
||||
// Check whether the channel was set correctly by the manipulator script
|
||||
if(Math.abs(cbean.getValue()-setValue)>0.00000001){
|
||||
if(Math.abs(channel.getValue()-setValue)>0.00000001){
|
||||
fail("Channel was not set correctly in the manipulator script");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
@@ -31,8 +33,11 @@ import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
@@ -41,34 +46,26 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessDoubleArraySensorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.DOUBLE_WAVEFORM;
|
||||
private static final int numberOfPoints = 10;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException {
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor("id0", channelName, numberOfPoints);
|
||||
ChannelBean<double[]> channel = ChannelBeanFactory.getFactory().createChannelBean(double[].class, channelName, false);
|
||||
public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
Channel<double[]> channel = cservice.createChannel(new ChannelDescriptor<>(double[].class, channelName, false, numberOfPoints));
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor("id0", channel);
|
||||
|
||||
// Prepare sensor channel
|
||||
double[] setValue = new double[] { 0.1,0.2,0.3,4,5,6,77,88,99,10.2};
|
||||
|
||||
@@ -21,18 +21,21 @@ package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
@@ -41,33 +44,25 @@ import ch.psi.jcae.ChannelBeanFactory;
|
||||
*/
|
||||
public class ChannelAccessDoubleSensorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException {
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor("id0", channelName);
|
||||
ChannelBean<Double> channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
public void testRead() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor("id0", channel);
|
||||
|
||||
// Prepare sensor channel
|
||||
Double setValue = 0.1d;
|
||||
|
||||
@@ -21,6 +21,7 @@ package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
@@ -30,6 +31,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
@@ -38,33 +44,27 @@ import ch.psi.fda.TestChannels;
|
||||
*/
|
||||
public class ChannelAccessStringSensorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessStringSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT+".NAME";
|
||||
private static final String actualValue = TestChannels.ANALOG_OUT;
|
||||
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}.
|
||||
* @throws CAException
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException {
|
||||
ChannelAccessStringSensor sensor = new ChannelAccessStringSensor("id0", channelName);
|
||||
public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException {
|
||||
Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, channelName));
|
||||
ChannelAccessStringSensor sensor = new ChannelAccessStringSensor("id0", channel);
|
||||
|
||||
// Get sensor readout value
|
||||
String value = (String) sensor.read();
|
||||
|
||||
@@ -22,6 +22,8 @@ package ch.psi.fda.core.sensors;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
@@ -34,8 +36,11 @@ import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.fda.core.sensors.ComplexSensor;
|
||||
import ch.psi.jcae.ChannelBean;
|
||||
import ch.psi.jcae.ChannelBeanFactory;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
@@ -48,31 +53,31 @@ public class ComplexSensorTest {
|
||||
private static Logger logger = Logger.getLogger(ComplexSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}.
|
||||
* @throws CAException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException {
|
||||
public void testRead() throws CAException, InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
|
||||
final HashMap<String, Long> timestamps = new HashMap<String,Long>();
|
||||
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", channelName);
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", channel);
|
||||
ComplexSensor sensor = new ComplexSensor("id2", s1);
|
||||
|
||||
// Add pre action
|
||||
@@ -111,9 +116,6 @@ public class ComplexSensorTest {
|
||||
}
|
||||
});
|
||||
|
||||
// Create channel bean for test sensor channel
|
||||
ChannelBean<Double> channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false);
|
||||
|
||||
// Prepare sensor channel
|
||||
Double setValue = 0.1d;
|
||||
channel.setValue(setValue);
|
||||
|
||||
Reference in New Issue
Block a user