From 93cd7668b69522f58825ca9afe7ab278530a3910 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 23 Jul 2013 13:41:52 +0200 Subject: [PATCH 01/12] Starting with 2.0.0 development --- ch.psi.fda/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index f24b3ec..a2e65bc 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -3,7 +3,7 @@ 4.0.0 ch.psi fda - 1.1.38 + 2.0.0 From 1d05d36b5c9ee49a45d93a0591c5019f53c26fa5 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Thu, 25 Jul 2013 08:22:24 +0200 Subject: [PATCH 02/12] Moved to newest jcae --- ch.psi.fda/.classpath | 6 +- .../.settings/org.eclipse.jdt.core.prefs | 6 +- ch.psi.fda/pom.xml | 24 +- .../main/java/ch/psi/fda/aq/Acquisition.java | 97 ++--- .../core/actions/ChannelAccessCondition.java | 151 ++++---- .../actions/ChannelAccessConditionAnd.java | 24 +- .../actions/ChannelAccessConditionOr.java | 24 +- .../actions/ChannelAccessConditionRegex.java | 24 +- .../fda/core/actions/ChannelAccessPut.java | 30 +- .../ch/psi/fda/core/actions/JythonAction.java | 17 +- .../actors/ChannelAccessFunctionActuator.java | 39 +- .../actors/ChannelAccessLinearActuator.java | 35 +- .../actors/ChannelAccessTableActuator.java | 39 +- .../fda/core/guard/ChannelAccessGuard.java | 7 +- .../guard/ChannelAccessGuardCondition.java | 20 +- .../java/ch/psi/fda/core/loops/OTFBean.java | 359 ++++++++++-------- .../java/ch/psi/fda/core/loops/OTFLoop.java | 34 +- .../loops/cr/CrlogicChannelsTemplate.java | 56 +-- .../ch/psi/fda/core/loops/cr/CrlogicLoop.java | 40 +- .../loops/cr/EncoderChannelsTemplate.java | 20 +- .../core/loops/cr/MotorChannelsTemplate.java | 272 ++++++------- .../psi/fda/core/loops/cr/ScrlogicLoop.java | 96 ++--- .../loops/cr/VSC16ScalerChannelsTemplate.java | 32 +- .../core/manipulator/JythonManipulation.java | 23 +- .../ChannelAccessDoubleArraySensor.java | 24 +- .../sensors/ChannelAccessDoubleSensor.java | 23 +- .../sensors/ChannelAccessStringSensor.java | 27 +- .../actions/ChannelAccessConditionTest.java | 64 ++-- .../core/actions/ChannelAccessPutTest.java | 43 ++- .../fda/core/actions/JythonActionTest.java | 10 +- .../ChannelAccessFunctionActuatorTest.java | 123 +++--- .../ChannelAccessLinearActuatorTest.java | 121 +++--- .../ChannelAccessTableActuatorTest.java | 93 +++-- .../psi/fda/core/actors/ComplexActorTest.java | 10 +- .../core/guard/ChannelAccessGuardTest.java | 22 +- .../fda/core/loops/ActorSensorLoopTest.java | 51 +-- .../ch/psi/fda/core/loops/OTFLoopTest.java | 36 +- .../core/loops/cr/ParallelCrlogicTest.java | 35 +- .../fda/core/loops/cr/ScrlogicLoopTest.java | 20 +- .../fda/core/manipulator/ManipulatorTest.java | 39 +- .../ChannelAccessDoubleArraySensorTest.java | 17 +- .../ChannelAccessDoubleSensorTest.java | 17 +- .../ChannelAccessStringSensorTest.java | 3 +- .../fda/core/sensors/ComplexSensorTest.java | 17 +- 44 files changed, 1299 insertions(+), 971 deletions(-) diff --git a/ch.psi.fda/.classpath b/ch.psi.fda/.classpath index 3865a70..a37deec 100644 --- a/ch.psi.fda/.classpath +++ b/ch.psi.fda/.classpath @@ -28,6 +28,10 @@ - + + + + + diff --git a/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs b/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs index 60105c1..ec4300d 100644 --- a/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs +++ b/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index a2e65bc..c4259a2 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -9,7 +9,7 @@ ch.psi jcae - 1.0.30 + 2.1.8 @@ -58,12 +58,24 @@ freehep-xdr 2.0.4 - + + com.google.inject + guice + 3.0 + + + + com.google.guava + guava + 14.0.1 + + + + test junit junit - 4.8.2 - test + 4.11 @@ -73,8 +85,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java index 4e78ad1..6a1ef4e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java @@ -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; @@ -118,7 +116,8 @@ 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.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; /** * Data acquisition engine for performing scans @@ -146,6 +145,8 @@ public class Acquisition { private Handler logHandler = null; + private ChannelService cservice; + /** * Name of the datafile */ @@ -181,7 +182,9 @@ public class Acquisition { * @throws InterruptedException */ public DataQueue initalize(Configuration smodel, boolean getQueue) { - + + cservice = new DefaultChannelService(); + // Create notification agent with globally configured recipients notificationAgent = new NotificationAgent(configuration.getSmptServer(), "fda.notification@psi.ch"); @@ -367,11 +370,9 @@ public class Acquisition { // Destroy the CA context try { logger.fine("Destroy Channel Access context"); - ChannelBeanFactory.getFactory().getChannelFactory().destroyContext(); + cservice.destroy(); } 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"); @@ -509,7 +510,7 @@ public class Acquisition { } } - JythonManipulation manipulation = new JythonManipulation(sm.getId(), sm.getScript(), mapping, sm.isReturnArray()); + JythonManipulation manipulation = new JythonManipulation(cservice, sm.getId(), sm.getScript(), mapping, sm.isReturnArray()); this.manipulations.add(manipulation); } } @@ -535,24 +536,24 @@ public class Acquisition { timeout = Math.round(ca.getTimeout()*1000); } if(type.equals("String")){ - alist.add(new ChannelAccessPut(ca.getChannel(), ca.getValue(), false, timeout)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), false, timeout)); } else if(type.equals("Integer")){ - alist.add(new ChannelAccessPut(ca.getChannel(), new Integer(ca.getValue()), false, timeout)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), false, timeout)); } else if(type.equals("Double")){ - alist.add(new ChannelAccessPut(ca.getChannel(), new Double(ca.getValue()), false, timeout)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), false, timeout)); } } else if(operation.equals("putq")){ if(type.equals("String")){ - alist.add(new ChannelAccessPut(ca.getChannel(), ca.getValue(), true, null)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), true, null)); } else if(type.equals("Integer")){ - alist.add(new ChannelAccessPut(ca.getChannel(), new Integer(ca.getValue()), true, null)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), true, null)); } else if(type.equals("Double")){ - alist.add(new ChannelAccessPut(ca.getChannel(), new Double(ca.getValue()), true, null)); + alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), true, null)); } } else if(operation.equals("wait")){ @@ -561,13 +562,13 @@ public class Acquisition { timeout = Math.round(ca.getTimeout()*1000); } if(type.equals("String")){ - alist.add(new ChannelAccessCondition(ca.getChannel(), ca.getValue(), timeout)); + alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), ca.getValue(), timeout)); } else if(type.equals("Integer")){ - alist.add(new ChannelAccessCondition(ca.getChannel(), new Integer(ca.getValue()), timeout)); + alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); } else if(type.equals("Double")){ - alist.add(new ChannelAccessCondition(ca.getChannel(), new Double(ca.getValue()), timeout)); + alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Double(ca.getValue()), timeout)); } } else if(operation.equals("waitREGEX")){ @@ -576,7 +577,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(cservice, ca.getChannel(), ca.getValue(), timeout)); } else{ logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); @@ -589,7 +590,7 @@ public class Acquisition { } if(type.equals("Integer")){ - alist.add(new ChannelAccessConditionOr(ca.getChannel(), new Integer(ca.getValue()), timeout)); + alist.add(new ChannelAccessConditionOr(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); } else{ logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); @@ -601,7 +602,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(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); } else { logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); @@ -645,7 +646,7 @@ public class Acquisition { logger.warning("Channel type ["+ma.getType()+"] is not supported for mapping"); } } - alist.add(new ch.psi.fda.core.actions.JythonAction(sa.getScript(), mapping)); + alist.add(new ch.psi.fda.core.actions.JythonAction(cservice, sa.getScript(), mapping)); } } return(alist); @@ -678,14 +679,14 @@ public class Acquisition { LinearPositioner lp =(LinearPositioner) p; ChannelAccessLinearActuator a; if(lp.getType().equals("String")){ - a = new ChannelAccessLinearActuator(lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } else if(lp.getType().equals("Double")){ - a = new ChannelAccessLinearActuator(lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } else{ // Default - a = new ChannelAccessLinearActuator(lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } a.setAsynchronous(lp.isAsynchronous()); @@ -698,7 +699,7 @@ public class Acquisition { if(name==null){ name = lp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), name); + ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); aLoop.getSensors().add(sensor); } else if(p instanceof FunctionPositioner){ @@ -711,14 +712,14 @@ public class Acquisition { // Create actuator ChannelAccessFunctionActuator a; if(lp.getType().equals("String")){ - a = new ChannelAccessFunctionActuator(lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } else if(lp.getType().equals("Double")){ - a = new ChannelAccessFunctionActuator(lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } else{ // Default - a = new ChannelAccessFunctionActuator(lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); + a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); } a.setAsynchronous(lp.isAsynchronous()); @@ -731,7 +732,7 @@ public class Acquisition { if(name==null){ name = lp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), name); + ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); aLoop.getSensors().add(sensor); } else if (p instanceof ArrayPositioner){ @@ -744,14 +745,14 @@ public class Acquisition { ChannelAccessTableActuator a; if(p.getType().equals("String")){ - a = new ChannelAccessTableActuator(p.getName(), p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); + a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); } else if(p.getType().equals("Double")){ - a = new ChannelAccessTableActuator(p.getName(), p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); + a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); } else{ // Default - a = new ChannelAccessTableActuator(p.getName(), p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); + a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); } a.setAsynchronous(p.isAsynchronous()); @@ -764,7 +765,7 @@ public class Acquisition { if(name==null){ name = ap.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(ap.getId(), name); + ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, ap.getId(), name); aLoop.getSensors().add(sensor); } else if (p instanceof RegionPositioner){ @@ -797,14 +798,14 @@ public class Acquisition { // Create actuator ChannelAccessLinearActuator act; if(rp.getType().equals("String")){ - act = new ChannelAccessLinearActuator(rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); } else if(rp.getType().equals("Double")){ - act = new ChannelAccessLinearActuator(rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); } else{ // Default - act = new ChannelAccessLinearActuator(rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); } act.setAsynchronous(rp.isAsynchronous()); @@ -825,14 +826,14 @@ public class Acquisition { JythonFunction function = mapFunction(r.getFunction()); ChannelAccessFunctionActuator act; if(rp.getType().equals("String")){ - act = new ChannelAccessFunctionActuator(rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); } else if(rp.getType().equals("Double")){ - act = new ChannelAccessFunctionActuator(rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); } else{ // Default - act = new ChannelAccessFunctionActuator(rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); + act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), r.getStepSize(), moveTimeout); } act.setAsynchronous(rp.isAsynchronous()); @@ -852,7 +853,7 @@ public class Acquisition { if(name==null){ name = rp.getName(); } - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(rp.getId(), name); + ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, rp.getId(), name); aLoop.getSensors().add(sensor); } else if(p instanceof PseudoPositioner){ @@ -899,7 +900,7 @@ public class Acquisition { value = con.getValue(); } - conditions.add(new ChannelAccessGuardCondition(con.getChannel(), value)); + conditions.add(new ChannelAccessGuardCondition(cservice, con.getChannel(), value)); } // Create guard and add to loop ChannelAccessGuard guard = new ChannelAccessGuard(conditions); @@ -950,10 +951,10 @@ public class Acquisition { // Add sensor Sensor sensor; if(sd.getType().equals("String")){ - sensor = new ChannelAccessStringSensor(sd.getId(), sd.getName()); + sensor = new ChannelAccessStringSensor(cservice, sd.getId(), sd.getName()); } else{ - sensor = new ChannelAccessDoubleSensor(sd.getId(), sd.getName()); + sensor = new ChannelAccessDoubleSensor(cservice, sd.getId(), sd.getName()); } aLoop.getSensors().add(sensor); @@ -965,7 +966,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(cservice, ad.getId(), ad.getName(), ad.getArraySize()); aLoop.getSensors().add(sensor); } else if (detector instanceof DetectorOfDetectors){ @@ -1008,7 +1009,7 @@ 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); + OTFLoop actionLoop = new OTFLoop(cservice, configuration.getOtfChannelPrefix(), configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag); actionLoop.getPreActions().addAll(mapActions(dimension.getPreAction())); @@ -1067,7 +1068,7 @@ 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); + CrlogicLoop actionLoop = new CrlogicLoop(cservice, configuration.getOtfCrlogicPrefix(), configuration.getOtfNfsServer(), configuration.getOtfNfsShare(), configuration.getOtfSmbShare(), zigZag); actionLoop.setKeepTmpFiles(configuration.isOtfCrlogicKeepTmpFiles()); actionLoop.getPreActions().addAll(mapActions(dimension.getPreAction())); @@ -1113,11 +1114,11 @@ public class Acquisition { List sensors = new ArrayList(); for(SimpleScalarDetector detector: dimension.getDetector()){ if(detector.isScr()){ - sensors.add(new ChannelAccessDoubleSensor(detector.getId(), detector.getName())); + sensors.add(new ChannelAccessDoubleSensor(cservice, detector.getId(), detector.getName())); } } // Create soft(ware) based crlogic - ScrlogicLoop scrlogic = new ScrlogicLoop(sensors); + ScrlogicLoop scrlogic = new ScrlogicLoop(cservice, sensors); // Create parallel logic ParallelCrlogic pcrlogic = new ParallelCrlogic(actionLoop, scrlogic); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessCondition.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessCondition.java index f56d416..0b3333a 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessCondition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessCondition.java @@ -2,15 +2,15 @@ * * Copyright 2010 Paul Scherrer Institute. All rights reserved. * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * This code is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. See the - * GNU Lesser General Public License for more details. + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. * * You should have received a copy of the GNU Lesser General Public License * along with this code. If not, see . @@ -19,124 +19,145 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** - * Perform a put on the specified Channel Access channel. The put can be done synchronous or - * asynchronously. + * Perform a put on the specified Channel Access channel. The put can be done + * synchronous or asynchronously. + * * @author ebner - * + * */ public class ChannelAccessCondition implements Action { // Get Logger private static Logger logger = Logger.getLogger(ChannelAccessCondition.class.getName()); - + /** * Channel to set */ - private final ChannelBean channel; + private final Channel channel; /** * Value to wait for */ private final E expectedValue; - - private final Long timeout; - + + private Long timeout; + private volatile boolean abort = false; private volatile Thread waitT = null; - + /** * Constructor - * @param channelName Name of the channel to set the value - * @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 + * @param channelName + * Name of the channel to set the value + * @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 */ @SuppressWarnings("unchecked") - public ChannelAccessCondition(String channelName, E expectedValue, Long timeout){ + public ChannelAccessCondition(ChannelService s, String channelName, 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) ChannelBeanFactory.getFactory().createChannelBean( (Class) expectedValue.getClass(), channelName, false); - } catch (CAException e) { - // Convert Exception into unchecked RuntimeException - throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); + this.channel = (Channel) s.createChannel(new ChannelDescriptor<>(expectedValue.getClass(), channelName, false)); + } catch (ChannelException | TimeoutException e) { + 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); + throw new RuntimeException("Unable to initialize actuator channel [name:" + channelName + "]", e); } - + this.expectedValue = expectedValue; - - if(timeout==null){ - this.timeout = channel.getWaitTimeout(); - } - else{ + + if (timeout == null) { + // this.timeout = channel.get.getWaitTimeout(); + this.timeout=1L; + } else { this.timeout = timeout; } } - - /* (non-Javadoc) + /* + * (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) + * @throws InterruptedException + * @throws RuntimeException + * Channel value did not reach expected value (within the + * specified timeout period) */ @Override public void execute() throws InterruptedException { - abort=false; - logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" ); - try{ + abort = false; + 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){ + channel.waitForValueAsync(expectedValue).get(timeout, TimeUnit.MILLISECONDS); // Workaround use + // 10seconds default + // set timeout to + // check several + // times whether the + // channel has + // reached the value + } catch (InterruptedException e) { + if (!abort) { throw e; } - } - finally{ - waitT=null; + } catch (ExecutionException | TimeoutException | ChannelException e) { + throw new RuntimeException("Channel [name:" + channel.getName() + "] did not reach expected value " + expectedValue + " ", e); + } finally { + waitT = null; } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see ch.psi.fda.core.Action#abort() */ @Override public void abort() { - abort=true; - if(waitT!=null){ + abort = true; + if (waitT != null) { waitT.interrupt(); } } - - /* (non-Javadoc) + /* + * (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); - } + logger.finest("Destroy action channel: " + channel.getName()); + try { + channel.destroy(); + } catch (ChannelException e) { + throw new RuntimeException("Unable to destroy channel [" + channel.getName() + "]", e); + } } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionAnd.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionAnd.java index 3c52821..9a18895 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionAnd.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionAnd.java @@ -20,12 +20,15 @@ package ch.psi.fda.core.actions; import java.util.Comparator; +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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Perform a put on the specified Channel Access channel. The put can be done synchronous or @@ -41,7 +44,7 @@ public class ChannelAccessConditionAnd implements Action { /** * Channel to set */ - private final ChannelBean channel; + private final Channel channel; /** * Value to wait for */ @@ -62,15 +65,15 @@ public class ChannelAccessConditionAnd implements Action { * Timeout specified is not >=0 */ @SuppressWarnings("unchecked") - public ChannelAccessConditionAnd(String channelName, E expectedValue, Long timeout){ + public ChannelAccessConditionAnd(ChannelService s, String channelName, E expectedValue, Long timeout){ if(timeout !=null && timeout<=0){ throw new IllegalArgumentException("Timeout must be > 0"); } try { - this.channel = (ChannelBean) ChannelBeanFactory.getFactory().createChannelBean( (Class) expectedValue.getClass(), channelName, false); - } catch (CAException e) { + this.channel = s.createChannel(new ChannelDescriptor<>( (Class) expectedValue.getClass(), channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -80,7 +83,8 @@ public class ChannelAccessConditionAnd implements Action { this.expectedValue = expectedValue; if(timeout==null){ - this.timeout = channel.getWaitTimeout(); +// this.timeout = channel.getWaitTimeout(); + this.timeout = 0L; } else{ this.timeout = timeout; @@ -114,7 +118,7 @@ public class ChannelAccessConditionAnd implements Action { } } , timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value - } catch (CAException e) { + } catch (ChannelException | ExecutionException e) { throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e); } catch(InterruptedException e){ if(!abort){ @@ -147,7 +151,7 @@ public class ChannelAccessConditionAnd implements Action { try { logger.finest("Destroy action channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionOr.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionOr.java index b4ca64b..042a314 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionOr.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionOr.java @@ -20,12 +20,15 @@ package ch.psi.fda.core.actions; import java.util.Comparator; +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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Perform a put on the specified Channel Access channel. The put can be done synchronous or @@ -41,7 +44,7 @@ public class ChannelAccessConditionOr implements Action { /** * Channel to set */ - private final ChannelBean channel; + private final Channel channel; /** * Value to wait for */ @@ -62,15 +65,15 @@ public class ChannelAccessConditionOr implements Action { * Timeout specified is not >=0 */ @SuppressWarnings("unchecked") - public ChannelAccessConditionOr(String channelName, E expectedValue, Long timeout){ + public ChannelAccessConditionOr(ChannelService s, String channelName, E expectedValue, Long timeout){ if(timeout !=null && timeout<=0){ throw new IllegalArgumentException("Timeout must be > 0"); } try { - this.channel = (ChannelBean) ChannelBeanFactory.getFactory().createChannelBean( (Class) expectedValue.getClass(), channelName, false); - } catch (CAException e) { + this.channel = s.createChannel(new ChannelDescriptor<>( (Class) expectedValue.getClass(), channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -80,7 +83,8 @@ public class ChannelAccessConditionOr implements Action { this.expectedValue = expectedValue; if(timeout==null){ - this.timeout = channel.getWaitTimeout(); +// this.timeout = channel.getWaitTimeout(); + this.timeout = 0L; } else{ this.timeout = timeout; @@ -114,7 +118,7 @@ public class ChannelAccessConditionOr implements Action { } } , timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value - } catch (CAException e) { + } catch (ChannelException | ExecutionException e) { throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e); } catch(InterruptedException e){ if(!abort){ @@ -147,7 +151,7 @@ public class ChannelAccessConditionOr implements Action { try { logger.finest("Destroy action channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionRegex.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionRegex.java index a904ab4..ca16148 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionRegex.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessConditionRegex.java @@ -20,12 +20,15 @@ package ch.psi.fda.core.actions; import java.util.Comparator; +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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Perform a put on the specified Channel Access channel. The put can be done synchronous or @@ -41,7 +44,7 @@ public class ChannelAccessConditionRegex implements Action { /** * Channel to set */ - private final ChannelBean channel; + private final Channel channel; /** * Value to wait for */ @@ -62,15 +65,15 @@ public class ChannelAccessConditionRegex implements Action { * Timeout specified is not >=0 */ @SuppressWarnings("unchecked") - public ChannelAccessConditionRegex(String channelName, E expectedValue, Long timeout){ + public ChannelAccessConditionRegex(ChannelService s, String channelName, E expectedValue, Long timeout){ if(timeout !=null && timeout<=0){ throw new IllegalArgumentException("Timeout must be > 0"); } try { - this.channel = (ChannelBean) ChannelBeanFactory.getFactory().createChannelBean( (Class) expectedValue.getClass(), channelName, false); - } catch (CAException e) { + this.channel = s.createChannel(new ChannelDescriptor<>( (Class) expectedValue.getClass(), channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -80,7 +83,8 @@ public class ChannelAccessConditionRegex implements Action { this.expectedValue = expectedValue; if(timeout==null){ - this.timeout = channel.getWaitTimeout(); +// this.timeout = channel.getWaitTimeout(); + this.timeout = 0L; } else{ this.timeout = timeout; @@ -108,7 +112,7 @@ public class ChannelAccessConditionRegex implements Action { return o1.matches(o2) ? 0:1; } }, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value - } catch (CAException e) { + } catch (ChannelException | ExecutionException e) { throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e); } catch(InterruptedException e){ if(!abort){ @@ -141,7 +145,7 @@ public class ChannelAccessConditionRegex implements Action { try { logger.finest("Destroy action channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java index fec10df..809b4c0 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java @@ -19,12 +19,16 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Perform a put on the specified Channel Access channel. The put can be done synchronous or @@ -40,7 +44,7 @@ public class ChannelAccessPut implements Action { /** * Channel to set */ - private final ChannelBean channel; + private final Channel channel; /** * Value to set */ @@ -62,11 +66,11 @@ public class ChannelAccessPut implements Action { * @throws IllegalArgumentException Unable to initialize channel */ @SuppressWarnings("unchecked") - public ChannelAccessPut(String channelName, E value, boolean asynchronous, Long timeout){ + public ChannelAccessPut(ChannelService s, String channelName, E value, boolean asynchronous, Long timeout){ try { - this.channel = ChannelBeanFactory.getFactory().createChannelBean((Class)value.getClass(), channelName, false); - } catch (CAException e) { + this.channel = s.createChannel(new ChannelDescriptor<>((Class)value.getClass(), channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -85,8 +89,8 @@ public class ChannelAccessPut implements Action { * * @throws RuntimeException Unable to initialize channel */ - public ChannelAccessPut(String channelName, E value){ - this(channelName, value, false, null); + public ChannelAccessPut(ChannelService s, String channelName, E value){ + this(s, channelName, value, false, null); } /* (non-Javadoc) @@ -101,17 +105,17 @@ public class ChannelAccessPut implements Action { logger.finest("Put to channel: "+channel.getName()+ " asynchronous: "+asynchronous); try{ if(asynchronous){ - channel.setValueNoWait(value); + channel.setValueAsync(value); } else{ if(timeout==null){ channel.setValue(value); } else{ - channel.setValue(value, timeout); + channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS); } } - } catch (CAException e) { + } catch (ChannelException | ExecutionException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new RuntimeException("Unable to set channel [name:"+channel.getName()+"] to value "+value, e); } @@ -134,7 +138,7 @@ public class ChannelAccessPut implements Action { try { logger.finest("Destroy action channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/JythonAction.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/JythonAction.java index 9eecdba..638878e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/JythonAction.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/JythonAction.java @@ -19,9 +19,8 @@ package ch.psi.fda.core.actions; -import gov.aps.jca.CAException; - import java.util.List; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,8 +32,10 @@ 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; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * @author ebner @@ -61,7 +62,7 @@ public class JythonAction implements Action { */ private String jythonCall; - public JythonAction(String script, List mapping){ + public JythonAction(ChannelService s, String script, List mapping){ // Workaround for Jython memory leak // http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/ @@ -116,10 +117,10 @@ public class JythonAction implements Action { for(JythonParameterMappingChannel b: mapping){ // Create channel - ChannelBean cb; + Channel cb; try { - cb = ChannelBeanFactory.getFactory().createChannelBean(b.getType(), b.getChannel(), true); - } catch (CAException e) { + cb = s.createChannel(new ChannelDescriptor<>(b.getType(), b.getChannel(), true)); + } catch (TimeoutException | ChannelException e) { throw new IllegalArgumentException("Unable to establish channel: "+b.getChannel(), e); } catch (InterruptedException e) { throw new RuntimeException("Unable to establish channel: "+b.getChannel(), e); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java index 478da04..719492c 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java @@ -19,14 +19,17 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * This actuator sets an Channel Access channel from a start to an end value by doing discrete steps. @@ -86,12 +89,12 @@ public class ChannelAccessFunctionActuator implements Actor { /** * Channel Access channel of the actuator */ - private ChannelBean channel; + private Channel channel; /** * Channel Access channel of the actuator */ - private ChannelBean doneChannel = null; + private Channel doneChannel = null; private final T doneValue; private final long doneDelay; @@ -116,8 +119,8 @@ public class ChannelAccessFunctionActuator 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(ChannelService s, String channelName, Function function, double start, double end, double stepSize, Long timeout){ + this(s, channelName, null, null, 0, function, start, end, stepSize, timeout); } /** @@ -132,7 +135,7 @@ public class ChannelAccessFunctionActuator implements Actor { * @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(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, Function function, double start, double end, double stepSize, Long timeout){ this.doneValue = doneValue; this.doneDelay = (long) Math.floor((doneDelay*1000)); @@ -170,8 +173,8 @@ public class ChannelAccessFunctionActuator implements Actor { // Initialize/create Channel Access channel try { - channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); - } catch (CAException e) { + channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -179,8 +182,8 @@ public class ChannelAccessFunctionActuator implements Actor { } if(doneChannelName != null){ try { - doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class)doneValue.getClass(), doneChannelName, false); - } catch (CAException e) { + doneChannel = s.createChannel(new ChannelDescriptor<>((Class)doneValue.getClass(), doneChannelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e); } catch (InterruptedException e) { @@ -210,11 +213,11 @@ public class ChannelAccessFunctionActuator implements Actor { channel.setValue(fvalue); } else{ - channel.setValue(fvalue, timeout); + channel.setValueAsync(fvalue).get(timeout, TimeUnit.MILLISECONDS); } } else{ - channel.setValueNoWait(fvalue); + channel.setValueAsync(fvalue); } if(doneChannel != null){ @@ -231,7 +234,7 @@ public class ChannelAccessFunctionActuator implements Actor { } } - } catch (CAException e) { + } catch (ChannelException | ExecutionException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e); } @@ -318,7 +321,7 @@ public class ChannelAccessFunctionActuator implements Actor { try { logger.finest("Destroy actor channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } @@ -327,7 +330,7 @@ public class ChannelAccessFunctionActuator implements Actor { try { logger.finest("Destroy actor done channel: "+doneChannel.getName()); doneChannel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java index 7279eca..ea42a55 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java @@ -19,14 +19,17 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * This actuator sets an Channel Access channel from a start to an end value by doing discrete steps. @@ -86,12 +89,12 @@ public class ChannelAccessLinearActuator implements Actor { /** * Channel Access channel of the actuator */ - private ChannelBean channel; + private Channel channel; /** * Channel Access channel of the actuator */ - private ChannelBean doneChannel = null; + private Channel doneChannel = null; private final T doneValue; private final long doneDelay; @@ -119,7 +122,7 @@ public class ChannelAccessLinearActuator implements Actor { * @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(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, double start, double end, double stepSize, Long timeout){ this.doneValue = doneValue; this.doneDelay = (long) Math.floor((doneDelay*1000)); @@ -152,8 +155,8 @@ public class ChannelAccessLinearActuator implements Actor { // Initialize/create Channel Access channel try { - channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); - } catch (CAException e) { + channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -161,8 +164,8 @@ public class ChannelAccessLinearActuator implements Actor { } if(doneChannelName != null){ try { - doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class) doneValue.getClass(), doneChannelName, false); - } catch (CAException e) { + doneChannel = s.createChannel(new ChannelDescriptor<>((Class) doneValue.getClass(), doneChannelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e); } catch (InterruptedException e) { @@ -191,11 +194,11 @@ public class ChannelAccessLinearActuator implements Actor { channel.setValue(value); } else{ - channel.setValue(value, timeout); + channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS); } } else{ - channel.setValueNoWait(value); + channel.setValueAsync(value); } if(doneChannel != null){ @@ -212,7 +215,7 @@ public class ChannelAccessLinearActuator implements Actor { } } - } catch (CAException e) { + } catch (ChannelException | TimeoutException | ExecutionException e) { // Convert Exception into unchecked RuntimeException throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e); } @@ -295,7 +298,7 @@ public class ChannelAccessLinearActuator implements Actor { try { logger.finest("Destroy actor channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } @@ -304,7 +307,7 @@ public class ChannelAccessLinearActuator implements Actor { try { logger.finest("Destroy actor done channel: "+doneChannel.getName()); doneChannel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java index 60eb4fe..2d849d4 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java @@ -19,14 +19,17 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * This actuator sets an Channel Access channel by using the positions from the given table. @@ -66,12 +69,12 @@ public class ChannelAccessTableActuator implements Actor { /** * Channel Access channel of the actuator */ - private ChannelBean channel; + private Channel channel; /** * Channel Access channel of the actuator */ - private ChannelBean doneChannel = null; + private Channel doneChannel = null; private final T doneValue; private final long doneDelay; @@ -94,8 +97,8 @@ public class ChannelAccessTableActuator 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(ChannelService s, String channelName, double[] table, Long timeout){ + this(s, channelName, null, null, 0, table, timeout); } /** @@ -108,7 +111,7 @@ public class ChannelAccessTableActuator implements Actor { * @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(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, double[] table, Long timeout){ this.doneValue = doneValue; this.doneDelay = (long) Math.floor((doneDelay*1000)); @@ -137,8 +140,8 @@ public class ChannelAccessTableActuator implements Actor { // Initialize/create Channel Access channel try { - channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); - } catch (CAException e) { + channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -147,8 +150,8 @@ public class ChannelAccessTableActuator implements Actor { if(doneChannelName != null){ try { - doneChannel = ChannelBeanFactory.getFactory().createChannelBean((Class)doneValue.getClass(), doneChannelName, false); - } catch (CAException e) { + doneChannel = s.createChannel(new ChannelDescriptor<>((Class)doneValue.getClass(), doneChannelName, false)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e); } catch (InterruptedException e) { @@ -176,11 +179,11 @@ public class ChannelAccessTableActuator implements Actor { channel.setValue(table[count]); } else{ - channel.setValue(table[count], timeout); + channel.setValueAsync(table[count]).get(timeout, TimeUnit.MILLISECONDS); } } else{ - channel.setValueNoWait(table[count]); + channel.setValueAsync(table[count]); } @@ -196,7 +199,7 @@ public class ChannelAccessTableActuator implements Actor { } } - } catch (CAException e) { + } catch (ChannelException | ExecutionException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new RuntimeException("Move actuator [channel: "+channel.getName()+"] to value "+table[count],e); } @@ -280,7 +283,7 @@ public class ChannelAccessTableActuator implements Actor { try { logger.finest("Destroy actor channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } @@ -289,7 +292,7 @@ public class ChannelAccessTableActuator implements Actor { try { logger.finest("Destroy actor done channel: "+doneChannel.getName()); doneChannel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java index 84144f7..c3e7f12 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuard.java @@ -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 @@ -85,7 +86,7 @@ public class ChannelAccessGuard implements Guard { break; } } - catch(CAException e){ + catch(ChannelException | TimeoutException | ExecutionException e){ logger.log(Level.WARNING, "Unable ", e); check=false; } catch (InterruptedException e) { diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuardCondition.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuardCondition.java index a844d11..734f019 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuardCondition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/guard/ChannelAccessGuardCondition.java @@ -19,11 +19,13 @@ package ch.psi.fda.core.guard; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; -import gov.aps.jca.CAException; -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; /** * Channel and condition that need to be met. @@ -38,7 +40,7 @@ public class ChannelAccessGuardCondition { /** * Channel name */ - private final ChannelBean channel; + private final Channel channel; /** * Value of the channel to meet condition @@ -50,10 +52,10 @@ public class ChannelAccessGuardCondition { * @param channel Name of the channel that contributes to a guard * @param value */ - public ChannelAccessGuardCondition(String channel, Object value){ + public ChannelAccessGuardCondition(ChannelService s, String channel, Object value){ try { - this.channel = ChannelBeanFactory.getFactory().createChannelBean(value.getClass(), channel, true); - } catch (CAException e) { + this.channel = s.createChannel(new ChannelDescriptor<>(value.getClass(), channel, true)); + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channel+"]",e); } catch (InterruptedException e) { @@ -65,7 +67,7 @@ public class ChannelAccessGuardCondition { /** * @return the channel */ - public ChannelBean getChannel() { + public Channel getChannel() { return channel; } @@ -88,7 +90,7 @@ public class ChannelAccessGuardCondition { try { logger.finest("Destroy guard condition channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java index 7725ba7..9bd99d6 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java @@ -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.Channel; +import ch.psi.jcae.ChannelException; import ch.psi.jcae.annotation.CaChannel; -import ch.psi.jcae.ChannelBean; /** * 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 motor; + @CaChannel(type=String.class, name ="${PREFIX}:UMOT") + private Channel motor; - @CaChannel(type=String.class, name=":MENC") - private ChannelBean encoder; + @CaChannel(type=String.class, name="${PREFIX}:MENC") + private Channel encoder; - @CaChannel(type=Double.class, name=":UBEG") - private ChannelBean begin; + @CaChannel(type=Double.class, name="${PREFIX}:UBEG") + private Channel begin; - @CaChannel(type=Double.class, name=":UBEG.DRVL") - private ChannelBean beginMin; + @CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVL") + private Channel beginMin; - @CaChannel(type=Double.class, name=":UBEG.DRVH") - private ChannelBean beginMax; + @CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVH") + private Channel beginMax; - @CaChannel(type=Double.class, name=":UEND") - private ChannelBean end; + @CaChannel(type=Double.class, name="${PREFIX}:UEND") + private Channel end; - @CaChannel(type=Double.class, name=":UEND.DRVL") - private ChannelBean endMin; + @CaChannel(type=Double.class, name="${PREFIX}:UEND.DRVL") + private Channel endMin; - @CaChannel(type=Double.class, name=":UEND.DRVH") - private ChannelBean endMax; + @CaChannel(type=Double.class, name="${PREFIX}:UEND.DRVH") + private Channel endMax; - @CaChannel(type=Double.class, name=":USSIZ") - private ChannelBean stepSize; + @CaChannel(type=Double.class, name="${PREFIX}:USSIZ") + private Channel stepSize; - @CaChannel(type=Double.class, name=":USSIZ.DRVL") - private ChannelBean stepSizeMin; + @CaChannel(type=Double.class, name="${PREFIX}:USSIZ.DRVL") + private Channel stepSizeMin; - @CaChannel(type=Double.class, name=":UITIM") - private ChannelBean integrationTime; + @CaChannel(type=Double.class, name="${PREFIX}:UITIM") + private Channel integrationTime; - @CaChannel(type=Double.class, name=":UITIM.DRVL") - private ChannelBean integrationTimeMin; + @CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVL") + private Channel integrationTimeMin; - @CaChannel(type=Double.class, name=":UITIM.DRVH") - private ChannelBean integrationTimeMax; + @CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVH") + private Channel integrationTimeMax; - @CaChannel(type=Double.class, name=":UBCL") - private ChannelBean userBacklash; + @CaChannel(type=Double.class, name="${PREFIX}:UBCL") + private Channel userBacklash; - @CaChannel(type=String.class, name=":NFSSE") - private ChannelBean nfsServer; + @CaChannel(type=String.class, name="${PREFIX}:NFSSE") + private Channel nfsServer; - @CaChannel(type=String.class, name=":NFSSH") - private ChannelBean nfsShare; + @CaChannel(type=String.class, name="${PREFIX}:NFSSH") + private Channel nfsShare; - @CaChannel(type=String.class, name=":DFNAM") - private ChannelBean fileName; + @CaChannel(type=String.class, name="${PREFIX}:DFNAM") + private Channel fileName; - @CaChannel(type=String.class, name=":FFORM") - private ChannelBean fileNameFormat; + @CaChannel(type=String.class, name="${PREFIX}:FFORM") + private Channel fileNameFormat; - @CaChannel(type=Integer.class, name=":FCNT") - private ChannelBean fileCount; + @CaChannel(type=Integer.class, name="${PREFIX}:FCNT") + private Channel fileCount; - @CaChannel(type=Integer.class, name=":FCNT.B") - private ChannelBean resetFileCounter; + @CaChannel(type=Integer.class, name="${PREFIX}:FCNT.B") + private Channel resetFileCounter; - @CaChannel(type=Boolean.class, name=":FAPPE") - private ChannelBean appendFile; + @CaChannel(type=Boolean.class, name="${PREFIX}:FAPPE") + private Channel appendFile; - @CaChannel(type=Boolean.class, name=":FUSE") - private ChannelBean fileNameGeneration; + @CaChannel(type=Boolean.class, name="${PREFIX}:FUSE") + private Channel fileNameGeneration; - @CaChannel(type=Boolean.class, name=":UZIGZ") - private ChannelBean zigZag; + @CaChannel(type=Boolean.class, name="${PREFIX}:UZIGZ") + private Channel zigZag; - @CaChannel(type=Integer.class, name=":UCOM") - private ChannelBean command; + @CaChannel(type=Integer.class, name="${PREFIX}:UCOM") + private Channel command; - @CaChannel(type=Boolean.class, name=":SCRU", monitor=true) - private ChannelBean scanRunning; + @CaChannel(type=Boolean.class, name="${PREFIX}:SCRU", monitor=true) + private Channel scanRunning; - @CaChannel(type=Boolean.class, name=":MUENC") - private ChannelBean useEncoder; + @CaChannel(type=Boolean.class, name="${PREFIX}:MUENC") + private Channel useEncoder; - @CaChannel(type=String.class, name={":CTM0",":CTM1",":CTM2",":CTM3",":CTM4",":CTM5",":CTM6",":CTM7"}) - private List> monitoredChannels; + @CaChannel(type=String.class, name={"${PREFIX}:CTM0","${PREFIX}:CTM1","${PREFIX}:CTM2","${PREFIX}:CTM3","${PREFIX}:CTM4","${PREFIX}:CTM5","${PREFIX}:CTM6","${PREFIX}:CTM7"}) + private List> monitoredChannels; - @CaChannel(type=Boolean.class, name=":OTF", monitor=true) - private ChannelBean running; + @CaChannel(type=Boolean.class, name="${PREFIX}:OTF", monitor=true) + private Channel running; - @CaChannel(type=Integer.class, name=":USTAT", monitor=true) - private ChannelBean status; + @CaChannel(type=Integer.class, name="${PREFIX}:USTAT", monitor=true) + private Channel status; - @CaChannel(type=Boolean.class, name=":MOK", monitor=true) - private ChannelBean motorOk; + @CaChannel(type=Boolean.class, name="${PREFIX}:MOK", monitor=true) + private Channel motorOk; - @CaChannel(type=Boolean.class, name=":EOK", monitor=true) - private ChannelBean encoderOk; + @CaChannel(type=Boolean.class, name="${PREFIX}:EOK", monitor=true) + private Channel encoderOk; - @CaChannel(type=String.class, name=":MSG") - private ChannelBean message; + @CaChannel(type=String.class, name="${PREFIX}:MSG") + private Channel message; /** * Get the trigger name that can be used by the sscan record to trigger an OTFScan @@ -174,7 +175,7 @@ public class OTFBean { this.command.setValue(Command.STOP.ordinal()); // Do not wait for put to return - this.running.setValueNoWait(false); + this.running.setValueAsync(false); } catch(Exception e){ throw new RuntimeException("Unable to abort OTF logic" ,e); @@ -210,7 +211,7 @@ public class OTFBean { throw new RuntimeException("OTFSCAN failed with message: "+message.getValue()); } - } catch (CAException e) { + } catch (ChannelException | ExecutionException | 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 (ChannelException | ExecutionException | TimeoutException e) { throw new RuntimeException("An error occurred while waiting for the OTF logic to finish.", e); } @@ -239,10 +240,10 @@ public class OTFBean { /** * Reset OTFScan records to defaults - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException * @throws InterruptedException */ - public void resetToDefaults() throws CAException, InterruptedException{ + public void resetToDefaults() throws ChannelException , ExecutionException , TimeoutException, InterruptedException{ setMonitoredChannels(new String[]{}); setMotor(""); begin.setValue(0d); @@ -267,54 +268,69 @@ public class OTFBean { /** * Get motor of the OTFScan axis * @return Name of the OTF motor - * @throws CAException + * @throws ExecutionException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getMotor() throws CAException, InterruptedException { + public String getMotor() throws ChannelException, InterruptedException, TimeoutException, ExecutionException { return(this.motor.getValue()); } /** * Set motor of the OTFScan axis * @param motor - * @throws CAException + * @throws ChannelException + * @throws ExecutionException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setMotor(String motor) throws CAException, InterruptedException { + public void setMotor(String motor) throws InterruptedException, ExecutionException, ChannelException { this.motor.setValue(motor); } /** * Get encoder of the OTFScan axis * @return Name of the used encoder - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getEncoder() throws CAException, InterruptedException { + public String getEncoder() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.encoder.getValue()); } /** * Set encoder to use of the OTFScan axis * @param encoder - * @throws CAException + * @throws ChannelException + * @throws ExecutionException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setEncoder(String encoder) throws CAException, InterruptedException { + public void setEncoder(String encoder) throws InterruptedException, ExecutionException, ChannelException { this.encoder.setValue(encoder); } /** * Get begin position of the scan * @return Begin position scan - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getBegin() throws CAException, InterruptedException { + public Double getBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.begin.getValue()); } /** * Set begin position of scan * @param begin + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws Exception */ - public void setBegin(Double begin) throws CAException, InterruptedException { + public void setBegin(Double begin) throws InterruptedException, TimeoutException, ChannelException, ExecutionException { if(begin==null){ throw new IllegalArgumentException("Begin position must not be null"); @@ -330,36 +346,48 @@ public class OTFBean { /** * Get minimum value of the begin position * @return Min value for begin - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMinBegin() throws CAException, InterruptedException { + public Double getMinBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.beginMin.getValue()); } /** * Get maximum value of the begin position * @return Max value for begin - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMaxBegin() throws CAException, InterruptedException { + public Double getMaxBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.beginMax.getValue()); } /** * Get end position of the scan * @return End position scan - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getEnd() throws CAException, InterruptedException { + public Double getEnd() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.end.getValue()); } /** * Set end positon of scan * @param end - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setEnd(Double end) throws CAException, InterruptedException { + public void setEnd(Double end) throws InterruptedException, TimeoutException, ChannelException, ExecutionException { if(end==null){ throw new IllegalArgumentException("End position must not be null"); @@ -375,35 +403,38 @@ public class OTFBean { /** * Get minimum value of end position * @return Min value for end - * @throws CAException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMinEnd() throws CAException, InterruptedException { + public Double getMinEnd() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { return(this.endMin.getValue()); } /** * Get maximum value of end position * @return Max value for end - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMaxEnd() throws CAException, InterruptedException { + public Double getMaxEnd() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.endMax.getValue()); } /** * Get scan step size * @return Step size - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getStepSize() throws CAException, InterruptedException { + public Double getStepSize() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.stepSize.getValue()); } /** * Set step size of scan * @param stepSize - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setStepSize(Double stepSize) throws CAException, InterruptedException { + public void setStepSize(Double stepSize) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { if(integrationTime==null){ throw new IllegalArgumentException("Step size must not be null"); @@ -423,27 +454,27 @@ public class OTFBean { /** * Get minimum integration time * @return Min value for step size - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public double getMinStepSize() throws CAException, InterruptedException { + public double getMinStepSize() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.stepSizeMin.getValue()); } /** * Get scan integration time (time that is spend in one step) * @return Integration time - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getIntegrationTime() throws CAException, InterruptedException { + public Double getIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.integrationTime.getValue()); } /** * Set integration time of scan * @param integrationTime - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setIntegrationTime(Double integrationTime) throws CAException, InterruptedException { + public void setIntegrationTime(Double integrationTime) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { if(integrationTime==null){ throw new IllegalArgumentException("Integration time must not be null"); @@ -472,35 +503,35 @@ public class OTFBean { /** * Get minimum integration time * @return Min value for integration time - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMinIntegrationTime() throws CAException, InterruptedException { + public Double getMinIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.integrationTimeMin.getValue()); } /** * Get maximum integration time * @return Max value for integration time - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getMaxIntegrationTime() throws CAException, InterruptedException { + public Double getMaxIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.integrationTimeMax.getValue()); } /** * Get additional user defined backlash * @return User backlash - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Double getUserBacklash() throws CAException, InterruptedException { + public Double getUserBacklash() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.userBacklash.getValue()); } /** * Set additional user defined backlash * @param userBacklash - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setUserBacklash(Double userBacklash) throws CAException, InterruptedException { + public void setUserBacklash(Double userBacklash) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { if(userBacklash==null){ throw new IllegalArgumentException("User backlash must not be null"); } @@ -511,63 +542,63 @@ public class OTFBean { /** * Get the current NFS server the data is written to * @return Name of NFS server - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getNfsServer() throws CAException, InterruptedException { + public String getNfsServer() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.nfsServer.getValue()); } /** * Set name of the NFS server the data is written to * @param nfsServer - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setNfsServer(String nfsServer) throws CAException, InterruptedException { + public void setNfsServer(String nfsServer) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.nfsServer.setValue(nfsServer); } /** * Get the NFS share the data is written to * @return Name of NFS share - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getNfsShare() throws CAException, InterruptedException { + public String getNfsShare() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.nfsShare.getValue()); } /** * Set name of the NFS share the data is written to * @param nfsShare - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setNfsShare(String nfsShare) throws CAException, InterruptedException { + public void setNfsShare(String nfsShare) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.nfsShare.setValue(nfsShare); } /** * Get the name of the data file * @return Name of data file name - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getFileName() throws CAException, InterruptedException { + public String getFileName() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.fileName.getValue()); } /** * Set name of the data file * @param filename - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setFileName(String filename) throws CAException, InterruptedException { + public void setFileName(String filename) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.fileName.setValue(filename); } /** * Get File name formate * @return Get format for file name - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getFileNameFormat() throws CAException, InterruptedException { + public String getFileNameFormat() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.fileNameFormat.getValue()); } @@ -576,102 +607,102 @@ public class OTFBean { * @param fileNameFormat * @throws Exception */ - public void setFileNameFormat(String fileNameFormat) throws CAException, InterruptedException { + public void setFileNameFormat(String fileNameFormat) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.fileNameFormat.setValue(fileNameFormat); } /** * Get value of the IOC based file name counter * @return File counter - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public int getFileCounter() throws CAException, InterruptedException { + public int getFileCounter() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.fileCount.getValue()); } /** * Reset the IOC based file counter - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void resetFileCounter() throws CAException, InterruptedException { + public void resetFileCounter() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.resetFileCounter.setValue(1); } /** * Get if append file option is activated * @return Append file flag - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public boolean isAppendFile() throws CAException, InterruptedException { + public boolean isAppendFile() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.appendFile.getValue()); } /** * Set whether to append the specified file if the file exists * @param append - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setAppendFile(boolean append) throws CAException, InterruptedException { + public void setAppendFile(boolean append) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.appendFile.setValue(append); } /** * Get if file name generation is on or off * @return File name generation flag - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public boolean isFileNameGeneration() throws CAException, InterruptedException { + public boolean isFileNameGeneration() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.fileNameGeneration.getValue()); } /** * Set Whether the file name should be generated out of the file name format and the file counter * @param generation - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setFileNameGeneration(boolean generation) throws CAException, InterruptedException { + public void setFileNameGeneration(boolean generation) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.fileNameGeneration.setValue(generation); } /** * Get if ZigZag scan option is on or off * @return ZigZag flag - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public boolean isZigZag() throws CAException, InterruptedException { + public boolean isZigZag() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.zigZag.getValue()); } /** * Set ZigZag scan mode on/off * @param zigZag ZigZag mode on = true, ZigZag mode off = false - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setZigZag(boolean zigZag) throws CAException, InterruptedException { + public void setZigZag(boolean zigZag) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.zigZag.setValue(zigZag); } /** * Get whether encoder is used */ - public boolean isUseEncoder() throws CAException, InterruptedException { + public boolean isUseEncoder() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(this.useEncoder.getValue()); } /** * Set flag to use encoder - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public void setUseEncoder(boolean flag) throws CAException, InterruptedException { + public void setUseEncoder(boolean flag) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { this.useEncoder.setValue(flag); } /** * Get the channels that are currently monitored by the OTFScan logic * @return Names of the monitored channels - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String[] getMonitoredChannels() throws CAException, InterruptedException { + public String[] getMonitoredChannels() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { String[] values = new String[this.monitoredChannels.size()]; for(int i=0; imonitoredChannels.size()){ throw new IllegalArgumentException("Only up to "+monitoredChannels.size()+" monitored channels are supported by OTF"); @@ -707,36 +738,36 @@ public class OTFBean { /** * Returns whether an scan is running * @return Running flag - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public boolean isRunning() throws CAException, InterruptedException { + public boolean isRunning() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(running.getValue()); } /** * Get status of the scan * @return Status of the scan - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public Status getStatus() throws CAException, InterruptedException { + public Status getStatus() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(Status.values()[this.status.getValue()]); } /** * Get the (error) message from the OTF records * @return Message from OTF C logic - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public String getMessage() throws CAException, InterruptedException { + public String getMessage() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(message.getValue()); } /** * Check whether the specified motor is recognized as ok (i.e. it is registered as OTFScan motor) * @return Flag whether motor is ok - * @throws CAException + * @throws TimeoutException, ChannelException, ExecutionException */ - public boolean isMotorOk() throws CAException, InterruptedException { + public boolean isMotorOk() throws TimeoutException, ChannelException, ExecutionException, InterruptedException { return(motorOk.getValue()); } @@ -744,9 +775,9 @@ public class OTFBean { * Wait until the motor flag goes to ok * @param timeout Timout in milliseconds * - * @throws CAException If motor ok flag does not switch to ok within the specified timeout + * @throws TimeoutException, ChannelException, ExecutionException 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 TimeoutException, ChannelException, ExecutionException, InterruptedException { motorOk.waitForValue(true, timeout); } @@ -754,14 +785,14 @@ public class OTFBean { * Wait until the motor flag goes to not ok * @param timeout Timout in milliseconds * - * @throws CAException If motor ok flag does not switch to ok within the specified timeout + * @throws TimeoutException, ChannelException, ExecutionException 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 TimeoutException, ChannelException, ExecutionException, InterruptedException { motorOk.waitForValue(false, timeout); } - public void waitUntilEncoderOk(long timeout) throws CAException, InterruptedException { + public void waitUntilEncoderOk(long timeout) throws TimeoutException, ChannelException, ExecutionException, InterruptedException { if(!useEncoder.getValue()){ return; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFLoop.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFLoop.java index fb53dc7..987a709 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFLoop.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFLoop.java @@ -24,15 +24,24 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.util.ArrayList; +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.TimeoutException; 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 +56,8 @@ 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; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * ActionLoop that is implementing the OTF Scan logic. @@ -143,6 +153,8 @@ public class OTFLoop implements ActionLoop { */ private volatile boolean abort = false; + private ChannelService cservice; + /** * Constructor * @param channelPrefix Prefix of the OTF related records, e.g. MTEST-HW3-OTF @@ -151,13 +163,15 @@ 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(ChannelService s, String channelPrefix, String server, String share, String smbShare, boolean zigZag){ + cservice = s; // Initialize connection to the OTF records try { this.obean = new OTFBean(); - ChannelBeanFactory.getFactory().createChannelBeans(obean, channelPrefix); - } catch (CAException e) { + Map m = new HashMap<>(); + m.put("PREFIX", channelPrefix); + s.createAnnotatedChannels(obean, m); + } catch (ChannelException | TimeoutException 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); @@ -311,7 +325,7 @@ public class OTFLoop implements ActionLoop { // Set monitored channels obean.setMonitoredChannels(monitoredChannels.toArray(new String[monitoredChannels.size()])); } - catch(CAException e){ + catch(ChannelException | ExecutionException | TimeoutException e){ throw new RuntimeException("Unable to set OTF configuration parameters",e); } catch (InterruptedException e) { throw new RuntimeException("Unable to set OTF configuration parameters",e); @@ -358,10 +372,8 @@ public class OTFLoop implements ActionLoop { 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) { + cservice.destroyAnnotatedChannels(obean); + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channels",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicChannelsTemplate.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicChannelsTemplate.java index 107dec1..f3dd630 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicChannelsTemplate.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicChannelsTemplate.java @@ -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 ticksPerSecond; + @CaChannel(type=Integer.class, name ="${PREFIX}:TPS") + private Channel ticksPerSecond; /** * Status of the OTFSCAN IOC logic */ - @CaChannel(type=String.class, name =":STATUS") - private ChannelBean status; + @CaChannel(type=String.class, name ="${PREFIX}:STATUS") + private Channel status; /** * Message from the OTFSCAN IOC logic */ - @CaChannel(type=String.class, name =":MSG") - private ChannelBean message; + @CaChannel(type=String.class, name ="${PREFIX}:MSG") + private Channel message; /** * IOC ticks between data acquisition interrupts */ - @CaChannel(type=Integer.class, name =":TBINT") - private ChannelBean ticksBetweenInterrupts; + @CaChannel(type=Integer.class, name ="${PREFIX}:TBINT") + private Channel 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 nfsServer; + @CaChannel(type=String.class, name ="${PREFIX}:NFSSE") + private Channel nfsServer; /** * Name of the NFS share on the NFS server */ - @CaChannel(type=String.class, name =":NFSSH") - private ChannelBean nfsShare; + @CaChannel(type=String.class, name ="${PREFIX}:NFSSH") + private Channel nfsShare; /** * Name of the data file */ - @CaChannel(type=String.class, name =":DFNAM") - private ChannelBean dataFile; + @CaChannel(type=String.class, name ="${PREFIX}:DFNAM") + private Channel dataFile; /** * Flag to identify whether the data file should be appended */ - @CaChannel(type=Boolean.class, name =":FAPPE") - private ChannelBean appendFile; + @CaChannel(type=Boolean.class, name ="${PREFIX}:FAPPE") + private Channel appendFile; /** * Readout resources */ - @CaChannel(type=String[].class, name =":RRES") - private ChannelBean readoutResources; + @CaChannel(type=String[].class, name ="${PREFIX}:RRES") + private Channel readoutResources; /** * @return the ticksPerSecond */ - public ChannelBean getTicksPerSecond() { + public Channel getTicksPerSecond() { return ticksPerSecond; } /** * @return the status */ - public ChannelBean getStatus() { + public Channel getStatus() { return status; } /** * @return the message */ - public ChannelBean getMessage() { + public Channel getMessage() { return message; } /** * @return the ticksBetweenInterrupts */ - public ChannelBean getTicksBetweenInterrupts() { + public Channel getTicksBetweenInterrupts() { return ticksBetweenInterrupts; } /** * @return the nfsServer */ - public ChannelBean getNfsServer() { + public Channel getNfsServer() { return nfsServer; } /** * @return the nfsShare */ - public ChannelBean getNfsShare() { + public Channel getNfsShare() { return nfsShare; } /** * @return the dataFile */ - public ChannelBean getDataFile() { + public Channel getDataFile() { return dataFile; } /** * @return the appendFile */ - public ChannelBean getAppendFile() { + public Channel getAppendFile() { return appendFile; } /** * @return the readoutResources */ - public ChannelBean getReadoutResources() { + public Channel getReadoutResources() { return readoutResources; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicLoop.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicLoop.java index 8c9e967..96c1161 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicLoop.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/CrlogicLoop.java @@ -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,9 @@ public class CrlogicLoop implements ActionLoop { private boolean abortForce = false; private Thread executionThread = null; - - public CrlogicLoop(String prefix, String server, String share, String smbShare, boolean zigZag){ + private ChannelService cservice; + public CrlogicLoop(ChannelService s, String prefix, String server, String share, String smbShare, boolean zigZag){ + cservice = s; this.prefix = prefix; this.server = server; this.share = share; @@ -462,7 +466,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 +504,7 @@ public class CrlogicLoop implements ActionLoop { try{ template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.ACTIVE.toString(), startStopTimeout); } - catch(CAException e){ + catch(ChannelException 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 +519,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 +541,7 @@ public class CrlogicLoop implements ActionLoop { try{ template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.INACTIVE.toString(), startStopTimeout); } - catch(CAException e){ + catch(ChannelException | ExecutionException 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); @@ -589,7 +593,7 @@ public class CrlogicLoop implements ActionLoop { executionThread = null; } } - catch(CAException e){ + catch(ChannelException | ExecutionException | TimeoutException e){ throw new RuntimeException("Unable to execute crloop", e); } } @@ -627,8 +631,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; @@ -677,11 +681,15 @@ public class CrlogicLoop implements ActionLoop { // Connect crlogic channels template = new CrlogicChannelsTemplate(); logger.info("Connect channels"); - ChannelBeanFactory.getFactory().createChannelBeans(template, prefix); + Map m = new HashMap<>(); + m.put("PREFIX", prefix); + cservice.createAnnotatedChannels(template, m); // Connect motor channels motortemplate = new MotorChannelsTemplate(); - ChannelBeanFactory.getFactory().createChannelBeans(motortemplate, actuator.getName()); + m = new HashMap<>(); + m.put("PREFIX", actuator.getName()); + cservice.createAnnotatedChannels(motortemplate, m); useReadback = motortemplate.getUseReadback().getValue(); useEncoder = motortemplate.getUseEncoder().getValue(); @@ -723,7 +731,9 @@ public class CrlogicLoop implements ActionLoop { // Fill readback encoder settings // Connect to encoder EncoderChannelsTemplate encodertemplate = new EncoderChannelsTemplate(); - ChannelBeanFactory.getFactory().createChannelBeans(encodertemplate, readback); + m = new HashMap<>(); + m.put("PREFIX", readback); + cservice.createAnnotatedChannels(encodertemplate, m); // Read encoder settings if(encodertemplate.getDirection().getValue()==EncoderChannelsTemplate.Direction.Positive.ordinal()){ @@ -736,7 +746,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)){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/EncoderChannelsTemplate.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/EncoderChannelsTemplate.java index ef8cb63..fd5247d 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/EncoderChannelsTemplate.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/EncoderChannelsTemplate.java @@ -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; /** @@ -31,41 +31,41 @@ public class EncoderChannelsTemplate { /** * Resolution - $(P)$(E)_SCL */ - @CaChannel(type=Double.class, name="_SCL") - private ChannelBean resolution; + @CaChannel(type=Double.class, name="${PREFIX}_SCL") + private Channel resolution; /** * Offset - $(P)$(E)_OFF */ - @CaChannel(type=Double.class, name ="_OFF") - private ChannelBean offset; + @CaChannel(type=Double.class, name ="${PREFIX}_OFF") + private Channel offset; /** * Direction - $(P)$(E)_DIR */ public enum Direction {Negative, Positive}; - @CaChannel(type=Integer.class, name ="_DIR") - private ChannelBean direction; + @CaChannel(type=Integer.class, name ="${PREFIX}_DIR") + private Channel direction; /** * @return the resolution */ - public ChannelBean getResolution() { + public Channel getResolution() { return resolution; } /** * @return the offset */ - public ChannelBean getOffset() { + public Channel getOffset() { return offset; } /** * @return the direction */ - public ChannelBean getDirection() { + public Channel getDirection() { return direction; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/MotorChannelsTemplate.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/MotorChannelsTemplate.java index c6c47da..199cbbe 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/MotorChannelsTemplate.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/MotorChannelsTemplate.java @@ -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 highLimit; + @CaChannel(type=Double.class, name ="${PREFIX}.HLM") + private Channel highLimit; /** * .LLM Low limit - double */ - @CaChannel(type=Double.class, name =".LLM") - private ChannelBean lowLimit; + @CaChannel(type=Double.class, name ="${PREFIX}.LLM") + private Channel lowLimit; /** * .RBV Readback value - double */ - @CaChannel(type=Double.class, name =".RBV", monitor=true) - private ChannelBean readbackValue; + @CaChannel(type=Double.class, name ="${PREFIX}.RBV", monitor=true) + private Channel readbackValue; /** * .VAL Set value - double */ - @CaChannel(type=Double.class, name =".VAL", monitor=true) - private ChannelBean setValue; + @CaChannel(type=Double.class, name ="${PREFIX}.VAL", monitor=true) + private Channel setValue; /** * .RLV Relative move value - double */ - @CaChannel(type=Double.class, name =".RLV") - private ChannelBean relativeMoveValue; + @CaChannel(type=Double.class, name ="${PREFIX}.RLV") + private Channel relativeMoveValue; /** * .TWV Teak value - double */ - @CaChannel(type=Double.class, name =".TWV") - private ChannelBean tweakValue; + @CaChannel(type=Double.class, name ="${PREFIX}.TWV") + private Channel tweakValue; /** * .TWR Tweak reverse - move left - int */ - @CaChannel(type=Integer.class, name =".TWR") - private ChannelBean tweakReverse; + @CaChannel(type=Integer.class, name ="${PREFIX}.TWR") + private Channel tweakReverse; /** * .TWF Tweak forward - move right - int */ - @CaChannel(type=Integer.class, name =".TWF") - private ChannelBean tweakForward; + @CaChannel(type=Integer.class, name ="${PREFIX}.TWF") + private Channel tweakForward; /** * .JOGR Jog reverse - int */ - @CaChannel(type=Integer.class, name =".JOGR") - private ChannelBean jogReverse; + @CaChannel(type=Integer.class, name ="${PREFIX}.JOGR") + private Channel jogReverse; /** * .JOGF Jog forward - int */ - @CaChannel(type=Integer.class, name =".JOGF") - private ChannelBean jogForward; + @CaChannel(type=Integer.class, name ="${PREFIX}.JOGF") + private Channel jogForward; /** * .HOMR Home reverse - int */ - @CaChannel(type=Integer.class, name =".HOMR") - private ChannelBean homeReverse; + @CaChannel(type=Integer.class, name ="${PREFIX}.HOMR") + private Channel homeReverse; /** * .HOMF Home forward - int */ - @CaChannel(type=Integer.class, name =".HOMF") - private ChannelBean homeForward; + @CaChannel(type=Integer.class, name ="${PREFIX}.HOMF") + private Channel homeForward; /** * .EGU Engineering unit - String */ - @CaChannel(type=String.class, name =".EGU") - private ChannelBean engineeringUnit; + @CaChannel(type=String.class, name ="${PREFIX}.EGU") + private Channel engineeringUnit; /** * .DTYP Type - String (e.g. "OMS MAXv") see enum Type */ - @CaChannel(type=Integer.class, name =".DTYP") - private ChannelBean type; + @CaChannel(type=Integer.class, name ="${PREFIX}.DTYP") + private Channel type; /** * .DESC Description - String */ - @CaChannel(type=String.class, name =".DESC") - private ChannelBean description; + @CaChannel(type=String.class, name ="${PREFIX}.DESC") + private Channel description; /** @@ -133,45 +133,45 @@ public class MotorChannelsTemplate { /** * .DHLM Dial high limit - double */ - @CaChannel(type=Double.class, name =".DHLM") - private ChannelBean dialHighLimit; + @CaChannel(type=Double.class, name ="${PREFIX}.DHLM") + private Channel dialHighLimit; /** * .DLLM Dial low limit - double */ - @CaChannel(type=Double.class, name =".DLLM") - private ChannelBean dialLowLimit; + @CaChannel(type=Double.class, name ="${PREFIX}.DLLM") + private Channel dialLowLimit; /** * .DRBV Dial readback value - double */ - @CaChannel(type=Double.class, name =".DRBV", monitor=true) - private ChannelBean dialReadbackValue; + @CaChannel(type=Double.class, name ="${PREFIX}.DRBV", monitor=true) + private Channel dialReadbackValue; /** * .DVAL Dial set value - double */ - @CaChannel(type=Double.class, name =".DVAL", monitor=true) - private ChannelBean dialSetValue; + @CaChannel(type=Double.class, name ="${PREFIX}.DVAL", monitor=true) + private Channel dialSetValue; /** * .RVAL Raw value - int */ - @CaChannel(type=Integer.class, name =".RVAL", monitor=true) - private ChannelBean rawValue; + @CaChannel(type=Integer.class, name ="${PREFIX}.RVAL", monitor=true) + private Channel rawValue; /** * .RRBV Raw readback value - int */ - @CaChannel(type=Integer.class, name =".RRBV", monitor=true) - private ChannelBean rawReadbackValue; + @CaChannel(type=Integer.class, name ="${PREFIX}.RRBV", monitor=true) + private Channel 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 command; + @CaChannel(type=Integer.class, name ="${PREFIX}.SPMG") + private Channel 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 calibration; + @CaChannel(type=Integer.class, name ="${PREFIX}.SET") + private Channel calibration; /** * .OFF User offset (EGU) - double */ - @CaChannel(type=Double.class, name =".OFF") - private ChannelBean offset; + @CaChannel(type=Double.class, name ="${PREFIX}.OFF") + private Channel offset; /** * .FOFF Offset-Freeze Switch - (0:"Variable", 1:"Frozen") - 1 */ public enum OffsetMode {Variable, Frozen}; - @CaChannel(type=Integer.class, name =".FOFF") - private ChannelBean offsetMode; + @CaChannel(type=Integer.class, name ="${PREFIX}.FOFF") + private Channel offsetMode; /** * .DIR User direction - (0:"Pos", 1:"Neg") */ public enum Direction {Positive, Negative}; - @CaChannel(type=Integer.class, name =".DIR") - private ChannelBean direction; + @CaChannel(type=Integer.class, name ="${PREFIX}.DIR") + private Channel direction; /** @@ -213,44 +213,44 @@ public class MotorChannelsTemplate { /** * .VELO Velocity (EGU/s) - double */ - @CaChannel(type=Double.class, name =".VELO") - private ChannelBean velocity; + @CaChannel(type=Double.class, name ="${PREFIX}.VELO") + private Channel velocity; /** * .BVEL Backlash velocity (EGU/s) - double */ - @CaChannel(type=Double.class, name =".BVEL") - private ChannelBean backlashVelocity; + @CaChannel(type=Double.class, name ="${PREFIX}.BVEL") + private Channel backlashVelocity; /** * .VBAS Base speed (EGU/s) - double */ - @CaChannel(type=Double.class, name =".VBAS") - private ChannelBean baseSpeed; + @CaChannel(type=Double.class, name ="${PREFIX}.VBAS") + private Channel baseSpeed; /** * .ACCL Acceleration time / seconds to velocity - double */ - @CaChannel(type=Double.class, name =".ACCL") - private ChannelBean accelerationTime; + @CaChannel(type=Double.class, name ="${PREFIX}.ACCL") + private Channel accelerationTime; /** * .BACC Backlash acceleration time / seconds to velocity - double */ - @CaChannel(type=Double.class, name =".BACC") - private ChannelBean backlashAccelerationTime; + @CaChannel(type=Double.class, name ="${PREFIX}.BACC") + private Channel backlashAccelerationTime; /** * .BDST Backlash distance (EGU) - double */ - @CaChannel(type=Double.class, name =".BDST") - private ChannelBean backlashDistance; + @CaChannel(type=Double.class, name ="${PREFIX}.BDST") + private Channel backlashDistance; /** * .FRAC Move fraction - double */ - @CaChannel(type=Double.class, name =".FRAC") - private ChannelBean moveFracion; + @CaChannel(type=Double.class, name ="${PREFIX}.FRAC") + private Channel moveFracion; /** @@ -260,69 +260,69 @@ public class MotorChannelsTemplate { /** * .MRES Motor resolution - double */ - @CaChannel(type=Double.class, name =".MRES") - private ChannelBean motorResolution; + @CaChannel(type=Double.class, name ="${PREFIX}.MRES") + private Channel motorResolution; /** * .ERES Encoder resolution - double */ - @CaChannel(type=Double.class, name =".ERES") - private ChannelBean encoderResolution; + @CaChannel(type=Double.class, name ="${PREFIX}.ERES") + private Channel encoderResolution; /** * .RRES Readback resolution - double */ - @CaChannel(type=Double.class, name =".RRES") - private ChannelBean readbackResolution; + @CaChannel(type=Double.class, name ="${PREFIX}.RRES") + private Channel readbackResolution; /** * .RDBD Retry deadband (EGU) - double */ - @CaChannel(type=Double.class, name =".RDBD") - private ChannelBean retryDeadband; + @CaChannel(type=Double.class, name ="${PREFIX}.RDBD") + private Channel retryDeadband; /** * .RTRY Max retry count - int */ - @CaChannel(type=Integer.class, name =".RTRY") - private ChannelBean maxRetryCount; + @CaChannel(type=Integer.class, name ="${PREFIX}.RTRY") + private Channel maxRetryCount; /** * .RCNT Retry count - int */ - @CaChannel(type=Integer.class, name =".RCNT", monitor=true) - private ChannelBean retryCount; + @CaChannel(type=Integer.class, name ="${PREFIX}.RCNT", monitor=true) + private Channel retryCount; /** * .UEIP Use encoder (if present) - (0:"No", 1:"Yes") */ - @CaChannel(type=Boolean.class, name =".UEIP") - private ChannelBean useEncoder; + @CaChannel(type=Boolean.class, name ="${PREFIX}.UEIP") + private Channel useEncoder; /** * .URIP Use readback link (if present) - (0:"No", 1:"Yes") */ - @CaChannel(type=Boolean.class, name =".URIP") - private ChannelBean useReadback; + @CaChannel(type=Boolean.class, name ="${PREFIX}.URIP") + private Channel useReadback; /** * .DLY Readback delay (s) - double */ - @CaChannel(type=Double.class, name =".DLY") - private ChannelBean readbackDelay; + @CaChannel(type=Double.class, name ="${PREFIX}.DLY") + private Channel readbackDelay; /** * .RDBL Readback link - String */ - @CaChannel(type=String.class, name =".RDBL") - private ChannelBean readbackLink; + @CaChannel(type=String.class, name ="${PREFIX}.RDBL") + private Channel readbackLink; /** * .OMSL Output mode select - (0:"supervisory", 1:"closed_loop") */ public enum OutputMode {Supervisory, Closed_Loop}; - @CaChannel(type=Integer.class, name =".OMSL") - private ChannelBean outputMode; + @CaChannel(type=Integer.class, name ="${PREFIX}.OMSL") + private Channel outputMode; /** * ## Status ## @@ -331,321 +331,321 @@ public class MotorChannelsTemplate { /** * .DMOV Done move - int */ - @CaChannel(type=Boolean.class, name =".DMOV", monitor=true) - private ChannelBean moveDone; + @CaChannel(type=Boolean.class, name ="${PREFIX}.DMOV", monitor=true) + private Channel moveDone; /** * @return the highLimit */ - public ChannelBean getHighLimit() { + public Channel getHighLimit() { return highLimit; } /** * @return the lowLimit */ - public ChannelBean getLowLimit() { + public Channel getLowLimit() { return lowLimit; } /** * @return the readbackValue */ - public ChannelBean getReadbackValue() { + public Channel getReadbackValue() { return readbackValue; } /** * @return the setValue */ - public ChannelBean getSetValue() { + public Channel getSetValue() { return setValue; } /** * @return the relativeMoveValue */ - public ChannelBean getRelativeMoveValue() { + public Channel getRelativeMoveValue() { return relativeMoveValue; } /** * @return the tweakValue */ - public ChannelBean getTweakValue() { + public Channel getTweakValue() { return tweakValue; } /** * @return the tweakReverse */ - public ChannelBean getTweakReverse() { + public Channel getTweakReverse() { return tweakReverse; } /** * @return the tweakForward */ - public ChannelBean getTweakForward() { + public Channel getTweakForward() { return tweakForward; } /** * @return the jogReverse */ - public ChannelBean getJogReverse() { + public Channel getJogReverse() { return jogReverse; } /** * @return the jogForward */ - public ChannelBean getJogForward() { + public Channel getJogForward() { return jogForward; } /** * @return the homeReverse */ - public ChannelBean getHomeReverse() { + public Channel getHomeReverse() { return homeReverse; } /** * @return the homeForward */ - public ChannelBean getHomeForward() { + public Channel getHomeForward() { return homeForward; } /** * @return the engineeringUnit */ - public ChannelBean getEngineeringUnit() { + public Channel getEngineeringUnit() { return engineeringUnit; } /** * @return the type */ - public ChannelBean getType() { + public Channel getType() { return type; } /** * @return the description */ - public ChannelBean getDescription() { + public Channel getDescription() { return description; } /** * @return the dialHighLimit */ - public ChannelBean getDialHighLimit() { + public Channel getDialHighLimit() { return dialHighLimit; } /** * @return the dialLowLimit */ - public ChannelBean getDialLowLimit() { + public Channel getDialLowLimit() { return dialLowLimit; } /** * @return the dialReadbackValue */ - public ChannelBean getDialReadbackValue() { + public Channel getDialReadbackValue() { return dialReadbackValue; } /** * @return the dialSetValue */ - public ChannelBean getDialSetValue() { + public Channel getDialSetValue() { return dialSetValue; } /** * @return the rawValue */ - public ChannelBean getRawValue() { + public Channel getRawValue() { return rawValue; } /** * @return the rawReadbackValue */ - public ChannelBean getRawReadbackValue() { + public Channel getRawReadbackValue() { return rawReadbackValue; } /** * @return the command */ - public ChannelBean getCommand() { + public Channel getCommand() { return command; } /** * @return the calibration */ - public ChannelBean getCalibration() { + public Channel getCalibration() { return calibration; } /** * @return the userOffset */ - public ChannelBean getOffset() { + public Channel getOffset() { return offset; } /** * @return the offsetMode */ - public ChannelBean getOffsetMode() { + public Channel getOffsetMode() { return offsetMode; } /** * @return the direction */ - public ChannelBean getDirection() { + public Channel getDirection() { return direction; } /** * @return the velocity */ - public ChannelBean getVelocity() { + public Channel getVelocity() { return velocity; } /** * @return the backlashVelocity */ - public ChannelBean getBacklashVelocity() { + public Channel getBacklashVelocity() { return backlashVelocity; } /** * @return the baseSpeed */ - public ChannelBean getBaseSpeed() { + public Channel getBaseSpeed() { return baseSpeed; } /** * @return the accelerationTime */ - public ChannelBean getAccelerationTime() { + public Channel getAccelerationTime() { return accelerationTime; } /** * @return the backlashAccelerationTime */ - public ChannelBean getBacklashAccelerationTime() { + public Channel getBacklashAccelerationTime() { return backlashAccelerationTime; } /** * @return the backlashDistance */ - public ChannelBean getBacklashDistance() { + public Channel getBacklashDistance() { return backlashDistance; } /** * @return the moveFracion */ - public ChannelBean getMoveFracion() { + public Channel getMoveFracion() { return moveFracion; } /** * @return the motorResolution */ - public ChannelBean getMotorResolution() { + public Channel getMotorResolution() { return motorResolution; } /** * @return the encoderResolution */ - public ChannelBean getEncoderResolution() { + public Channel getEncoderResolution() { return encoderResolution; } /** * @return the readbackResolution */ - public ChannelBean getReadbackResolution() { + public Channel getReadbackResolution() { return readbackResolution; } /** * @return the retryDeadband */ - public ChannelBean getRetryDeadband() { + public Channel getRetryDeadband() { return retryDeadband; } /** * @return the maxRetryCount */ - public ChannelBean getMaxRetryCount() { + public Channel getMaxRetryCount() { return maxRetryCount; } /** * @return the retryCount */ - public ChannelBean getRetryCount() { + public Channel getRetryCount() { return retryCount; } /** * @return the useEncoder */ - public ChannelBean getUseEncoder() { + public Channel getUseEncoder() { return useEncoder; } /** * @return the useReadback */ - public ChannelBean getUseReadback() { + public Channel getUseReadback() { return useReadback; } /** * @return the readbackDelay */ - public ChannelBean getReadbackDelay() { + public Channel getReadbackDelay() { return readbackDelay; } /** * @return the readbackLink */ - public ChannelBean getReadbackLink() { + public Channel getReadbackLink() { return readbackLink; } /** * @return the outputMode */ - public ChannelBean getOutputMode() { + public Channel getOutputMode() { return outputMode; } /** * @return the moveDone */ - public ChannelBean getMoveDone() { + public Channel getMoveDone() { return moveDone; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java index 2e0ca3f..460e740 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java @@ -19,15 +19,17 @@ 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.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,8 +43,11 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; +import ch.psi.jcae.impl.type.DoubleTimestamp; /** * @author ebner @@ -85,13 +90,13 @@ public class ScrlogicLoop implements ActionLoop { /** * Sensors to read out */ - private List sensors; +// private List sensors; /** * List of monitors that were attached to the sensor channels (i.e * workaround) */ - private final List monitors = new ArrayList(); + private final List monitors = new ArrayList<>(); /** * List of blocking queues that hold the data for one sensor (channel) @@ -100,8 +105,20 @@ public class ScrlogicLoop implements ActionLoop { private CountDownLatch latch; - public ScrlogicLoop(List sensors) { - this.sensors = sensors; + private List> sensors = new ArrayList<>(); + private List sensorIds = new ArrayList<>(); + private ChannelService cservice; + + public ScrlogicLoop(ChannelService s, List sensors) { + try{ + for(Sensor ss: sensors){ + this.sensors.add(s.createChannel(new ChannelDescriptor(DoubleTimestamp.class, ((ChannelAccessDoubleSensor)ss).getChannel().getName(), true))); + sensorIds.add(ss.getId()); + } + this.cservice = s; + } catch (ChannelException | InterruptedException | TimeoutException e) { + throw new RuntimeException(e); + } } /* @@ -116,53 +133,40 @@ 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 b = s.getChannel(); + for (Channel sensor : sensors) { +// if (sensor instanceof ChannelAccessDoubleSensor) { +// ChannelAccessDoubleSensor s = (ChannelAccessDoubleSensor) sensor; +// Channel b = s.getChannel(); // Create data queue for the channel final BlockingQueue q = new LinkedBlockingQueue(); queues.add(q); + + PropertyChangeListener b = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + DoubleTimestamp value = (DoubleTimestamp) evt.getNewValue(); + q.add(new TimestampedValue(value.getValue(), value.getTimestamp().getTime(), value.getNanosecondOffset())); + } + }; - 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); - } + sensor.addPropertyChangeListener("value", b); + + monitors.add(b); +// } } - } catch (CAException e) { - new RuntimeException("Unable to create monitor for channels", e); - } logger.info("Start data acquisition"); latch.await(); // Remove monitors - try { + try{ for (int i = 0; i < sensors.size(); i++) { - Sensor sensor = sensors.get(i); - if (sensor instanceof ChannelAccessDoubleSensor) { - ChannelAccessDoubleSensor s = (ChannelAccessDoubleSensor) sensor; - ChannelBean b = s.getChannel(); - try{ - b.removeMonitor(monitors.get(i)); - } - catch(IllegalArgumentException e){ - logger.log(Level.SEVERE, "Unable to detach monitor", e); - } - } + Channel sensor = sensors.get(i); + sensor.removePropertyChangeListener(monitors.get(i)); } - } catch (CAException e) { - new RuntimeException(e); } finally{ // Clear all monitors in the list @@ -201,8 +205,12 @@ public class ScrlogicLoop implements ActionLoop { @Override public void destroy() { // Destroy all sensors - for (Sensor s : sensors) { - s.destroy(); + for (Channel s : sensors) { + try { + s.destroy(); + } catch (ChannelException e) { + throw new RuntimeException(e); + } } sensors.clear(); } @@ -280,8 +288,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); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/VSC16ScalerChannelsTemplate.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/VSC16ScalerChannelsTemplate.java index 16e5713..69f03ba 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/VSC16ScalerChannelsTemplate.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/VSC16ScalerChannelsTemplate.java @@ -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 command; + @CaChannel(type=Integer.class, name ="${PREFIX}.CNT") + private Channel command; public enum Mode {OneShot, AutoCount}; /** * Count mode */ - @CaChannel(type=Integer.class, name =".CONT") - private ChannelBean mode; + @CaChannel(type=Integer.class, name ="${PREFIX}.CONT") + private Channel 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> 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> 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> 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> 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> 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> channelPresetCount; /** * @return the command */ - public ChannelBean getCommand() { + public Channel getCommand() { return command; } /** * @return the mode */ - public ChannelBean getMode() { + public Channel getMode() { return mode; } /** * @return the channelDescription */ - public List> getChannelDescription() { + public List> getChannelDescription() { return channelDescription; } /** * @return the channelGate */ - public List> getChannelGate() { + public List> getChannelGate() { return channelGate; } /** * @return the channelPresetCount */ - public List> getChannelPresetCount() { + public List> getChannelPresetCount() { return channelPresetCount; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/manipulator/JythonManipulation.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/manipulator/JythonManipulation.java index 3cb0e53..3805c44 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/manipulator/JythonManipulation.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/manipulator/JythonManipulation.java @@ -19,9 +19,8 @@ package ch.psi.fda.core.manipulator; -import gov.aps.jca.CAException; - import java.util.List; +import java.util.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -37,8 +36,10 @@ 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; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Manipulation @@ -96,14 +97,15 @@ public class JythonManipulation implements Manipulation{ * Parameter array of the entry function */ private String[] parameter; + private ChannelService cservice; /** * Jython entry call */ private String jythonCall; - public JythonManipulation(String id, String script, List mapping){ - this(id, script, mapping, false); + public JythonManipulation(ChannelService s, String id, String script, List mapping){ + this(s, id, script, mapping, false); } /** @@ -112,11 +114,12 @@ public class JythonManipulation implements Manipulation{ * @param script * @param mapping */ - public JythonManipulation(String id, String script, List mapping, boolean returnArray){ + public JythonManipulation(ChannelService s, String id, String script, List mapping, boolean returnArray){ this.id = id; this.script = script; this.mapping = mapping; this.returnArray = returnArray; + this.cservice = s; } /** @@ -192,10 +195,10 @@ public class JythonManipulation implements Manipulation{ JythonParameterMappingChannel pm = (JythonParameterMappingChannel)jpm; parameterIndex[i] = null; - ChannelBean cb; + Channel cb; try { - cb = ChannelBeanFactory.getFactory().createChannelBean(pm.getType(), pm.getChannel(), true); - } catch (CAException e) { + cb = cservice.createChannel(new ChannelDescriptor<>(pm.getType(), pm.getChannel(), true)); + } catch (ChannelException | TimeoutException e) { throw new IllegalArgumentException("Unable to establish channel: "+pm.getChannel(), e); } catch (InterruptedException e) { throw new RuntimeException("Unable to establish channel: "+pm.getChannel(), e); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java index 0b81103..82ecfd5 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensor.java @@ -19,13 +19,16 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Scalar sensor that reads a double form a Channel Access channel @@ -40,7 +43,7 @@ public class ChannelAccessDoubleArraySensor implements Sensor { /** * Channel Access channel of this sensor */ - private final ChannelBean channel; + private final Channel channel; /** * Number of elements to read from the waveform @@ -58,12 +61,12 @@ public class ChannelAccessDoubleArraySensor implements Sensor { * @param channelName Name of the Channel Access channel of this sensor * @param numberOfElements Number of elements to read out of the waveform */ - public ChannelAccessDoubleArraySensor(String id, String channelName, int numberOfElements){ + public ChannelAccessDoubleArraySensor(ChannelService s, String id, String channelName, int numberOfElements){ try { - this.channel = ChannelBeanFactory.getFactory().createChannelBean(double[].class, channelName, false); + this.channel = s.createChannel(new ChannelDescriptor<>(double[].class, channelName, false, numberOfElements)); this.numberOfElements = numberOfElements; this.id = id; - } catch (CAException e) { + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -80,7 +83,8 @@ public class ChannelAccessDoubleArraySensor implements Sensor { double[] v; try { - v = channel.getValue(numberOfElements); +// v = channel.getValue(numberOfElements); + 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) @@ -91,7 +95,7 @@ public class ChannelAccessDoubleArraySensor implements Sensor { for(int i =0;i channel; + private Channel channel; /** * Global id of the sensor @@ -53,11 +56,11 @@ public class ChannelAccessDoubleSensor implements Sensor { * @param id Global id of the sensor * @param channelName Name of the Channel Access channel of this sensor */ - public ChannelAccessDoubleSensor(String id, String channelName){ + public ChannelAccessDoubleSensor(ChannelService s, String id, String channelName){ try { - channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); + channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false)); this.id = id; - } catch (CAException e) { + } catch (ChannelException | TimeoutException e) { // Convert Exception into unchecked RuntimeException throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e); } catch (InterruptedException e) { @@ -82,7 +85,7 @@ public class ChannelAccessDoubleSensor implements Sensor { throw e; } v = Double.NaN; - } catch (CAException e) { + } catch (ChannelException | TimeoutException | 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()){ @@ -116,7 +119,7 @@ public class ChannelAccessDoubleSensor implements Sensor { try { logger.finest("Destroy sensor channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } @@ -125,7 +128,7 @@ public class ChannelAccessDoubleSensor implements Sensor { * Get channel object of sensor * @return */ - public ChannelBean getChannel(){ + public Channel getChannel(){ return channel; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java index 7dcad23..6ba5828 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessStringSensor.java @@ -19,13 +19,16 @@ 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.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; /** * Scalar sensor that reads a double form a Channel Access channel @@ -41,7 +44,7 @@ public class ChannelAccessStringSensor implements Sensor { /** * Channel Access channel of this sensor */ - private ChannelBean channel; + private Channel channel; /** * Global id of the sensor @@ -53,15 +56,16 @@ public class ChannelAccessStringSensor implements Sensor { * @param id Global id of the sensor * @param channelName Name of the Channel Access channel of this sensor */ - public ChannelAccessStringSensor(String id, String channelName){ + public ChannelAccessStringSensor(ChannelService s, String id, String channelName){ try { - channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, channelName, false); + channel = s.createChannel(new ChannelDescriptor(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); + } catch (ChannelException e) { + throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e); + } catch (TimeoutException e) { + throw new IllegalArgumentException("Unable to initialize sensor channel [name:"+channelName+"]",e); } } @@ -82,7 +86,7 @@ public class ChannelAccessStringSensor implements Sensor { throw e; } v = null; - } catch (CAException e) { + } catch (TimeoutException | ExecutionException |ChannelException 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()){ @@ -96,6 +100,7 @@ public class ChannelAccessStringSensor implements Sensor { // } // v = null; } + return(v); } @@ -116,7 +121,7 @@ public class ChannelAccessStringSensor implements Sensor { try { logger.finest("Destroy sensor channel: "+channel.getName()); channel.destroy(); - } catch (CAException e) { + } catch (ChannelException e) { throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e); } } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessConditionTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessConditionTest.java index d1c8ab7..fdb133a 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessConditionTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessConditionTest.java @@ -21,18 +21,21 @@ 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; - import org.junit.After; import org.junit.Before; 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 @@ -43,11 +46,14 @@ public class ChannelAccessConditionTest { // Get Logger private static Logger logger = Logger.getLogger(ChannelAccessConditionTest.class.getName()); + private ChannelService cservice; + /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -60,21 +66,24 @@ public class ChannelAccessConditionTest { /** * Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringCondition#ChannelAccessStringCondition(java.lang.String, java.lang.String, long)}. * @throws InterruptedException + * @throws TimeoutException + * @throws ChannelException + * @throws ExecutionException * @throws CAException */ @Test - public void testChannelAccessStringCondition() throws InterruptedException, CAException { - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + public void testChannelAccessStringCondition() throws InterruptedException, ChannelException, TimeoutException, ExecutionException { + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); channel.setValue("SomeValue"); - ChannelAccessCondition c = new ChannelAccessCondition(TestChannels.STRING_OUT, "SomeValue", 1000l); + ChannelAccessCondition c = new ChannelAccessCondition(cservice, TestChannels.STRING_OUT, "SomeValue", 1000l); c.execute(); } @Test - public void testChannelAccessStringConditionRegex() throws InterruptedException, CAException { - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + public void testChannelAccessStringConditionRegex() throws InterruptedException, ExecutionException, ChannelException, TimeoutException { + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); channel.setValue("SomeValue"); - ChannelAccessConditionRegex c = new ChannelAccessConditionRegex(TestChannels.STRING_OUT, "Some.*", 1000l); + ChannelAccessConditionRegex c = new ChannelAccessConditionRegex(cservice, TestChannels.STRING_OUT, "Some.*", 1000l); c.execute(); } @@ -83,20 +92,23 @@ public class ChannelAccessConditionTest { */ @Test(expected=IllegalArgumentException.class) public void testChannelAccessStringConditionNotExist() { - new ChannelAccessCondition(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue", 1000l); + new ChannelAccessCondition(cservice, 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 InterruptedException, ChannelException, TimeoutException, ExecutionException { String value = "SomeValue"; - final ChannelAccessCondition action = new ChannelAccessCondition(TestChannels.STRING_OUT, value, 10000l); - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + final ChannelAccessCondition action = new ChannelAccessCondition(cservice, TestChannels.STRING_OUT, value, 10000l); + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); Thread t = new Thread(new Runnable() { @@ -131,11 +143,11 @@ public class ChannelAccessConditionTest { } @Test(expected=RuntimeException.class) - public void testExecuteFail() throws CAException, InterruptedException { + public void testExecuteFail() throws InterruptedException, ExecutionException, ChannelException, TimeoutException { String value = "SomeValue"; - final ChannelAccessCondition action = new ChannelAccessCondition(TestChannels.STRING_OUT, value, 9000l); - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + final ChannelAccessCondition action = new ChannelAccessCondition(cservice, TestChannels.STRING_OUT, value, 9000l); + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); // Set the value to something else than the expected value @@ -148,13 +160,16 @@ 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 InterruptedException, ChannelException, TimeoutException, ExecutionException { Integer value = 12; - final ChannelAccessCondition action = new ChannelAccessCondition(TestChannels.STRING_OUT, value, 10000l); - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, TestChannels.STRING_OUT, false); + final ChannelAccessCondition action = new ChannelAccessCondition(cservice, TestChannels.STRING_OUT, value, 10000l); + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, TestChannels.STRING_OUT, false)); Thread t = new Thread(new Runnable() { @@ -192,11 +207,14 @@ 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 action = new ChannelAccessCondition(TestChannels.BINARY_OUT, 1, 10000l); - final ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, TestChannels.BINARY_OUT, false); + public void testWaitAbort() throws InterruptedException, ChannelException, TimeoutException, ExecutionException { + final ChannelAccessCondition action = new ChannelAccessCondition(cservice, TestChannels.BINARY_OUT, 1, 10000l); + final Channel channel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, TestChannels.BINARY_OUT, false)); Thread t = new Thread(new Runnable() { diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessPutTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessPutTest.java index 45cddd1..2f85956 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessPutTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/ChannelAccessPutTest.java @@ -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,8 +32,11 @@ 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 @@ -42,12 +45,14 @@ import ch.psi.jcae.ChannelBeanFactory; */ public class ChannelAccessPutTest { + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -63,7 +68,7 @@ public class ChannelAccessPutTest { */ @Test public void testChannelAccessStringPutStringStringBoolean() { - new ChannelAccessPut(TestChannels.STRING_OUT, "SomeValue", true, null); + new ChannelAccessPut(cservice, TestChannels.STRING_OUT, "SomeValue", true, null); } /** @@ -72,7 +77,7 @@ public class ChannelAccessPutTest { */ @Test(expected=IllegalArgumentException.class) public void testChannelAccessStringPutStringStringBooleanNotExist() { - new ChannelAccessPut(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue", true, null); + new ChannelAccessPut(cservice, TestChannels.STRING_OUT_NOT_EXIST, "SomeValue", true, null); } /** @@ -81,7 +86,7 @@ public class ChannelAccessPutTest { */ @Test public void testChannelAccessStringPutStringString() { - new ChannelAccessPut(TestChannels.STRING_OUT, "SomeValue"); + new ChannelAccessPut(cservice, TestChannels.STRING_OUT, "SomeValue"); } /** @@ -90,22 +95,25 @@ public class ChannelAccessPutTest { */ @Test(expected=IllegalArgumentException.class) public void testChannelAccessStringPutStringStringNotExist() { - new ChannelAccessPut(TestChannels.STRING_OUT_NOT_EXIST, "SomeValue"); + new ChannelAccessPut(cservice, TestChannels.STRING_OUT_NOT_EXIST, "SomeValue"); } /** * Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#execute()}. * @throws CAException * @throws InterruptedException + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException */ @Test - public void testExecute() throws CAException, InterruptedException { + public void testExecute() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { String setValue = "MyTestString"; - ChannelAccessPut action = new ChannelAccessPut(TestChannels.STRING_OUT, setValue); + ChannelAccessPut action = new ChannelAccessPut(cservice, TestChannels.STRING_OUT, setValue); action.execute(); - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); String value = channel.getValue(); if(!value.equals(setValue)){ @@ -115,18 +123,21 @@ public class ChannelAccessPutTest { /** * Test method for {@link ch.psi.fda.core.actions.ChannelAccessStringPut#execute()}. + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testExecuteString() throws CAException, InterruptedException { + public void testExecuteString() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { String setValue = "MyTestString"; - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false); + Channel channel = cservice.createChannel(new ChannelDescriptor<>(String.class, TestChannels.STRING_OUT, false)); // Set channel to something else channel.setValue(setValue+"test"); - ChannelAccessPut action = new ChannelAccessPut(TestChannels.STRING_OUT, setValue); + ChannelAccessPut action = new ChannelAccessPut(cservice, TestChannels.STRING_OUT, setValue); action.execute(); @@ -143,11 +154,11 @@ public class ChannelAccessPutTest { * @throws InterruptedException */ @Test - public void testExecuteMulti() throws CAException, InterruptedException { + public void testExecuteMulti() throws InterruptedException { List> actions = new ArrayList>(); for(int i=0;i<20;i++){ - actions.add(new ChannelAccessPut(TestChannels.STRING_OUT, i+"")); + actions.add(new ChannelAccessPut(cservice, TestChannels.STRING_OUT, i+"")); } for(ChannelAccessPut action: actions){ diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/JythonActionTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/JythonActionTest.java index 0e01589..ddc3cd8 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/JythonActionTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actions/JythonActionTest.java @@ -31,6 +31,8 @@ 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.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; /** * @author ebner @@ -38,11 +40,13 @@ import ch.psi.fda.core.scripting.JythonParameterMappingChannel; */ public class JythonActionTest { + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -61,7 +65,7 @@ public class JythonActionTest { 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 mapping = new ArrayList(); mapping.add(new JythonParameterMappingChannel("o", TestChannels.ANALOG_OUT, Double.class)); - JythonAction action = new JythonAction(script, mapping); + JythonAction action = new JythonAction(cservice, script, mapping); // Execute action action.execute(); @@ -78,7 +82,7 @@ public class JythonActionTest { List mapping = new ArrayList(); 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); + JythonAction action = new JythonAction(cservice, script, mapping); // Execute action action.execute(); @@ -94,7 +98,7 @@ public class JythonActionTest { 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 mapping = new ArrayList(); mapping.add(new JythonParameterMappingChannel("ooo", TestChannels.ANALOG_OUT, Double.class)); - JythonAction action = new JythonAction(script, mapping); + JythonAction action = new JythonAction(cservice, script, mapping); // Execute action action.execute(); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuatorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuatorTest.java index 4496bd2..6869509 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuatorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuatorTest.java @@ -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. @@ -53,18 +57,20 @@ public class ChannelAccessFunctionActuatorTest { private static final double doneDelay = 0; private static final Long timeout = 1800000l; // 30 minutes - private ChannelBean channel; - private ChannelBean doneChannel; + private Channel channel; + private Channel doneChannel; private Function function; + private ChannelService cservice; /** * @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, false)); + doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone, false)); function = new Function() { @@ -87,22 +93,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(channelName, function,0, 1, -0.1, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, 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(channelName, function, 0, 1, 0.1, -1l); + new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 1, 0.1, -1l); } catch(IllegalArgumentException e){ flag=true; @@ -115,7 +121,7 @@ public class ChannelAccessFunctionActuatorTest { flag=false; try{ // Need to return IllegalArgumentException - new ChannelAccessFunctionActuator(channelName, function, 0, 1, 0.1, -0l); + new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 1, 0.1, -0l); } catch(IllegalArgumentException e){ flag=true; @@ -125,10 +131,10 @@ public class ChannelAccessFunctionActuatorTest { } // Accept null timeout - new ChannelAccessFunctionActuator(channelName, function, 0, 1, 0.1, null); + new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 1, 0.1, null); // Accept positive timeout - new ChannelAccessFunctionActuator(channelName, function, 0, 1, 0.1, 1l); + new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 1, 0.1, 1l); } @@ -137,18 +143,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(channelName, function, 0, 1, 0, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, 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(channelName, function, 0, 10, 1, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 10, 1, timeout); } @@ -158,7 +164,7 @@ public class ChannelAccessFunctionActuatorTest { */ @Test public void testSet() throws InterruptedException { - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, 0, 0.09999, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 0.09999, 0.1, timeout); actuator.set(); } @@ -169,7 +175,7 @@ public class ChannelAccessFunctionActuatorTest { */ @Test(expected=IllegalStateException.class) public void testSetNoNext() throws InterruptedException { - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, 0, 0.09999, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 0.09999, 0.1, timeout); actuator.set(); actuator.set(); } @@ -180,7 +186,7 @@ public class ChannelAccessFunctionActuatorTest { */ @Test public void testHasNextOneStep() throws InterruptedException { - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, 0, 0.09999, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 0.09999, 0.1, timeout); // Execute first set (because there is always a first move) actuator.set(); @@ -197,7 +203,7 @@ public class ChannelAccessFunctionActuatorTest { */ @Test public void testHasNext() throws InterruptedException { - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, 0, 10, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, 0, 10, 0.1, timeout); int count = 0; int steps = (int) ((10-0)/0.1)+1; @@ -227,7 +233,7 @@ public class ChannelAccessFunctionActuatorTest { for(double[] svalue: settings){ - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, svalue[0], svalue[1], svalue[2], timeout); int count =0; while(actuator.hasNext()){ @@ -246,10 +252,13 @@ public class ChannelAccessFunctionActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#set()}. * Test actuator move startend ... + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testReverse() throws CAException, InterruptedException { + public void testReverse() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { List settings = new ArrayList(); // start end stepsize @@ -258,7 +267,7 @@ public class ChannelAccessFunctionActuatorTest { for(double[] svalue: settings){ - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, svalue[0], svalue[1], svalue[2], timeout); actuator.init(); int count =0; @@ -328,10 +337,13 @@ public class ChannelAccessFunctionActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessFunctionActuator#set()}. * Test actuator move startend ... + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testReverseReset() throws CAException, InterruptedException { + public void testReverseReset() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { List settings = new ArrayList(); // start end stepsize @@ -340,7 +352,7 @@ public class ChannelAccessFunctionActuatorTest { for(double[] svalue: settings){ - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, svalue[0], svalue[1], svalue[2], timeout); actuator.init(); int count =0; @@ -417,9 +429,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(channelName, channelNameDone, doneValue, doneDelay, function, 0, 1, -0.1, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function, 0, 1, -0.1, timeout); } /** @@ -427,29 +439,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(channelName, channelNameDone, doneValue, doneDelay, function, 0, 1, 0, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, 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(channelName, channelNameDone, doneValue, doneDelay, function, 0, 10, 1, timeout); + new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, 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 actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout); // Simulate done channel doneChannel.setValue(0); @@ -472,12 +486,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 actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, 1.5, function, 0, 1, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, 1.5, function, 0, 1, 0.1, timeout); // Simulate done channel doneChannel.setValue(1); @@ -510,12 +526,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 actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function,0, 0.09999, 0.1, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function,0, 0.09999, 0.1, timeout); // Simulate done channel @@ -558,11 +576,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 actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout); + public void testDoneHasNextOneStep() throws InterruptedException, ExecutionException, ChannelException { + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function, 0, 0.09999, 0.1, timeout); // Simulate done channel doneChannel.setValue(0); @@ -592,11 +612,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 actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function,0, 10, 0.1, timeout); + public void testDoneHasNext() throws InterruptedException, ExecutionException, ChannelException { + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function,0, 10, 0.1, timeout); int count = 0; int steps = (int) ((10-0)/0.1)+1; @@ -633,10 +655,12 @@ public class ChannelAccessFunctionActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPFunctionActuator#set()}. * Test actuator move startend ... + * @throws ChannelException + * @throws ExecutionException * @throws CAException */ @Test - public void testDoneSetLoop() throws CAException, InterruptedException { + public void testDoneSetLoop() throws InterruptedException, ExecutionException, ChannelException { List settings = new ArrayList(); // start end stepsize @@ -645,7 +669,7 @@ public class ChannelAccessFunctionActuatorTest { for(double[] svalue: settings){ - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function, svalue[0], svalue[1], svalue[2], timeout); int count =0; while(actuator.hasNext()){ @@ -682,10 +706,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 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; @@ -697,7 +724,7 @@ public class ChannelAccessFunctionActuatorTest { logger.info("Current channel value: "+channel.getValue()); - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, channelNameDone, doneValue, doneDelay, function, start, end, stepSize, timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, function, start, end, stepSize, timeout); while(actuator.hasNext()){ // Simulate done channel @@ -740,7 +767,7 @@ public class ChannelAccessFunctionActuatorTest { for(double[] svalue: settings){ - ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(channelName, function, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessFunctionActuator actuator = new ChannelAccessFunctionActuator(cservice, channelName, function, svalue[0], svalue[1], svalue[2], timeout); int count =0; while(actuator.hasNext()){ diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessLinearActuatorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessLinearActuatorTest.java index 4fcb72c..f34845d 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessLinearActuatorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessLinearActuatorTest.java @@ -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,16 +57,18 @@ public class ChannelAccessLinearActuatorTest { private static final double doneDelay = 0; private static final Long timeout = 1800000l; // 30 minutes - private ChannelBean channel; - private ChannelBean doneChannel; + private Channel channel; + private Channel doneChannel; + private ChannelService cservice; /** * @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, false)); + doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone, false)); } /** @@ -77,22 +83,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(channelName, null, 1,0, 0, 1, -0.1, timeout); + new ChannelAccessLinearActuator(cservice, channelName, 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(channelName, null, 1,0, 0, 1, 0.1, -1l); + new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 1, 0.1, -1l); } catch(IllegalArgumentException e){ flag=true; @@ -105,7 +111,7 @@ public class ChannelAccessLinearActuatorTest { flag=false; try{ // Need to return IllegalArgumentException - new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 1, 0.1, -0l); + new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 1, 0.1, -0l); } catch(IllegalArgumentException e){ flag=true; @@ -115,10 +121,10 @@ public class ChannelAccessLinearActuatorTest { } // Accept null timeout - new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 1, 0.1, null); + new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 1, 0.1, null); // Accept positive timeout - new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 1, 0.1, 1l); + new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 1, 0.1, 1l); } @@ -127,18 +133,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(channelName, null, 1,0, 0, 1, 0, timeout); + new ChannelAccessLinearActuator(cservice, channelName, 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(channelName, null, 1,0, 0, 10, 1, timeout); + new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 10, 1, timeout); } @@ -148,7 +154,7 @@ public class ChannelAccessLinearActuatorTest { */ @Test public void testSet() throws InterruptedException { - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 0.09999, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 0.09999, 0.1, timeout); actuator.set(); } @@ -159,7 +165,7 @@ public class ChannelAccessLinearActuatorTest { */ @Test(expected=IllegalStateException.class) public void testSetNoNext() throws InterruptedException { - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 0.09999, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 0.09999, 0.1, timeout); actuator.set(); actuator.set(); } @@ -170,7 +176,7 @@ public class ChannelAccessLinearActuatorTest { */ @Test public void testHasNextOneStep() throws InterruptedException { - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 0.09999, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 0.09999, 0.1, timeout); // Execute first set (because there is always a first move) actuator.set(); @@ -187,7 +193,7 @@ public class ChannelAccessLinearActuatorTest { */ @Test public void testHasNext() throws InterruptedException { - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, 0, 10, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, 0, 10, 0.1, timeout); int count = 0; int steps = (int) ((10-0)/0.1)+1; @@ -217,7 +223,7 @@ public class ChannelAccessLinearActuatorTest { for(double[] svalue: settings){ - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); int count =0; while(actuator.hasNext()){ @@ -236,10 +242,13 @@ public class ChannelAccessLinearActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#set()}. * Test actuator move startend ... + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testReverse() throws CAException, InterruptedException { + public void testReverse() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { List settings = new ArrayList(); // start end stepsize @@ -248,7 +257,7 @@ public class ChannelAccessLinearActuatorTest { for(double[] svalue: settings){ - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); actuator.init(); int count =0; @@ -316,10 +325,13 @@ public class ChannelAccessLinearActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessLinearActuator#set()}. * Test actuator move startend ... + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testReverseReset() throws CAException, InterruptedException { + public void testReverseReset() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { List settings = new ArrayList(); // start end stepsize @@ -328,7 +340,7 @@ public class ChannelAccessLinearActuatorTest { for(double[] svalue: settings){ - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, null, 1,0, svalue[0], svalue[1], svalue[2], timeout); actuator.init(); int count =0; @@ -403,9 +415,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(channelName, channelNameDone, doneValue, doneDelay, 0, 1, -0.1, timeout); + new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, 0, 1, -0.1, timeout); } /** @@ -413,29 +425,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(channelName, channelNameDone, doneValue, doneDelay, 0, 1, 0, timeout); + new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, 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(channelName, channelNameDone, doneValue, doneDelay, 0, 10, 1, timeout); + new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, 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 actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); // Simulate done channel doneChannel.setValue(0); @@ -458,12 +472,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 actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, 1.5, 0, 1, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, 1.5, 0, 1, 0.1, timeout); // Simulate done channel doneChannel.setValue(1); @@ -496,12 +512,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 actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); // Simulate done channel @@ -544,11 +562,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 actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); + public void testDoneHasNextOneStep() throws InterruptedException, ExecutionException, ChannelException { + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, 0, 0.09999, 0.1, timeout); // Simulate done channel doneChannel.setValue(0); @@ -578,11 +598,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 actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, 0, 10, 0.1, timeout); + public void testDoneHasNext() throws InterruptedException, ExecutionException, ChannelException { + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, 0, 10, 0.1, timeout); int count = 0; int steps = (int) ((10-0)/0.1)+1; @@ -619,10 +641,12 @@ public class ChannelAccessLinearActuatorTest { /** * Test method for {@link ch.psi.fda.core.actors.ChannelAccessGPLinearActuator#set()}. * Test actuator move startend ... + * @throws ChannelException + * @throws ExecutionException * @throws CAException */ @Test - public void testDoneSetLoop() throws CAException, InterruptedException { + public void testDoneSetLoop() throws InterruptedException, ExecutionException, ChannelException { List settings = new ArrayList(); // start end stepsize @@ -631,7 +655,7 @@ public class ChannelAccessLinearActuatorTest { for(double[] svalue: settings){ - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, svalue[0], svalue[1], svalue[2], timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, svalue[0], svalue[1], svalue[2], timeout); int count =0; while(actuator.hasNext()){ @@ -668,10 +692,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 +710,7 @@ public class ChannelAccessLinearActuatorTest { logger.info("Current channel value: "+channel.getValue()); - ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(channelName, channelNameDone, doneValue, doneDelay, start, end, stepSize, timeout); + ChannelAccessLinearActuator actuator = new ChannelAccessLinearActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, start, end, stepSize, timeout); while(actuator.hasNext()){ // Simulate done channel diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessTableActuatorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessTableActuatorTest.java index 9c52859..8036024 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessTableActuatorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ChannelAccessTableActuatorTest.java @@ -21,18 +21,21 @@ 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 @@ -50,16 +53,19 @@ public class ChannelAccessTableActuatorTest { private static final double doneDelay = 0; private static final Long timeout = 1800000l; // 30 minutes - private ChannelBean channel; - private ChannelBean doneChannel; + private Channel channel; + private Channel doneChannel; + + private ChannelService cservice; /** * @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, false)); + doneChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, channelNameDone, false)); } /** @@ -74,7 +80,7 @@ public class ChannelAccessTableActuatorTest { */ @Test public void testChannelAccessTableActuator() { - new ChannelAccessTableActuator(channelName, new double[]{1}, timeout); + new ChannelAccessTableActuator(cservice, channelName, new double[]{1}, timeout); } /** @@ -86,7 +92,7 @@ public class ChannelAccessTableActuatorTest { boolean flag = false; try{ // Need to return IllegalArgumentException due to negative Timeout - new ChannelAccessTableActuator(channelName, new double[]{1}, -1l); + new ChannelAccessTableActuator(cservice, channelName, new double[]{1}, -1l); } catch(IllegalArgumentException e){ flag=true; @@ -99,7 +105,7 @@ public class ChannelAccessTableActuatorTest { flag=false; try{ // Need to return IllegalArgumentException - new ChannelAccessTableActuator(channelName, new double[]{1}, 0l); + new ChannelAccessTableActuator(cservice, channelName, new double[]{1}, 0l); } catch(IllegalArgumentException e){ flag=true; @@ -109,10 +115,10 @@ public class ChannelAccessTableActuatorTest { } // Accept null timeout - new ChannelAccessTableActuator(channelName, new double[]{1}, null); + new ChannelAccessTableActuator(cservice, channelName, new double[]{1}, null); // Accept positive timeout - new ChannelAccessTableActuator(channelName, new double[]{1}, 1l); + new ChannelAccessTableActuator(cservice, channelName, new double[]{1}, 1l); } @@ -122,7 +128,7 @@ public class ChannelAccessTableActuatorTest { */ @Test(expected=IllegalArgumentException.class) public void testChannelAccessTableActuatorNull() { - new ChannelAccessTableActuator(channelName, null, timeout); + new ChannelAccessTableActuator(cservice, channelName, null, timeout); } /** @@ -131,17 +137,20 @@ public class ChannelAccessTableActuatorTest { */ @Test(expected=IllegalArgumentException.class) public void testChannelAccessTableActuatorEmptyTable() { - new ChannelAccessTableActuator(channelName, new double[0], timeout); + new ChannelAccessTableActuator(cservice, channelName, 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 actor = new ChannelAccessTableActuator(channelName, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, table, timeout); int count=0; while(actor.hasNext()){ @@ -166,7 +175,7 @@ public class ChannelAccessTableActuatorTest { @Test(expected=RuntimeException.class) public void testSetFail() throws InterruptedException { double[] table = new double[]{1}; - ChannelAccessTableActuator actor = new ChannelAccessTableActuator(channelName, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, table, timeout); actor.set(); // This set() call has to fail with an RuntimeException @@ -181,7 +190,7 @@ public class ChannelAccessTableActuatorTest { public void testHasNext() throws InterruptedException { double[] table = new double[]{1}; - ChannelAccessTableActuator actor = new ChannelAccessTableActuator(channelName, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, table, timeout); actor.set(); boolean next = actor.hasNext(); @@ -192,12 +201,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 actor = new ChannelAccessTableActuator(channelName, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, table, timeout); actor.init(); int count=0; @@ -237,12 +249,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 actor = new ChannelAccessTableActuator(channelName, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, table, timeout); actor.init(); int count=0; @@ -287,7 +302,7 @@ public class ChannelAccessTableActuatorTest { */ @Test public void testDoneChannelAccessTableActuator() { - new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, new double[]{1}, timeout); + new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, new double[]{1}, timeout); } /** @@ -296,7 +311,7 @@ public class ChannelAccessTableActuatorTest { */ @Test(expected=IllegalArgumentException.class) public void testDoneChannelAccessTableActuatorNull() { - new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, null, timeout); + new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, null, timeout); } /** @@ -305,17 +320,20 @@ public class ChannelAccessTableActuatorTest { */ @Test(expected=IllegalArgumentException.class) public void testDoneChannelAccessTableActuatorEmptyTable() { - new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, new double[0], timeout); + new ChannelAccessTableActuator(cservice, channelName, channelNameDone, 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 actor = new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, table, timeout); int count=0; while(actor.hasNext()){ @@ -349,12 +367,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 testDoneDelay() throws CAException, InterruptedException { + public void testDoneDelay() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { double[] table = new double[]{1,2,3,4,5,6}; - ChannelAccessTableActuator actor = new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, 0.1, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, 0.1, table, timeout); int count=0; long start = System.currentTimeMillis(); @@ -398,12 +419,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 actor = new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, table, timeout); // Simulate done channel doneChannel.setValue(0); new Thread(new Runnable() { @@ -442,13 +465,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 actor = new ChannelAccessTableActuator(channelName, channelNameDone, doneValue, doneDelay, table, timeout); + ChannelAccessTableActuator actor = new ChannelAccessTableActuator(cservice, channelName, channelNameDone, doneValue, doneDelay, table, timeout); // Simulate done channel doneChannel.setValue(0); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ComplexActorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ComplexActorTest.java index 25e8805..eae0ca4 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ComplexActorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/actors/ComplexActorTest.java @@ -31,6 +31,8 @@ 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.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; /** * Prerequisites for this test are: @@ -45,12 +47,14 @@ public class ComplexActorTest { 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(); } /** @@ -69,9 +73,9 @@ public class ComplexActorTest { ComplexActuator actuator = new ComplexActuator(); - actuator.getActors().add(new ChannelAccessLinearActuator(TestChannels.ANALOG_OUT, null, 1,0, 0, 0.09999, 0.1, timeout)); - actuator.getActors().add(new ChannelAccessLinearActuator(TestChannels.ANALOG_OUT, null, 1,0, 1, 2, 0.1, timeout)); - actuator.getActors().add(new ChannelAccessLinearActuator(TestChannels.ANALOG_OUT, null, 1,0, -1, -2, 0.1, timeout)); + actuator.getActors().add(new ChannelAccessLinearActuator(cservice, TestChannels.ANALOG_OUT, null, 1,0, 0, 0.09999, 0.1, timeout)); + actuator.getActors().add(new ChannelAccessLinearActuator(cservice, TestChannels.ANALOG_OUT, null, 1,0, 1, 2, 0.1, timeout)); + actuator.getActors().add(new ChannelAccessLinearActuator(cservice, TestChannels.ANALOG_OUT, null, 1,0, -1, -2, 0.1, timeout)); // Initialize actuator actuator.init(); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/guard/ChannelAccessGuardTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/guard/ChannelAccessGuardTest.java index 14fa0ee..e229bdf 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/guard/ChannelAccessGuardTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/guard/ChannelAccessGuardTest.java @@ -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,8 +34,11 @@ 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 @@ -43,11 +46,13 @@ import ch.psi.jcae.ChannelBeanFactory; */ public class ChannelAccessGuardTest { + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -60,17 +65,20 @@ public class ChannelAccessGuardTest { /** * 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 { + public void testCheck() throws InterruptedException, ExecutionException, ChannelException, TimeoutException { String guardChannel = TestChannels.ANALOG_OUT; Integer channelOkValue = 10; List conditions = new ArrayList(); - conditions.add(new ChannelAccessGuardCondition(guardChannel, channelOkValue)); + conditions.add(new ChannelAccessGuardCondition(cservice, guardChannel, channelOkValue)); Guard guard = new ChannelAccessGuard(conditions ); - ChannelBean b = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, guardChannel, false); + Channel b = cservice.createChannel(new ChannelDescriptor<>(Integer.class, guardChannel, false)); b.setValue(channelOkValue); guard.init(); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java index 7ffac80..b4387b6 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/ActorSensorLoopTest.java @@ -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 @@ -66,20 +69,21 @@ public class ActorSensorLoopTest { private static final Long timeout = 1800000l; // 30 minutes private ActorSensorLoop loopOne; + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { - + cservice = new DefaultChannelService(); loopOne = new ActorSensorLoop(); - ChannelAccessLinearActuator a = new ChannelAccessLinearActuator(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 a = new ChannelAccessLinearActuator(cservice, aoChannel, null, 1,0, 0, 10, 0.1, timeout); // Positioner + ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor(cservice, "id0", boChannel); // Positioner Readback + ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor(cservice, "id1", aoChannel); // Scalar Detector + ChannelAccessStringSensor s1string = new ChannelAccessStringSensor(cservice, "id3", boChannel+".NAME"); // Scalar String Detector + ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor(cservice, "id2", wfChannel, 10); loopOne.getActors().add(a); loopOne.getSensors().add(s); @@ -140,8 +144,8 @@ public class ActorSensorLoopTest { 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(cservice, "id0", boChannel); // Positioner Readback + ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor(cservice, "id1", aoChannel); // Scalar Detector 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 ChannelException + * @throws ExecutionException + * @throws TimeoutException * @throws CAException */ @Test - public void testExecuteGuard() throws InterruptedException, CAException { + public void testExecuteGuard() throws InterruptedException, ExecutionException, ChannelException, TimeoutException { ActorSensorLoop loop = new ActorSensorLoop(); - ChannelAccessLinearActuator a = new ChannelAccessLinearActuator(aoChannel, null, 1,0, 0, 1.5, 0.1,timeout); // Positioner + ChannelAccessLinearActuator a = new ChannelAccessLinearActuator(cservice, 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(cservice, "id0", aoChannel); // Positioner Readback + ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor(cservice, "id1", boChannel); // Scalar Detector + ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor(cservice, "id2", wfChannel, 10); loop.getActors().add(a); loop.getPostActorActions().add(new Delay(500)); @@ -189,11 +196,11 @@ public class ActorSensorLoopTest { // Guard final Integer okValue = 0; List conditions = new ArrayList(); - conditions.add(new ChannelAccessGuardCondition(boChannel, new Integer(0))); + conditions.add(new ChannelAccessGuardCondition(cservice, boChannel, new Integer(0))); Guard guard = new ChannelAccessGuard(conditions); loop.setGuard(guard); - final ChannelBean b = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, boChannel, false); + final Channel b = cservice.createChannel(new ChannelDescriptor<>(Integer.class, boChannel, false)); Thread tguard = new Thread(new Runnable() { @@ -253,16 +260,16 @@ public class ActorSensorLoopTest { @Test - public void testParallelSet() throws InterruptedException, CAException { + public void testParallelSet() throws InterruptedException { final int steps = 2; final HashMap timestamps = new HashMap(); ActorSensorLoop loop = new ActorSensorLoop(); - ChannelAccessLinearActuator a = new ChannelAccessLinearActuator(aoChannel, null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner + ChannelAccessLinearActuator a = new ChannelAccessLinearActuator(cservice, aoChannel, null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner - ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", aoChannel); // Positioner Readback + ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor(cservice, "id0", aoChannel); // Positioner Readback loop.getActors().add(a); loop.getActors().add(new Actor() { diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java index 11b280e..8f7e4d8 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java @@ -21,9 +21,9 @@ package ch.psi.fda.core.loops; import static org.junit.Assert.*; -import gov.aps.jca.CAException; - 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,8 +42,11 @@ 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 @@ -88,15 +91,17 @@ public class OTFLoopTest { private OTFLoop loopZigZag; private OTFLoop loop; - private ChannelBean statusChannel; + private Channel statusChannel; + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); - statusChannel = ChannelBeanFactory.getFactory().createChannelBean(Integer.class, configuration.getOtfPrefix()+":USTAT", false); + statusChannel = cservice.createChannel(new ChannelDescriptor<>(Integer.class, configuration.getOtfPrefix()+":USTAT", false)); OTFActuator actor = new OTFActuator("id", configuration.getMotor1(), null, 0, 8, 0.5, 0.5, 0); OTFReadbackSensor s1 = new OTFReadbackSensor("id0"); @@ -107,7 +112,7 @@ public class OTFLoopTest { // ZigZag loop - loopZigZag = new OTFLoop(configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), true); + loopZigZag = new OTFLoop(cservice, configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), true); loopZigZag.setActor(actor); loopZigZag.getSensors().add(s1); loopZigZag.getSensors().add(s2); @@ -117,7 +122,7 @@ public class OTFLoopTest { // Normal loop - loop = new OTFLoop(configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), false); + loop = new OTFLoop(cservice, configuration.getOtfPrefix(), configuration.getServer(), configuration.getShare(), configuration.getSmbShare(), false); loop.setActor(actor); loop.getSensors().add(s1); loop.getSensors().add(s2); @@ -136,10 +141,13 @@ public class OTFLoopTest { /** * 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 +166,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(); @@ -181,10 +192,13 @@ public class OTFLoopTest { /** * Test method for {@link ch.psi.fda.core.loops.OTFLoop#execute()}. * Test abort functionality while executing an OTF scan + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testExecuteAbort() throws CAException, InterruptedException { + public void testExecuteAbort() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { // Data collector thread Thread t = new Thread(new TestCollector(loop.getDataQueue().getQueue())); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java index e230874..f96f818 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java @@ -20,16 +20,17 @@ package ch.psi.fda.core.loops.cr; -import gov.aps.jca.CAException; - import java.util.ArrayList; +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.TimeoutException; import java.util.logging.Logger; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import ch.psi.fda.TestConfiguration; @@ -41,7 +42,9 @@ import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; 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; +import ch.psi.jcae.impl.DefaultChannelService; /** * @author ebner @@ -51,12 +54,13 @@ public class ParallelCrlogicTest { // Get Logger private static final Logger logger = Logger.getLogger(ParallelCrlogicTest.class.getName()); - + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -68,7 +72,7 @@ public class ParallelCrlogicTest { // @Ignore @Test(timeout=60000) - public void testExecute() throws InterruptedException, CAException{ + public void testExecute() throws InterruptedException, ChannelException, TimeoutException, ExecutionException{ TestConfiguration c = TestConfiguration.getInstance(); @@ -82,18 +86,18 @@ public class ParallelCrlogicTest { double additionalBacklash = 0; List sensors = new ArrayList(); - ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("mot1", c.getMotor1()+".RVAL"); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("mot2", c.getMotor1()+".RBV"); - ChannelAccessDoubleSensor s3 = new ChannelAccessDoubleSensor("mot2", "ARIDI-PCT:CURRENT"); + ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor(cservice, "mot1", c.getMotor1()+".RVAL"); + ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor(cservice, "mot2", c.getMotor1()+".RBV"); + ChannelAccessDoubleSensor s3 = new ChannelAccessDoubleSensor(cservice, "mot2", "ARIDI-PCT:CURRENT"); sensors.add(s1); sensors.add(s2); sensors.add(s3); - ScrlogicLoop scrlogic = new ScrlogicLoop(sensors); + ScrlogicLoop scrlogic = new ScrlogicLoop(cservice, sensors); - CrlogicLoop crlogic = new CrlogicLoop(c.getCrlogicPrefix(), c.getServer(), c.getShare(), c.getSmbShare(), zigZag); + CrlogicLoop crlogic = new CrlogicLoop(cservice, c.getCrlogicPrefix(), c.getServer(), c.getShare(), c.getSmbShare(), zigZag); crlogic.setActor(new OTFActuator("cmot", c.getMotor1(), readback, start, end, stepSize, integrationTime, additionalBacklash)); crlogic.getSensors().add(new OTFNamedChannelSensor("trigger", "TRIGGER0")); crlogic.getSensors().add(new OTFScalerChannelSensor("scaler0", 0)); @@ -103,13 +107,16 @@ public class ParallelCrlogicTest { // Initialize scaler template VSC16ScalerChannelsTemplate scalertemplate = new VSC16ScalerChannelsTemplate(); - ChannelBeanFactory.getFactory().createChannelBeans(scalertemplate, c.getPrefixScaler()); + Map ma = new HashMap<>(); + ma.put("PREFIX", c.getPrefixScaler()); + System.out.println(c.getPrefixScaler()); + cservice.createAnnotatedChannels(scalertemplate, ma); ParallelCrlogic pcrlogic = new ParallelCrlogic(crlogic, scrlogic); logger.info("Start scaler"); - scalertemplate.getCommand().setValueNoWait(VSC16ScalerChannelsTemplate.Command.Count.ordinal()); + scalertemplate.getCommand().setValueAsync(VSC16ScalerChannelsTemplate.Command.Count.ordinal()); pcrlogic.prepare(); pcrlogic.execute(); @@ -127,7 +134,7 @@ public class ParallelCrlogicTest { } // Destroy scaler template - ChannelBeanFactory.getFactory().destroyChannelBeans(scalertemplate); + cservice.destroyAnnotatedChannels(scalertemplate); pcrlogic.destroy(); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java index 84e3fd4..c2f4853 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java @@ -19,8 +19,6 @@ package ch.psi.fda.core.loops.cr; -import gov.aps.jca.CAException; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; @@ -34,8 +32,10 @@ import ch.psi.fda.core.Sensor; 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.ChannelBeanFactory; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; /** * @author ebner @@ -43,11 +43,13 @@ import ch.psi.jcae.ChannelBeanFactory; */ public class ScrlogicLoopTest { + private ChannelService cservice; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } /** @@ -63,20 +65,20 @@ public class ScrlogicLoopTest { * @throws CAException */ @Test - public void testExecute() throws InterruptedException, CAException { + public void testExecute() throws InterruptedException { System.out.println("For this test the motor MTEST-HW3:MOT1 need to be moved manually"); List sensors = new ArrayList(); - ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("mot1", "MTEST-HW3:MOT1.RBV"); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("mot2", "MTEST-HW3:MOT1"); + ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor(cservice, "mot1", "MTEST-HW3:MOT1.RBV"); + ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor(cservice, "mot2", "MTEST-HW3:MOT1"); sensors.add(s1); sensors.add(s2); - final ScrlogicLoop logic = new ScrlogicLoop(sensors); + final ScrlogicLoop logic = new ScrlogicLoop(cservice, sensors); for(int i=0;i<2;i++){ @@ -104,7 +106,7 @@ public class ScrlogicLoopTest { @Override public void run() { try{ - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, "MTEST-HW3:MOT1", false); + Channel channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false)); // Wait some time until Thread.sleep(100); channel.setValue(1.5); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/manipulator/ManipulatorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/manipulator/ManipulatorTest.java index 6ab9024..dd77105 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/manipulator/ManipulatorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/manipulator/ManipulatorTest.java @@ -20,12 +20,13 @@ package ch.psi.fda.core.manipulator; 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.LinkedBlockingQueue; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import org.junit.After; @@ -46,8 +47,11 @@ 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; /** * @author ebner @@ -58,12 +62,14 @@ public class ManipulatorTest { // Get Logger private static Logger logger = Logger.getLogger(ManipulatorTest.class.getName()); + private ChannelService cservice; + /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { - + cservice = new DefaultChannelService(); } /** @@ -85,7 +91,7 @@ public class ManipulatorTest { String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); // This constructor need to throw an IllegalArgumentException as there is no component // id "myid" which is expected in the mapping @@ -110,7 +116,7 @@ public class ManipulatorTest { String script = "import math\ndef process():\n return 0.0"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -135,7 +141,7 @@ public class ManipulatorTest { String script = "import math\ndef process():\n return 0.0"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -163,7 +169,7 @@ public class ManipulatorTest { String script = "import math\ndef process(o ,c):\n return math.cos(c) + math.sin(o)"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -190,7 +196,7 @@ public class ManipulatorTest { String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -256,7 +262,7 @@ public class ManipulatorTest { String script = "import math\ndef process(o):\n return 1"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -335,7 +341,7 @@ public class ManipulatorTest { String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)"; List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -401,7 +407,7 @@ public class ManipulatorTest { List mapping = new ArrayList(); mapping.add(new JythonParameterMappingID("o", "myid")); mapping.add(new JythonParameterMappingID("c", "myid2")); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); @@ -459,13 +465,16 @@ 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, ChannelException, TimeoutException, ExecutionException { Double setValue = 12.22; - ChannelBean cbean = ChannelBeanFactory.getFactory().createChannelBean(Double.class, TestChannels.ANALOG_OUT, false); + Channel cbean = new DefaultChannelService().createChannel(new ChannelDescriptor(Double.class, TestChannels.ANALOG_OUT, false)); DataMessageMetadata dmm = new DataMessageMetadata(); dmm.getComponents().add(new ComponentMetadata("myid")); @@ -484,7 +493,7 @@ public class ManipulatorTest { mapping.add(new JythonParameterMappingID("o", "myid")); mapping.add(new JythonParameterMappingID("c", "myid2")); mapping.add(new JythonParameterMappingChannel("d", TestChannels.ANALOG_OUT, Double.class)); - JythonManipulation manipulation = new JythonManipulation(id, script, mapping); + JythonManipulation manipulation = new JythonManipulation(cservice, id, script, mapping); List manipulations = new ArrayList(); manipulations.add(manipulation); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java index eed852c..4aea4a3 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleArraySensorTest.java @@ -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,10 @@ 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.impl.DefaultChannelService; /** * Test class for the ScalarDoubleSensorChannelAccess class. @@ -64,11 +68,14 @@ public class ChannelAccessDoubleArraySensorTest { /** * Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}. * @throws CAException + * @throws TimeoutException + * @throws ChannelException + * @throws ExecutionException */ @Test - public void testRead() throws CAException, InterruptedException { - ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor("id0", channelName, numberOfPoints); - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(double[].class, channelName, false); + public void testRead() throws InterruptedException, ChannelException, TimeoutException, ExecutionException { + ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor(new DefaultChannelService(), "id0", channelName, numberOfPoints); + Channel channel = new DefaultChannelService().createChannel(new ChannelDescriptor(double[].class, channelName, false)); // Prepare sensor channel double[] setValue = new double[] { 0.1,0.2,0.3,4,5,6,77,88,99,10.2}; diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java index 5e71912..c3523dc 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessDoubleSensorTest.java @@ -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,10 @@ 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.impl.DefaultChannelService; /** * Test class for the ScalarDoubleSensorChannelAccess class. @@ -62,12 +66,15 @@ public class ChannelAccessDoubleSensorTest { /** * Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}. + * @throws ChannelException + * @throws ExecutionException + * @throws TimeoutException * @throws CAException */ @Test - public void testRead() throws CAException, InterruptedException { - ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor("id0", channelName); - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); + public void testRead() throws InterruptedException, ExecutionException, ChannelException, TimeoutException { + ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(new DefaultChannelService(), "id0", channelName); + Channel channel = new DefaultChannelService().createChannel(new ChannelDescriptor(Double.class, channelName, false)); // Prepare sensor channel Double setValue = 0.1d; diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java index 5ded394..e07994e 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ChannelAccessStringSensorTest.java @@ -30,6 +30,7 @@ import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestChannels; +import ch.psi.jcae.impl.DefaultChannelService; /** * Test class for the ScalarDoubleSensorChannelAccess class. @@ -64,7 +65,7 @@ public class ChannelAccessStringSensorTest { */ @Test public void testRead() throws CAException, InterruptedException { - ChannelAccessStringSensor sensor = new ChannelAccessStringSensor("id0", channelName); + ChannelAccessStringSensor sensor = new ChannelAccessStringSensor(new DefaultChannelService(), "id0", channelName); // Get sensor readout value String value = (String) sensor.read(); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java index 41eb035..f2ed786 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/sensors/ComplexSensorTest.java @@ -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,10 @@ 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.impl.DefaultChannelService; /** * Test class for the ScalarDoubleSensorChannelAccess class. @@ -66,13 +70,16 @@ public class ComplexSensorTest { /** * Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}. * @throws CAException + * @throws TimeoutException + * @throws ChannelException + * @throws ExecutionException */ @Test - public void testRead() throws CAException, InterruptedException { + public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException { final HashMap timestamps = new HashMap(); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", channelName); + ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor(new DefaultChannelService(), "id0", channelName); ComplexSensor sensor = new ComplexSensor("id2", s1); // Add pre action @@ -112,7 +119,7 @@ public class ComplexSensorTest { }); // Create channel bean for test sensor channel - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, channelName, false); + Channel channel = new DefaultChannelService().createChannel(new ChannelDescriptor(Double.class, channelName, false)); // Prepare sensor channel Double setValue = 0.1d; From 4a597316695d0a5e90f45b38680ed1ad8dcce92c Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Fri, 26 Jul 2013 13:40:06 +0200 Subject: [PATCH 03/12] Started new concept to generate an acquisition script instead of using complex objects that need to be maintained by ourself --- ch.psi.fda/pom.xml | 3 +- .../ch/psi/fda/aq/AcquisitionEngineNG.java | 50 ++ .../main/java/ch/psi/fda/aq/ScanMapperNG.java | 490 ++++++++++++++++++ .../psi/fda/aq/AcquisitionEngineNGTest.java | 60 +++ .../java/ch/psi/fda/aq/ScanMapperNGTest.java | 98 ++++ 5 files changed, 700 insertions(+), 1 deletion(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java create mode 100644 ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java create mode 100644 ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index c4259a2..e6acca9 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -9,7 +9,7 @@ ch.psi jcae - 2.1.8 + 2.1.9 @@ -32,6 +32,7 @@ org.python jython + 2.5.3 diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java new file mode 100644 index 0000000..682a67a --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +/** + * @author ebner + * + */ +public class AcquisitionEngineNG { + + private ScriptEngine engine; + + public AcquisitionEngineNG() { + // Workaround for Jython memory leak + // http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/ + System.setProperty("python.options.internalTablesImpl", "weak"); + + // Create new script engine + this.engine = new ScriptEngineManager().getEngineByName("python"); + } + + public void execute(String script){ + try { + engine.eval(script); + } catch (ScriptException e) { + throw new RuntimeException("Action failed while executing the Jython script",e); + } + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java new file mode 100644 index 0000000..eeb63da --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java @@ -0,0 +1,490 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import ch.psi.fda.core.Actor; +import ch.psi.fda.core.actions.ChannelAccessCondition; +import ch.psi.fda.core.actions.ChannelAccessConditionAnd; +import ch.psi.fda.core.actions.ChannelAccessConditionOr; +import ch.psi.fda.core.actions.ChannelAccessConditionRegex; +import ch.psi.fda.core.actions.ChannelAccessPut; +import ch.psi.fda.core.actions.Delay; +import ch.psi.fda.core.actors.ChannelAccessFunctionActuator; +import ch.psi.fda.core.actors.ChannelAccessLinearActuator; +import ch.psi.fda.core.actors.ChannelAccessTableActuator; +import ch.psi.fda.core.actors.ComplexActuator; +import ch.psi.fda.core.actors.JythonFunction; +import ch.psi.fda.core.actors.PseudoActuatorSensor; +import ch.psi.fda.core.scripting.JythonParameterMappingChannel; +import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; +import ch.psi.fda.model.v1.Action; +import ch.psi.fda.model.v1.ArrayPositioner; +import ch.psi.fda.model.v1.ChannelAction; +import ch.psi.fda.model.v1.ChannelParameterMapping; +import ch.psi.fda.model.v1.Configuration; +import ch.psi.fda.model.v1.ContinuousDimension; +import ch.psi.fda.model.v1.Dimension; +import ch.psi.fda.model.v1.DiscreteStepDimension; +import ch.psi.fda.model.v1.DiscreteStepPositioner; +import ch.psi.fda.model.v1.FunctionPositioner; +import ch.psi.fda.model.v1.LinearPositioner; +import ch.psi.fda.model.v1.PseudoPositioner; +import ch.psi.fda.model.v1.Region; +import ch.psi.fda.model.v1.RegionPositioner; +import ch.psi.fda.model.v1.Scan; +import ch.psi.fda.model.v1.ScriptAction; +import ch.psi.fda.model.v1.ShellAction; + +/** + * @author ebner + * + */ +public class ScanMapperNG { + + private static final String INDENT = " "; + + private StringBuilder script = new StringBuilder(); + private Set imports = new HashSet<>(); + private String indentation=""; + + + + public void map(Configuration configuration){ + + Scan scan = configuration.getScan(); + mapActions(scan.getPreAction()); + + + // Bring the dimensions into the correct order and then map them + // to the script + List dimensions = new ArrayList<>(); + int size = scan.getDimension().size(); + for(int i=size-1; i>=0; i--){ + dimensions.add(scan.getDimension().get(i)); + } + // Continuous dimensions are always at the very end + if(scan.getCdimension()!=null){ + dimensions.add(scan.getCdimension()); + } + mapDimensions(dimensions, 0); + + + // map + mapActions(scan.getPostAction()); + + // TODO CONSIDER TO PROVIDE RESOURCE MAP AND SCRIPT IN ONE OBJECT AS RETURN TYPE + // WOULD MAKE MORE SENSE + } + + + /** + * Get the generated script + * @return + */ + public String getScript(){ + StringBuilder scriptlines= new StringBuilder(); + for(String s: imports){ + scriptlines.append("import "+s+"\n"); + } + scriptlines.append(script); + return scriptlines.toString(); + } + + private void mapDimensions(List dimensions, int index) { + Dimension dimension = dimensions.get(index); + if (dimension instanceof DiscreteStepDimension) { + DiscreteStepDimension d = (DiscreteStepDimension) dimension; + + mapActions(d.getPreAction()); + // TODO Do mapping + script.append(indentation + "for i in test\n"); + indentation = indentation + INDENT; + mapPositioners(d.getPositioner()); + mapActions(d.getAction()); + + // TODO map guard and sensors + + // Next dimension + if((index+1) actions){ + for(Action action: actions){ + if(action instanceof ChannelAction){ + ChannelAction ca = (ChannelAction) action; + switch (ca.getOperation()) { + case "put": + break; + case "putq": + break; + case "wait": + break; + case "waitREGEX": + break; + case "waitOR": + break; + case "waitAND": + break; + } + } + else if(action instanceof ShellAction){ + ShellAction saction = (ShellAction) action; + // TODO Need to indicate that shell resource is required + script.append(indentation+String.format("shell.execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue())); + } + else if(action instanceof ScriptAction){ + ScriptAction saction = (ScriptAction) action; + + // TODO Need to indicate that that mapped resources are required + // Read script line by line and prepend the current indentation level + String[] lines = saction.getScript().split(System.getProperty("line.separator")); + for(String s:lines){ + script.append(indentation+s); + } + script.append(indentation+"\n"); + } + } + } + + public void mapPositioners(List positioners) { +// for (DiscreteStepPositioner p : positioners) { +// +// if (p.getSettlingTime() > stime) { +// stime = p.getSettlingTime(); +// } +// +// if (p instanceof LinearPositioner) { +// LinearPositioner lp = (LinearPositioner) p; +// ChannelAccessLinearActuator a; +// if (lp.getType().equals("String")) { +// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); +// } else if (lp.getType().equals("Double")) { +// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), +// lp.getStepSize(), moveTimeout); +// } else { +// // Default +// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), +// lp.getStepSize(), moveTimeout); +// } +// +// a.setAsynchronous(lp.isAsynchronous()); +// Actor actuator = a; +// +// aLoop.getActors().add(actuator); +// +// // Add a sensor for the readback +// String name = lp.getReadback(); +// if (name == null) { +// name = lp.getName(); +// } +// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); +// aLoop.getSensors().add(sensor); +// } else if (p instanceof FunctionPositioner) { +// FunctionPositioner lp = (FunctionPositioner) p; +// +// // Create function object +// JythonFunction function = mapFunction(lp.getFunction()); +// +// // Create actuator +// ChannelAccessFunctionActuator a; +// if (lp.getType().equals("String")) { +// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), +// moveTimeout); +// } else if (lp.getType().equals("Double")) { +// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), +// lp.getStepSize(), moveTimeout); +// } else { +// // Default +// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), +// lp.getStepSize(), moveTimeout); +// } +// +// a.setAsynchronous(lp.isAsynchronous()); +// Actor actuator = a; +// +// aLoop.getActors().add(actuator); +// +// // Add a sensor for the readback +// String name = lp.getReadback(); +// if (name == null) { +// name = lp.getName(); +// } +// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); +// aLoop.getSensors().add(sensor); +// } else if (p instanceof ArrayPositioner) { +// ArrayPositioner ap = (ArrayPositioner) p; +// String[] positions = (ap.getPositions().trim()).split(" +"); +// double[] table = new double[positions.length]; +// for (int i = 0; i < positions.length; i++) { +// table[i] = Double.parseDouble(positions[i]); +// } +// +// ChannelAccessTableActuator a; +// if (p.getType().equals("String")) { +// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); +// } else if (p.getType().equals("Double")) { +// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); +// } else { +// // Default +// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); +// } +// +// a.setAsynchronous(p.isAsynchronous()); +// Actor actuator = a; +// +// aLoop.getActors().add(actuator); +// +// // Add a sensor for the readback +// String name = ap.getReadback(); +// if (name == null) { +// name = ap.getName(); +// } +// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, ap.getId(), name); +// aLoop.getSensors().add(sensor); +// } else if (p instanceof RegionPositioner) { +// RegionPositioner rp = (RegionPositioner) p; +// +// ComplexActuator actuator = new ComplexActuator(); +// /* +// * Regions are translated into a complex actor consisting of a +// * LinearActuator If consecutive regions are overlapping, i.e. +// * end point of region a equals the start point of region b then +// * the start point for the LinearActuator of region b is changes +// * to its next step (start+/-stepSize depending on whether end +// * position of the region is > or < start of the region) +// */ +// Region lastRegion = null; +// for (Region r : rp.getRegion()) { +// // Normal region +// if (r.getFunction() == null) { +// +// // Check whether regions are consecutive +// double start = r.getStart(); +// if (lastRegion != null && start == lastRegion.getEnd()) { // TODO +// // verify +// // whether +// // double +// // comparison +// // is +// // ok +// if (r.getStart() < r.getEnd()) { +// start = start + r.getStepSize(); +// } else { +// start = start - r.getStepSize(); +// } +// } +// +// // Create actuator +// ChannelAccessLinearActuator act; +// if (rp.getType().equals("String")) { +// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); +// } else if (rp.getType().equals("Double")) { +// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), +// r.getStepSize(), moveTimeout); +// } else { +// // Default +// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), +// r.getStepSize(), moveTimeout); +// } +// +// act.setAsynchronous(rp.isAsynchronous()); +// Actor a = act; +// +// ComplexActuator ca = new ComplexActuator(); +// ca.getActors().add(a); +// ca.getPreActions().addAll(mapActions(r.getPreAction())); +// actuator.getActors().add(ca); +// lastRegion = r; +// } else { +// // Function based region +// +// // Cannot check whether the regions are consecutive as +// // the function +// // used might change the start value to something else +// // [THIS LIMITATION NEEDS TO BE SOMEHOW RESOLVED IN THE +// // NEXT VERSIONS] +// JythonFunction function = mapFunction(r.getFunction()); +// ChannelAccessFunctionActuator act; +// if (rp.getType().equals("String")) { +// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), +// r.getStepSize(), moveTimeout); +// } else if (rp.getType().equals("Double")) { +// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), +// r.getEnd(), r.getStepSize(), moveTimeout); +// } else { +// // Default +// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), +// r.getEnd(), r.getStepSize(), moveTimeout); +// } +// +// act.setAsynchronous(rp.isAsynchronous()); +// Actor a = act; +// +// ComplexActuator ca = new ComplexActuator(); +// ca.getActors().add(a); +// ca.getPreActions().addAll(mapActions(r.getPreAction())); +// actuator.getActors().add(ca); +// lastRegion = r; +// } +// } +// aLoop.getActors().add(actuator); +// +// // Add a sensor for the readback +// String name = rp.getReadback(); +// if (name == null) { +// name = rp.getName(); +// } +// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, rp.getId(), name); +// aLoop.getSensors().add(sensor); +// } else if (p instanceof PseudoPositioner) { +// PseudoPositioner pp = (PseudoPositioner) p; +// PseudoActuatorSensor actorSensor = new PseudoActuatorSensor(pp.getId(), pp.getCounts()); +// +// // Register as actor +// aLoop.getActors().add(actorSensor); +// +// // Register as sensor +// aLoop.getSensors().add(actorSensor); +// } else { +// // Not supported +// logger.warning("Mapping for " + p.getClass().getName() + " not available"); +// } +// } + } + + /** + * Get unique variable names that do not collide with others. (at least have an extreme unlikeness to do so) + * @return + */ + private String getUniqueVariableName(){ + return "v"+UUID.randomUUID().toString().replaceAll("-", ""); + } +// +// String operation = ca.getOperation(); // Default = put +// String type=ca.getType(); // Default = String +// +// if(operation.equals("put")){ +// Long timeout = null; +// if(ca.getTimeout()!=null){ +// timeout = Math.round(ca.getTimeout()*1000); +// } +// if(type.equals("String")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), false, timeout)); +// } +// else if(type.equals("Integer")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), false, timeout)); +// } +// else if(type.equals("Double")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), false, timeout)); +// } +// } +// else if(operation.equals("putq")){ +// if(type.equals("String")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), true, null)); +// } +// else if(type.equals("Integer")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), true, null)); +// } +// else if(type.equals("Double")){ +// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), true, null)); +// } +// } +// else if(operation.equals("wait")){ +// Long timeout = null ; // Default timeout = wait forever +// if(ca.getTimeout()!=null){ +// timeout = Math.round(ca.getTimeout()*1000); +// } +// if(type.equals("String")){ +// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), ca.getValue(), timeout)); +// } +// else if(type.equals("Integer")){ +// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); +// } +// else if(type.equals("Double")){ +// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Double(ca.getValue()), timeout)); +// } +// } +// else if(operation.equals("waitREGEX")){ +// Long timeout = null ; // Default timeout = wait forever +// if(ca.getTimeout()!=null){ +// timeout = Math.round(ca.getTimeout()*1000); +// } +// if(type.equals("String")){ +// alist.add(new ChannelAccessConditionRegex(cservice, ca.getChannel(), ca.getValue(), timeout)); +// } +// else{ +// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); +// } +// } +// else if(operation.equals("waitOR")){ +// Long timeout = null ; // Default timeout = wait forever +// if(ca.getTimeout()!=null){ +// timeout = Math.round(ca.getTimeout()*1000); +// } +// +// if(type.equals("Integer")){ +// alist.add(new ChannelAccessConditionOr(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); +// } +// else{ +// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); +// } +// } +// else if(operation.equals("waitAND")){ +// Long timeout = null ; // Default timeout = wait forever +// if(ca.getTimeout()!=null){ +// timeout = Math.round(ca.getTimeout()*1000); +// } +// if(type.equals("Integer")){ +// alist.add(new ChannelAccessConditionAnd(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); +// } +// else { +// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); +// } +// } +// else{ +// // Operation not supported +// logger.warning("Operation "+operation+" for action is not supported"); +// } +// +// // Translate delay attribute to delay action +// if(ca.getDelay()!=null){ +// Double x = ca.getDelay()*1000; +// alist.add(new Delay(x.longValue())); +// } +// +//} + +} diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java new file mode 100644 index 0000000..ba5387a --- /dev/null +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java @@ -0,0 +1,60 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @author ebner + * + */ +public class AcquisitionEngineNGTest { + + private AcquisitionEngineNG engine; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + engine = new AcquisitionEngineNG(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link ch.psi.fda.aq.AcquisitionEngineNG#execute(java.lang.String)}. + */ + @Test + public void testExecute() { +// engine.execute("import os"); + engine.execute("print 'hello'"); +// engine.execute("os.system('echo hello world this is a test')"); + } + +} diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java new file mode 100644 index 0000000..29ed1af --- /dev/null +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java @@ -0,0 +1,98 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import ch.psi.fda.model.v1.Configuration; +import ch.psi.fda.model.v1.DiscreteStepDimension; +import ch.psi.fda.model.v1.Scan; +import ch.psi.fda.model.v1.ScriptAction; +import ch.psi.fda.model.v1.ShellAction; +import ch.psi.fda.model.v1.Action; + +/** + * @author ebner + * + */ +public class ScanMapperNGTest { + + private ScanMapperNG mapper; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + mapper = new ScanMapperNG(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link ch.psi.fda.aq.ScanMapperNG#mapActions(java.util.List)}. + */ + @Test + public void testMap() { + System.out.println("juhu"+("This is a Java string".hashCode())); + + + Configuration config = new Configuration(); + config.setScan(new Scan()); + + ShellAction a = new ShellAction(); + a.setCommand("echo hello world this is a test"); + + config.getScan().getPreAction().add(a); + + + ScriptAction sa = new ScriptAction(); + sa.setScript("print 'hello'"); + + config.getScan().getPostAction().add(sa); + config.getScan().getPostAction().add(a); + + DiscreteStepDimension d = new DiscreteStepDimension(); + d.getPreAction().add(a); + d.getAction().add(sa); + d.getPostAction().add(a); + + config.getScan().getDimension().add(d); + config.getScan().getDimension().add(d); + + + mapper.map(config); + String script = mapper.getScript(); + + System.out.println(script); + } + +} From bc0763a22c0a5d0b1afaab6a6510ad0ea6813392 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Mon, 29 Jul 2013 11:18:20 +0200 Subject: [PATCH 04/12] Now all action related methods should work ... --- ch.psi.fda/pom.xml | 2 +- .../ch/psi/fda/aq/AcquisitionEngineNG.java | 51 +- .../main/java/ch/psi/fda/aq/ScanMapperNG.java | 757 +++++++++--------- .../java/ch/psi/fda/aq/ShellDescriptor.java | 28 + .../java/ch/psi/fda/aq/ShellResource.java | 59 ++ .../psi/fda/aq/AcquisitionEngineNGTest.java | 62 +- .../java/ch/psi/fda/aq/ScanMapperNGTest.java | 10 +- 7 files changed, 582 insertions(+), 387 deletions(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index e6acca9..24d7835 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -9,7 +9,7 @@ ch.psi jcae - 2.1.9 + 2.1.10 diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java index 682a67a..07abcf4 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java @@ -18,30 +18,65 @@ */ package ch.psi.fda.aq; +import java.util.Map; +import java.util.concurrent.TimeoutException; +import java.util.logging.Logger; + import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; + /** * @author ebner * */ public class AcquisitionEngineNG { - - private ScriptEngine engine; - - public AcquisitionEngineNG() { + + private static final Logger logger = Logger.getLogger(AcquisitionEngineNG.class.getName()); + + private ChannelService cservice; + + public AcquisitionEngineNG(ChannelService cservice) { + this.cservice = cservice; + // Workaround for Jython memory leak // http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/ System.setProperty("python.options.internalTablesImpl", "weak"); - - // Create new script engine - this.engine = new ScriptEngineManager().getEngineByName("python"); } - public void execute(String script){ + public void execute(Map resourceDescriptors, String script){ try { + ScriptEngine engine = new ScriptEngineManager().getEngineByName("python"); + + // Set logger + engine.put("logger", logger); + + // Retrieve and set resources + for(String k: resourceDescriptors.keySet()){ + if(resourceDescriptors.get(k) instanceof ChannelDescriptor){ + ChannelDescriptor descriptor = (ChannelDescriptor)resourceDescriptors.get(k); + try { + engine.put(k, cservice.createChannel(descriptor)); + } catch (ChannelException | InterruptedException | TimeoutException e) { + throw new RuntimeException("Unable to create resource for channel: "+descriptor.getName(),e); + } + } + else if(resourceDescriptors.get(k) instanceof ShellDescriptor){ + engine.put(k, new ShellResource()); + } + else{ + throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName()); + } + } + + // Execute script engine.eval(script); + + } catch (ScriptException e) { throw new RuntimeException("Action failed while executing the Jython script",e); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java index eeb63da..d573afc 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java @@ -19,100 +19,100 @@ package ch.psi.fda.aq; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.logging.Logger; -import ch.psi.fda.core.Actor; -import ch.psi.fda.core.actions.ChannelAccessCondition; -import ch.psi.fda.core.actions.ChannelAccessConditionAnd; -import ch.psi.fda.core.actions.ChannelAccessConditionOr; -import ch.psi.fda.core.actions.ChannelAccessConditionRegex; -import ch.psi.fda.core.actions.ChannelAccessPut; -import ch.psi.fda.core.actions.Delay; -import ch.psi.fda.core.actors.ChannelAccessFunctionActuator; -import ch.psi.fda.core.actors.ChannelAccessLinearActuator; -import ch.psi.fda.core.actors.ChannelAccessTableActuator; -import ch.psi.fda.core.actors.ComplexActuator; -import ch.psi.fda.core.actors.JythonFunction; -import ch.psi.fda.core.actors.PseudoActuatorSensor; -import ch.psi.fda.core.scripting.JythonParameterMappingChannel; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; import ch.psi.fda.model.v1.Action; -import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; -import ch.psi.fda.model.v1.ChannelParameterMapping; import ch.psi.fda.model.v1.Configuration; import ch.psi.fda.model.v1.ContinuousDimension; import ch.psi.fda.model.v1.Dimension; import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.DiscreteStepPositioner; -import ch.psi.fda.model.v1.FunctionPositioner; -import ch.psi.fda.model.v1.LinearPositioner; -import ch.psi.fda.model.v1.PseudoPositioner; -import ch.psi.fda.model.v1.Region; -import ch.psi.fda.model.v1.RegionPositioner; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.util.ComparatorAND; +import ch.psi.jcae.util.ComparatorOR; +import ch.psi.jcae.util.ComparatorREGEX; /** * @author ebner - * + * */ public class ScanMapperNG { + private static final Logger logger = Logger.getLogger(ScanMapperNG.class.getName()); + private static final String INDENT = " "; private StringBuilder script = new StringBuilder(); private Set imports = new HashSet<>(); - private String indentation=""; - - - - public void map(Configuration configuration){ - + private Map resourceDescriptors = new HashMap<>(); + + private String indentation = ""; + + public void map(Configuration configuration) { + Scan scan = configuration.getScan(); mapActions(scan.getPreAction()); - - // Bring the dimensions into the correct order and then map them + // Bring the dimensions into the correct order and then map them // to the script List dimensions = new ArrayList<>(); int size = scan.getDimension().size(); - for(int i=size-1; i>=0; i--){ + for (int i = size - 1; i >= 0; i--) { dimensions.add(scan.getDimension().get(i)); } // Continuous dimensions are always at the very end - if(scan.getCdimension()!=null){ + if (scan.getCdimension() != null) { dimensions.add(scan.getCdimension()); } mapDimensions(dimensions, 0); - - - // map + + // map mapActions(scan.getPostAction()); - - // TODO CONSIDER TO PROVIDE RESOURCE MAP AND SCRIPT IN ONE OBJECT AS RETURN TYPE + + // TODO CONSIDER TO PROVIDE RESOURCE MAP AND SCRIPT IN ONE OBJECT AS + // RETURN TYPE // WOULD MAKE MORE SENSE } - - + /** * Get the generated script + * * @return */ - public String getScript(){ - StringBuilder scriptlines= new StringBuilder(); - for(String s: imports){ - scriptlines.append("import "+s+"\n"); + public String getScript() { + StringBuilder scriptlines = new StringBuilder(); + for (String s : imports) { + scriptlines.append(s + "\n"); } scriptlines.append(script); return scriptlines.toString(); } + /** + * Get map of required resources + * @return + */ + public Map getResourceDescriptors(){ + return resourceDescriptors; + } + private void mapDimensions(List dimensions, int index) { + + if(dimensions.size()<1){ + logger.info("There are no dimensions to map"); + return; + } + Dimension dimension = dimensions.get(index); if (dimension instanceof DiscreteStepDimension) { DiscreteStepDimension d = (DiscreteStepDimension) dimension; @@ -125,12 +125,12 @@ public class ScanMapperNG { mapActions(d.getAction()); // TODO map guard and sensors - + // Next dimension - if((index+1) actions){ - for(Action action: actions){ - if(action instanceof ChannelAction){ + + private void mapActions(List actions) { + for (Action action : actions) { + if (action instanceof ChannelAction) { ChannelAction ca = (ChannelAction) action; + Class type = String.class; + long waitTimeout=1800000; // Max wait timeout is 30 minutes + if(ca.getTimeout()!=null){ + waitTimeout = ca.getTimeout().longValue()*1000; // wait timeout is currently in seconds + } + ca.getTimeout(); + switch (ca.getType()) { + case "Integer": + type = Integer.class; + break; + case "Double": + type = Double.class; + break; + } + String var = getChannelResourceVariable(ca.getChannel(), type, false); switch (ca.getOperation()) { case "put": + if(ca.getTimeout()==null){ + script.append(var+".setValue("+getPythonValue(ca.getValue(), type)+")\n"); + } else { + imports.add("from java.util.concurrent import TimeUnit"); + script.append(var+".setValueAsync("+getPythonValue(ca.getValue(), type)+").get("+ca.getTimeout()+", TimeUnit.MILLISECONDS)\n"); + } break; case "putq": + script.append(var+".setValueAsync("+getPythonValue(ca.getValue(), type)+")\n"); break; case "wait": + script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+waitTimeout+")\n"); break; case "waitREGEX": + imports.add("from"+ComparatorREGEX.class.getPackage().getName()+" import "+ComparatorREGEX.class.getName()); + script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorREGEX.class.getName()+"() "+waitTimeout+")\n"); break; case "waitOR": + imports.add("from"+ComparatorOR.class.getPackage().getName()+" import "+ComparatorOR.class.getName()); + script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorOR.class.getName()+"() "+waitTimeout+")\n"); break; case "waitAND": + imports.add("from"+ComparatorAND.class.getPackage().getName()+" import "+ComparatorAND.class.getName()); + script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorAND.class.getName()+"() "+waitTimeout+")\n"); + break; + default: + logger.warning("Operation - "+ca.getOperation()+" - is not supported"); + // TODO Eventually throw exception - have two modes one logging, one exception? break; } - } - else if(action instanceof ShellAction){ - ShellAction saction = (ShellAction) action; - // TODO Need to indicate that shell resource is required - script.append(indentation+String.format("shell.execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue())); - } - else if(action instanceof ScriptAction){ - ScriptAction saction = (ScriptAction) action; - - // TODO Need to indicate that that mapped resources are required - // Read script line by line and prepend the current indentation level - String[] lines = saction.getScript().split(System.getProperty("line.separator")); - for(String s:lines){ - script.append(indentation+s); + + // If delay is specified wait specified time + if (ca.getDelay() != null) { + imports.add("import time"); + script.append("time.sleep(" + (ca.getDelay()) + ")\n"); } - script.append(indentation+"\n"); + + } else if (action instanceof ShellAction) { + ShellAction saction = (ShellAction) action; + resourceDescriptors.put("shell", new ShellDescriptor()); + // TODO Need to indicate that shell resource is required + script.append(indentation + String.format("shell.execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue()?"True":"False")); + } else if (action instanceof ScriptAction) { + ScriptAction saction = (ScriptAction) action; + + // TODO Need to indicate that that mapped resources are required + // Read script line by line and prepend the current indentation + // level + String[] lines = saction.getScript().split(System.getProperty("line.separator")); + for (String s : lines) { + script.append(indentation + s); + } + script.append(indentation + "\n"); } } } - + public void mapPositioners(List positioners) { -// for (DiscreteStepPositioner p : positioners) { -// -// if (p.getSettlingTime() > stime) { -// stime = p.getSettlingTime(); -// } -// -// if (p instanceof LinearPositioner) { -// LinearPositioner lp = (LinearPositioner) p; -// ChannelAccessLinearActuator a; -// if (lp.getType().equals("String")) { -// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), lp.getStepSize(), moveTimeout); -// } else if (lp.getType().equals("Double")) { -// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), -// lp.getStepSize(), moveTimeout); -// } else { -// // Default -// a = new ChannelAccessLinearActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), lp.getStart(), lp.getEnd(), -// lp.getStepSize(), moveTimeout); -// } -// -// a.setAsynchronous(lp.isAsynchronous()); -// Actor actuator = a; -// -// aLoop.getActors().add(actuator); -// -// // Add a sensor for the readback -// String name = lp.getReadback(); -// if (name == null) { -// name = lp.getName(); -// } -// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); -// aLoop.getSensors().add(sensor); -// } else if (p instanceof FunctionPositioner) { -// FunctionPositioner lp = (FunctionPositioner) p; -// -// // Create function object -// JythonFunction function = mapFunction(lp.getFunction()); -// -// // Create actuator -// ChannelAccessFunctionActuator a; -// if (lp.getType().equals("String")) { -// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), lp.getStepSize(), -// moveTimeout); -// } else if (lp.getType().equals("Double")) { -// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Double.parseDouble(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), -// lp.getStepSize(), moveTimeout); -// } else { -// // Default -// a = new ChannelAccessFunctionActuator(cservice, lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), -// lp.getStepSize(), moveTimeout); -// } -// -// a.setAsynchronous(lp.isAsynchronous()); -// Actor actuator = a; -// -// aLoop.getActors().add(actuator); -// -// // Add a sensor for the readback -// String name = lp.getReadback(); -// if (name == null) { -// name = lp.getName(); -// } -// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, lp.getId(), name); -// aLoop.getSensors().add(sensor); -// } else if (p instanceof ArrayPositioner) { -// ArrayPositioner ap = (ArrayPositioner) p; -// String[] positions = (ap.getPositions().trim()).split(" +"); -// double[] table = new double[positions.length]; -// for (int i = 0; i < positions.length; i++) { -// table[i] = Double.parseDouble(positions[i]); -// } -// -// ChannelAccessTableActuator a; -// if (p.getType().equals("String")) { -// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); -// } else if (p.getType().equals("Double")) { -// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); -// } else { -// // Default -// a = new ChannelAccessTableActuator(cservice, p.getName(), p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), table, moveTimeout); -// } -// -// a.setAsynchronous(p.isAsynchronous()); -// Actor actuator = a; -// -// aLoop.getActors().add(actuator); -// -// // Add a sensor for the readback -// String name = ap.getReadback(); -// if (name == null) { -// name = ap.getName(); -// } -// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, ap.getId(), name); -// aLoop.getSensors().add(sensor); -// } else if (p instanceof RegionPositioner) { -// RegionPositioner rp = (RegionPositioner) p; -// -// ComplexActuator actuator = new ComplexActuator(); -// /* -// * Regions are translated into a complex actor consisting of a -// * LinearActuator If consecutive regions are overlapping, i.e. -// * end point of region a equals the start point of region b then -// * the start point for the LinearActuator of region b is changes -// * to its next step (start+/-stepSize depending on whether end -// * position of the region is > or < start of the region) -// */ -// Region lastRegion = null; -// for (Region r : rp.getRegion()) { -// // Normal region -// if (r.getFunction() == null) { -// -// // Check whether regions are consecutive -// double start = r.getStart(); -// if (lastRegion != null && start == lastRegion.getEnd()) { // TODO -// // verify -// // whether -// // double -// // comparison -// // is -// // ok -// if (r.getStart() < r.getEnd()) { -// start = start + r.getStepSize(); -// } else { -// start = start - r.getStepSize(); -// } -// } -// -// // Create actuator -// ChannelAccessLinearActuator act; -// if (rp.getType().equals("String")) { -// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, r.getEnd(), r.getStepSize(), moveTimeout); -// } else if (rp.getType().equals("Double")) { -// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), -// r.getStepSize(), moveTimeout); -// } else { -// // Default -// act = new ChannelAccessLinearActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), start, r.getEnd(), -// r.getStepSize(), moveTimeout); -// } -// -// act.setAsynchronous(rp.isAsynchronous()); -// Actor a = act; -// -// ComplexActuator ca = new ComplexActuator(); -// ca.getActors().add(a); -// ca.getPreActions().addAll(mapActions(r.getPreAction())); -// actuator.getActors().add(ca); -// lastRegion = r; -// } else { -// // Function based region -// -// // Cannot check whether the regions are consecutive as -// // the function -// // used might change the start value to something else -// // [THIS LIMITATION NEEDS TO BE SOMEHOW RESOLVED IN THE -// // NEXT VERSIONS] -// JythonFunction function = mapFunction(r.getFunction()); -// ChannelAccessFunctionActuator act; -// if (rp.getType().equals("String")) { -// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), function, r.getStart(), r.getEnd(), -// r.getStepSize(), moveTimeout); -// } else if (rp.getType().equals("Double")) { -// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), -// r.getEnd(), r.getStepSize(), moveTimeout); -// } else { -// // Default -// act = new ChannelAccessFunctionActuator(cservice, rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), rp.getDoneDelay(), function, r.getStart(), -// r.getEnd(), r.getStepSize(), moveTimeout); -// } -// -// act.setAsynchronous(rp.isAsynchronous()); -// Actor a = act; -// -// ComplexActuator ca = new ComplexActuator(); -// ca.getActors().add(a); -// ca.getPreActions().addAll(mapActions(r.getPreAction())); -// actuator.getActors().add(ca); -// lastRegion = r; -// } -// } -// aLoop.getActors().add(actuator); -// -// // Add a sensor for the readback -// String name = rp.getReadback(); -// if (name == null) { -// name = rp.getName(); -// } -// ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(cservice, rp.getId(), name); -// aLoop.getSensors().add(sensor); -// } else if (p instanceof PseudoPositioner) { -// PseudoPositioner pp = (PseudoPositioner) p; -// PseudoActuatorSensor actorSensor = new PseudoActuatorSensor(pp.getId(), pp.getCounts()); -// -// // Register as actor -// aLoop.getActors().add(actorSensor); -// -// // Register as sensor -// aLoop.getSensors().add(actorSensor); -// } else { -// // Not supported -// logger.warning("Mapping for " + p.getClass().getName() + " not available"); -// } -// } + // for (DiscreteStepPositioner p : positioners) { + // + // if (p.getSettlingTime() > stime) { + // stime = p.getSettlingTime(); + // } + // + // if (p instanceof LinearPositioner) { + // LinearPositioner lp = (LinearPositioner) p; + // ChannelAccessLinearActuator a; + // if (lp.getType().equals("String")) { + // a = new ChannelAccessLinearActuator(cservice, lp.getName(), + // lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), + // lp.getEnd(), lp.getStepSize(), moveTimeout); + // } else if (lp.getType().equals("Double")) { + // a = new ChannelAccessLinearActuator(cservice, lp.getName(), + // lp.getDone(), Double.parseDouble(lp.getDoneValue()), + // lp.getDoneDelay(), lp.getStart(), lp.getEnd(), + // lp.getStepSize(), moveTimeout); + // } else { + // // Default + // a = new ChannelAccessLinearActuator(cservice, lp.getName(), + // lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), + // lp.getStart(), lp.getEnd(), + // lp.getStepSize(), moveTimeout); + // } + // + // a.setAsynchronous(lp.isAsynchronous()); + // Actor actuator = a; + // + // aLoop.getActors().add(actuator); + // + // // Add a sensor for the readback + // String name = lp.getReadback(); + // if (name == null) { + // name = lp.getName(); + // } + // ChannelAccessDoubleSensor sensor = new + // ChannelAccessDoubleSensor(cservice, lp.getId(), name); + // aLoop.getSensors().add(sensor); + // } else if (p instanceof FunctionPositioner) { + // FunctionPositioner lp = (FunctionPositioner) p; + // + // // Create function object + // JythonFunction function = mapFunction(lp.getFunction()); + // + // // Create actuator + // ChannelAccessFunctionActuator a; + // if (lp.getType().equals("String")) { + // a = new ChannelAccessFunctionActuator(cservice, lp.getName(), + // lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, + // lp.getStart(), lp.getEnd(), lp.getStepSize(), + // moveTimeout); + // } else if (lp.getType().equals("Double")) { + // a = new ChannelAccessFunctionActuator(cservice, lp.getName(), + // lp.getDone(), Double.parseDouble(lp.getDoneValue()), + // lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), + // lp.getStepSize(), moveTimeout); + // } else { + // // Default + // a = new ChannelAccessFunctionActuator(cservice, + // lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), + // lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), + // lp.getStepSize(), moveTimeout); + // } + // + // a.setAsynchronous(lp.isAsynchronous()); + // Actor actuator = a; + // + // aLoop.getActors().add(actuator); + // + // // Add a sensor for the readback + // String name = lp.getReadback(); + // if (name == null) { + // name = lp.getName(); + // } + // ChannelAccessDoubleSensor sensor = new + // ChannelAccessDoubleSensor(cservice, lp.getId(), name); + // aLoop.getSensors().add(sensor); + // } else if (p instanceof ArrayPositioner) { + // ArrayPositioner ap = (ArrayPositioner) p; + // String[] positions = (ap.getPositions().trim()).split(" +"); + // double[] table = new double[positions.length]; + // for (int i = 0; i < positions.length; i++) { + // table[i] = Double.parseDouble(positions[i]); + // } + // + // ChannelAccessTableActuator a; + // if (p.getType().equals("String")) { + // a = new ChannelAccessTableActuator(cservice, p.getName(), + // p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); + // } else if (p.getType().equals("Double")) { + // a = new ChannelAccessTableActuator(cservice, p.getName(), + // p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), + // table, moveTimeout); + // } else { + // // Default + // a = new ChannelAccessTableActuator(cservice, p.getName(), + // p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), + // table, moveTimeout); + // } + // + // a.setAsynchronous(p.isAsynchronous()); + // Actor actuator = a; + // + // aLoop.getActors().add(actuator); + // + // // Add a sensor for the readback + // String name = ap.getReadback(); + // if (name == null) { + // name = ap.getName(); + // } + // ChannelAccessDoubleSensor sensor = new + // ChannelAccessDoubleSensor(cservice, ap.getId(), name); + // aLoop.getSensors().add(sensor); + // } else if (p instanceof RegionPositioner) { + // RegionPositioner rp = (RegionPositioner) p; + // + // ComplexActuator actuator = new ComplexActuator(); + // /* + // * Regions are translated into a complex actor consisting of a + // * LinearActuator If consecutive regions are overlapping, i.e. + // * end point of region a equals the start point of region b then + // * the start point for the LinearActuator of region b is changes + // * to its next step (start+/-stepSize depending on whether end + // * position of the region is > or < start of the region) + // */ + // Region lastRegion = null; + // for (Region r : rp.getRegion()) { + // // Normal region + // if (r.getFunction() == null) { + // + // // Check whether regions are consecutive + // double start = r.getStart(); + // if (lastRegion != null && start == lastRegion.getEnd()) { // TODO + // // verify + // // whether + // // double + // // comparison + // // is + // // ok + // if (r.getStart() < r.getEnd()) { + // start = start + r.getStepSize(); + // } else { + // start = start - r.getStepSize(); + // } + // } + // + // // Create actuator + // ChannelAccessLinearActuator act; + // if (rp.getType().equals("String")) { + // act = new ChannelAccessLinearActuator(cservice, rp.getName(), + // rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, + // r.getEnd(), r.getStepSize(), moveTimeout); + // } else if (rp.getType().equals("Double")) { + // act = new ChannelAccessLinearActuator(cservice, rp.getName(), + // rp.getDone(), Double.parseDouble(rp.getDoneValue()), + // rp.getDoneDelay(), start, r.getEnd(), + // r.getStepSize(), moveTimeout); + // } else { + // // Default + // act = new ChannelAccessLinearActuator(cservice, + // rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), + // rp.getDoneDelay(), start, r.getEnd(), + // r.getStepSize(), moveTimeout); + // } + // + // act.setAsynchronous(rp.isAsynchronous()); + // Actor a = act; + // + // ComplexActuator ca = new ComplexActuator(); + // ca.getActors().add(a); + // ca.getPreActions().addAll(mapActions(r.getPreAction())); + // actuator.getActors().add(ca); + // lastRegion = r; + // } else { + // // Function based region + // + // // Cannot check whether the regions are consecutive as + // // the function + // // used might change the start value to something else + // // [THIS LIMITATION NEEDS TO BE SOMEHOW RESOLVED IN THE + // // NEXT VERSIONS] + // JythonFunction function = mapFunction(r.getFunction()); + // ChannelAccessFunctionActuator act; + // if (rp.getType().equals("String")) { + // act = new ChannelAccessFunctionActuator(cservice, + // rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), + // function, r.getStart(), r.getEnd(), + // r.getStepSize(), moveTimeout); + // } else if (rp.getType().equals("Double")) { + // act = new ChannelAccessFunctionActuator(cservice, + // rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), + // rp.getDoneDelay(), function, r.getStart(), + // r.getEnd(), r.getStepSize(), moveTimeout); + // } else { + // // Default + // act = new ChannelAccessFunctionActuator(cservice, + // rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), + // rp.getDoneDelay(), function, r.getStart(), + // r.getEnd(), r.getStepSize(), moveTimeout); + // } + // + // act.setAsynchronous(rp.isAsynchronous()); + // Actor a = act; + // + // ComplexActuator ca = new ComplexActuator(); + // ca.getActors().add(a); + // ca.getPreActions().addAll(mapActions(r.getPreAction())); + // actuator.getActors().add(ca); + // lastRegion = r; + // } + // } + // aLoop.getActors().add(actuator); + // + // // Add a sensor for the readback + // String name = rp.getReadback(); + // if (name == null) { + // name = rp.getName(); + // } + // ChannelAccessDoubleSensor sensor = new + // ChannelAccessDoubleSensor(cservice, rp.getId(), name); + // aLoop.getSensors().add(sensor); + // } else if (p instanceof PseudoPositioner) { + // PseudoPositioner pp = (PseudoPositioner) p; + // PseudoActuatorSensor actorSensor = new + // PseudoActuatorSensor(pp.getId(), pp.getCounts()); + // + // // Register as actor + // aLoop.getActors().add(actorSensor); + // + // // Register as sensor + // aLoop.getSensors().add(actorSensor); + // } else { + // // Not supported + // logger.warning("Mapping for " + p.getClass().getName() + + // " not available"); + // } + // } + } + + /** + * Get unique variable names that do not collide with others. (at least have + * an extreme unlikeness to do so) + * + * @return + */ + private String getUniqueVariableName() { + return "v" + UUID.randomUUID().toString().replaceAll("-", ""); } /** - * Get unique variable names that do not collide with others. (at least have an extreme unlikeness to do so) + * Get the string representation for a variable in python + * i.e. surrounds String with '', ensures that double has a . in the value, ... + * @param value + * @param type * @return */ - private String getUniqueVariableName(){ - return "v"+UUID.randomUUID().toString().replaceAll("-", ""); + private String getPythonValue(String value, Class type){ + if(type.equals(String.class)){ + return "'"+value+"'"; + } + else if(type.equals(Double.class)){ + return String.format("%f", new Double(value)); + } + else if(type.equals(Integer.class)){ + return String.format("%d", new Integer(value)); + } + return value.toString(); + } + + /** + * Request resource + * + * @param resourceId + * @return variable name for resource + * + * TODO Eventually we need to add type of resource here to be able + * to generate the resource before the script is executed. + */ + private String getChannelResourceVariable(String channelName, Class type, boolean monitor) { + // Right now each a new channel object will be created for each requirested channel resource (even it is the same channel) + // TODO Optimize the resource consumption by checking whether the resource already exists and return only one reference. + String varname = getUniqueVariableName(); + resourceDescriptors.put(varname, new ChannelDescriptor<>(type, channelName, monitor)); + return varname; } -// -// String operation = ca.getOperation(); // Default = put -// String type=ca.getType(); // Default = String -// -// if(operation.equals("put")){ -// Long timeout = null; -// if(ca.getTimeout()!=null){ -// timeout = Math.round(ca.getTimeout()*1000); -// } -// if(type.equals("String")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), false, timeout)); -// } -// else if(type.equals("Integer")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), false, timeout)); -// } -// else if(type.equals("Double")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), false, timeout)); -// } -// } -// else if(operation.equals("putq")){ -// if(type.equals("String")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), ca.getValue(), true, null)); -// } -// else if(type.equals("Integer")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Integer(ca.getValue()), true, null)); -// } -// else if(type.equals("Double")){ -// alist.add(new ChannelAccessPut(cservice, ca.getChannel(), new Double(ca.getValue()), true, null)); -// } -// } -// else if(operation.equals("wait")){ -// Long timeout = null ; // Default timeout = wait forever -// if(ca.getTimeout()!=null){ -// timeout = Math.round(ca.getTimeout()*1000); -// } -// if(type.equals("String")){ -// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), ca.getValue(), timeout)); -// } -// else if(type.equals("Integer")){ -// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); -// } -// else if(type.equals("Double")){ -// alist.add(new ChannelAccessCondition(cservice, ca.getChannel(), new Double(ca.getValue()), timeout)); -// } -// } -// else if(operation.equals("waitREGEX")){ -// Long timeout = null ; // Default timeout = wait forever -// if(ca.getTimeout()!=null){ -// timeout = Math.round(ca.getTimeout()*1000); -// } -// if(type.equals("String")){ -// alist.add(new ChannelAccessConditionRegex(cservice, ca.getChannel(), ca.getValue(), timeout)); -// } -// else{ -// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); -// } -// } -// else if(operation.equals("waitOR")){ -// Long timeout = null ; // Default timeout = wait forever -// if(ca.getTimeout()!=null){ -// timeout = Math.round(ca.getTimeout()*1000); -// } -// -// if(type.equals("Integer")){ -// alist.add(new ChannelAccessConditionOr(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); -// } -// else{ -// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); -// } -// } -// else if(operation.equals("waitAND")){ -// Long timeout = null ; // Default timeout = wait forever -// if(ca.getTimeout()!=null){ -// timeout = Math.round(ca.getTimeout()*1000); -// } -// if(type.equals("Integer")){ -// alist.add(new ChannelAccessConditionAnd(cservice, ca.getChannel(), new Integer(ca.getValue()), timeout)); -// } -// else { -// logger.warning("Operation "+operation+" wity type "+type+" for action is not supported"); -// } -// } -// else{ -// // Operation not supported -// logger.warning("Operation "+operation+" for action is not supported"); -// } -// -// // Translate delay attribute to delay action -// if(ca.getDelay()!=null){ -// Double x = ca.getDelay()*1000; -// alist.add(new Delay(x.longValue())); -// } -// -//} - } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java new file mode 100644 index 0000000..a1f8e0a --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +/** + * Resource descriptor of an operating system shell. + * @author ebner + * + */ +public class ShellDescriptor { + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java new file mode 100644 index 0000000..14f15ca --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.logging.Logger; + +/** + * @author ebner + * + */ +public class ShellResource { + + private static final Logger logger = Logger.getLogger(ShellResource.class.getName()); + + public void execute(String script, int returnValue, boolean checkReturnValue){ + ProcessBuilder pb = new ProcessBuilder(new String[]{"/bin/bash","-c",script}); + pb.redirectErrorStream(true); + + try { + Process p = pb.start(); + int rvalue = p.waitFor(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = null; + while((line=reader.readLine()) != null){ + logger.info(line); + } + + // Check return value if need to be checked + if(checkReturnValue){ + if(rvalue != returnValue){ + throw new RuntimeException("Executing script "+script+" failed"); + } + } + } catch (IOException | InterruptedException e) { + throw new RuntimeException("Unable to execute script", e); + } + } + +} diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java index ba5387a..b13aad0 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java @@ -18,17 +18,27 @@ */ package ch.psi.fda.aq; -import static org.junit.Assert.*; +import java.util.logging.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; +import ch.psi.fda.TestChannels; +import ch.psi.fda.model.v1.ChannelAction; +import ch.psi.fda.model.v1.Configuration; +import ch.psi.fda.model.v1.Scan; +import ch.psi.fda.model.v1.ScriptAction; +import ch.psi.fda.model.v1.ShellAction; +import ch.psi.jcae.impl.DefaultChannelService; + /** * @author ebner * */ public class AcquisitionEngineNGTest { + + private static final Logger logger = Logger.getLogger(AcquisitionEngineNGTest.class.getName()); private AcquisitionEngineNG engine; @@ -37,7 +47,7 @@ public class AcquisitionEngineNGTest { */ @Before public void setUp() throws Exception { - engine = new AcquisitionEngineNG(); + engine = new AcquisitionEngineNG(new DefaultChannelService()); } /** @@ -51,10 +61,50 @@ public class AcquisitionEngineNGTest { * Test method for {@link ch.psi.fda.aq.AcquisitionEngineNG#execute(java.lang.String)}. */ @Test - public void testExecute() { -// engine.execute("import os"); - engine.execute("print 'hello'"); -// engine.execute("os.system('echo hello world this is a test')"); + public void testExecuteChannelAction() { + + Configuration config = new Configuration(); + config.setScan(new Scan()); + + // Set value + ChannelAction ca = new ChannelAction(); + ca.setChannel(TestChannels.ANALOG_OUT); + ca.setValue("12"); + ca.setType("Double"); + ca.setDelay(1.2); + + config.getScan().getPreAction().add(ca); + + // Wait for value + ca = new ChannelAction(); + ca.setChannel(TestChannels.ANALOG_OUT); + ca.setValue("13"); + ca.setOperation("wait"); + ca.setTimeout(10.0); + ca.setType("Double"); + + config.getScan().getPreAction().add(ca); + + + ScriptAction sa = new ScriptAction(); + sa.setScript("for i in range(0, 3):\n logger.info('hello %d' %i)\n"); + + ShellAction a = new ShellAction(); + a.setCommand("echo hello world this is a test"); +// a.setExitValue(1); + + config.getScan().getPostAction().add(sa); + config.getScan().getPostAction().add(a); + + + ScanMapperNG mapper = new ScanMapperNG(); + mapper.map(config); + + logger.info("Resources to create: "+mapper.getResourceDescriptors()); + logger.info("Script to execute: "+mapper.getScript()); + + + engine.execute(mapper.getResourceDescriptors(), mapper.getScript()); } } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java index 29ed1af..a123b4a 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java @@ -27,6 +27,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.Scan; @@ -62,17 +63,19 @@ public class ScanMapperNGTest { */ @Test public void testMap() { - System.out.println("juhu"+("This is a Java string".hashCode())); - Configuration config = new Configuration(); config.setScan(new Scan()); ShellAction a = new ShellAction(); a.setCommand("echo hello world this is a test"); + + ChannelAction ca = new ChannelAction(); + ca.setValue("hossa"); + ca.setDelay(1.2); config.getScan().getPreAction().add(a); - + config.getScan().getPreAction().add(ca); ScriptAction sa = new ScriptAction(); sa.setScript("print 'hello'"); @@ -80,6 +83,7 @@ public class ScanMapperNGTest { config.getScan().getPostAction().add(sa); config.getScan().getPostAction().add(a); + DiscreteStepDimension d = new DiscreteStepDimension(); d.getPreAction().add(a); d.getAction().add(sa); From e64d341a383b05eaf250696f6d3f8f532d98b62f Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Mon, 29 Jul 2013 15:22:33 +0200 Subject: [PATCH 05/12] Changes --- .../ch/psi/fda/aq/AcquisitionEngineNG.java | 16 + .../ch/psi/fda/aq/ChannelProbeResource.java | 58 +++ .../java/ch/psi/fda/aq/ProbeDescriptor.java | 37 ++ .../main/java/ch/psi/fda/aq/ScanMapperNG.java | 343 +++++------------- .../psi/fda/aq/AcquisitionEngineNGTest.java | 69 +++- .../java/ch/psi/fda/aq/ScanMapperNGTest.java | 8 + 6 files changed, 280 insertions(+), 251 deletions(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java index 07abcf4..0d8dd87 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java @@ -18,6 +18,8 @@ */ package ch.psi.fda.aq; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; @@ -26,6 +28,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelDescriptor; import ch.psi.jcae.ChannelException; import ch.psi.jcae.ChannelService; @@ -68,6 +71,19 @@ public class AcquisitionEngineNG { else if(resourceDescriptors.get(k) instanceof ShellDescriptor){ engine.put(k, new ShellResource()); } + else if(resourceDescriptors.get(k) instanceof ProbeDescriptor){ + ProbeDescriptor descriptor = (ProbeDescriptor) resourceDescriptors.get(k); + List> descriptors = new ArrayList<>(); + + for(ChannelDescriptor s: descriptor.getSensors()){ + try { + descriptors.add(cservice.createChannel(s)); + } catch (ChannelException | InterruptedException | TimeoutException e) { + throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e); + } + } + engine.put(k, new ChannelProbeResource(descriptors)); + } else{ throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName()); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java new file mode 100644 index 0000000..36b69bf --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import ch.psi.fda.core.messages.DataMessage; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelException; + +/** + * @author ebner + * + */ +public class ChannelProbeResource { + + private final List> channels; + + + public ChannelProbeResource(List> channels){ + this.channels = channels; + } + + public void read(){ + try{ + DataMessage message = new DataMessage(); + for(Channel sensor: channels){ + // Readout sensor + Object o = sensor.getValue(); + // Add sensor data item to message + message.getData().add(o); + } + System.out.println("MESSAGE: "+message); + } catch (InterruptedException | TimeoutException | ChannelException | ExecutionException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java new file mode 100644 index 0000000..b2a1309 --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq; + +import java.util.ArrayList; +import java.util.List; + +import ch.psi.jcae.ChannelDescriptor; + +/** + * @author ebner + * + */ +public class ProbeDescriptor { + + private List> sensors = new ArrayList<>(); + public List> getSensors(){ + return sensors; + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java index d573afc..4104543 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java @@ -28,12 +28,15 @@ import java.util.UUID; import java.util.logging.Logger; import ch.psi.fda.model.v1.Action; +import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; import ch.psi.fda.model.v1.ContinuousDimension; import ch.psi.fda.model.v1.Dimension; import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.DiscreteStepPositioner; +import ch.psi.fda.model.v1.FunctionPositioner; +import ch.psi.fda.model.v1.LinearPositioner; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; @@ -48,6 +51,11 @@ import ch.psi.jcae.util.ComparatorREGEX; */ public class ScanMapperNG { + // Reserved resource id's + private static final String PROBE_RESOURCE_ID = "probe"; + private static final String SHELL_RESOURCE_ID = "shell"; + // "logger" is also a special variable as it is bound to the logger of the application! + private static final Logger logger = Logger.getLogger(ScanMapperNG.class.getName()); private static final String INDENT = " "; @@ -56,9 +64,19 @@ public class ScanMapperNG { private Set imports = new HashSet<>(); private Map resourceDescriptors = new HashMap<>(); + private ProbeDescriptor probeDescriptor = new ProbeDescriptor(); + private String indentation = ""; public void map(Configuration configuration) { + + // Clear object state + script = new StringBuilder(); + imports = new HashSet<>(); + resourceDescriptors = new HashMap<>(); + probeDescriptor = new ProbeDescriptor(); + + resourceDescriptors.put(PROBE_RESOURCE_ID, probeDescriptor); Scan scan = configuration.getScan(); mapActions(scan.getPreAction()); @@ -118,18 +136,88 @@ public class ScanMapperNG { DiscreteStepDimension d = (DiscreteStepDimension) dimension; mapActions(d.getPreAction()); - // TODO Do mapping - script.append(indentation + "for i in test\n"); + + List actuators = new ArrayList<>(); + + for(DiscreteStepPositioner positioner: d.getPositioner()){ + Class type = String.class; + switch (positioner.getType()) { + case "Integer": + type = Integer.class; + break; + case "Double": + type = Double.class; + break; + } + + String var = getChannelResourceVariable(positioner.getName(), type, false); + actuators.add(var); + + // Readback + if(positioner.getReadback()==null){ + probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getName(), false)); + } + else{ + // Use readback + probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getReadback(), false)); + } + + // TODO Done resource + + + if(positioner instanceof LinearPositioner){ + LinearPositioner lpositioner = (LinearPositioner) positioner; + } + else if(positioner instanceof ArrayPositioner){ + ArrayPositioner apositioner = (ArrayPositioner) positioner; + // Calculate positions + String[] positions = apositioner.getPositions().trim().split(" +"); + boolean first = true; + StringBuffer b = new StringBuffer(); + b.append("["); + for(String po: positions){ + if(first){ + first=false; + } + else{ + b.append(","); + } + + b.append(getPythonValue(po, type)); + } + b.append("]"); + script.append(indentation + var+"_positions="+b.toString()+"\n"); + } + else if(positioner instanceof FunctionPositioner){ + FunctionPositioner fpositioner = (FunctionPositioner) positioner; + // TODO take variable mappings into account ! + } + } + + // Create dimension loop + String v = getUniqueVariableName(); + script.append(indentation + "for "+v+"_idx ,"+v+"_pos in enumerate("+actuators.get(0)+"_positions):\n"); indentation = indentation + INDENT; - mapPositioners(d.getPositioner()); + + // Set all actuators of this dimension + for(String a: actuators){ + script.append(indentation + a+".setValue("+a+"_positions["+v+"_idx])\n"); + } + + // Add all actions executed between actuator and sensors mapActions(d.getAction()); // TODO map guard and sensors - // Next dimension + // Check whether final dimension reached if ((index + 1) < dimensions.size()) { + // Map next dimension mapDimensions(dimensions, (index + 1)); } + else{ + // Final dimension reached - readout probe + script.append(indentation + PROBE_RESOURCE_ID+".read()\n"); + } indentation = indentation.replaceFirst(INDENT, ""); // decrease // indentation @@ -201,9 +289,9 @@ public class ScanMapperNG { } else if (action instanceof ShellAction) { ShellAction saction = (ShellAction) action; - resourceDescriptors.put("shell", new ShellDescriptor()); + resourceDescriptors.put(SHELL_RESOURCE_ID, new ShellDescriptor()); // TODO Need to indicate that shell resource is required - script.append(indentation + String.format("shell.execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue()?"True":"False")); + script.append(indentation + String.format(SHELL_RESOURCE_ID+".execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue()?"True":"False")); } else if (action instanceof ScriptAction) { ScriptAction saction = (ScriptAction) action; @@ -212,254 +300,13 @@ public class ScanMapperNG { // level String[] lines = saction.getScript().split(System.getProperty("line.separator")); for (String s : lines) { - script.append(indentation + s); + script.append(indentation + s+"\n"); } script.append(indentation + "\n"); } } } - public void mapPositioners(List positioners) { - // for (DiscreteStepPositioner p : positioners) { - // - // if (p.getSettlingTime() > stime) { - // stime = p.getSettlingTime(); - // } - // - // if (p instanceof LinearPositioner) { - // LinearPositioner lp = (LinearPositioner) p; - // ChannelAccessLinearActuator a; - // if (lp.getType().equals("String")) { - // a = new ChannelAccessLinearActuator(cservice, lp.getName(), - // lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), lp.getStart(), - // lp.getEnd(), lp.getStepSize(), moveTimeout); - // } else if (lp.getType().equals("Double")) { - // a = new ChannelAccessLinearActuator(cservice, lp.getName(), - // lp.getDone(), Double.parseDouble(lp.getDoneValue()), - // lp.getDoneDelay(), lp.getStart(), lp.getEnd(), - // lp.getStepSize(), moveTimeout); - // } else { - // // Default - // a = new ChannelAccessLinearActuator(cservice, lp.getName(), - // lp.getDone(), Integer.parseInt(lp.getDoneValue()), lp.getDoneDelay(), - // lp.getStart(), lp.getEnd(), - // lp.getStepSize(), moveTimeout); - // } - // - // a.setAsynchronous(lp.isAsynchronous()); - // Actor actuator = a; - // - // aLoop.getActors().add(actuator); - // - // // Add a sensor for the readback - // String name = lp.getReadback(); - // if (name == null) { - // name = lp.getName(); - // } - // ChannelAccessDoubleSensor sensor = new - // ChannelAccessDoubleSensor(cservice, lp.getId(), name); - // aLoop.getSensors().add(sensor); - // } else if (p instanceof FunctionPositioner) { - // FunctionPositioner lp = (FunctionPositioner) p; - // - // // Create function object - // JythonFunction function = mapFunction(lp.getFunction()); - // - // // Create actuator - // ChannelAccessFunctionActuator a; - // if (lp.getType().equals("String")) { - // a = new ChannelAccessFunctionActuator(cservice, lp.getName(), - // lp.getDone(), lp.getDoneValue(), lp.getDoneDelay(), function, - // lp.getStart(), lp.getEnd(), lp.getStepSize(), - // moveTimeout); - // } else if (lp.getType().equals("Double")) { - // a = new ChannelAccessFunctionActuator(cservice, lp.getName(), - // lp.getDone(), Double.parseDouble(lp.getDoneValue()), - // lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), - // lp.getStepSize(), moveTimeout); - // } else { - // // Default - // a = new ChannelAccessFunctionActuator(cservice, - // lp.getName(), lp.getDone(), Integer.parseInt(lp.getDoneValue()), - // lp.getDoneDelay(), function, lp.getStart(), lp.getEnd(), - // lp.getStepSize(), moveTimeout); - // } - // - // a.setAsynchronous(lp.isAsynchronous()); - // Actor actuator = a; - // - // aLoop.getActors().add(actuator); - // - // // Add a sensor for the readback - // String name = lp.getReadback(); - // if (name == null) { - // name = lp.getName(); - // } - // ChannelAccessDoubleSensor sensor = new - // ChannelAccessDoubleSensor(cservice, lp.getId(), name); - // aLoop.getSensors().add(sensor); - // } else if (p instanceof ArrayPositioner) { - // ArrayPositioner ap = (ArrayPositioner) p; - // String[] positions = (ap.getPositions().trim()).split(" +"); - // double[] table = new double[positions.length]; - // for (int i = 0; i < positions.length; i++) { - // table[i] = Double.parseDouble(positions[i]); - // } - // - // ChannelAccessTableActuator a; - // if (p.getType().equals("String")) { - // a = new ChannelAccessTableActuator(cservice, p.getName(), - // p.getDone(), p.getDoneValue(), p.getDoneDelay(), table, moveTimeout); - // } else if (p.getType().equals("Double")) { - // a = new ChannelAccessTableActuator(cservice, p.getName(), - // p.getDone(), Double.parseDouble(p.getDoneValue()), p.getDoneDelay(), - // table, moveTimeout); - // } else { - // // Default - // a = new ChannelAccessTableActuator(cservice, p.getName(), - // p.getDone(), Integer.parseInt(p.getDoneValue()), p.getDoneDelay(), - // table, moveTimeout); - // } - // - // a.setAsynchronous(p.isAsynchronous()); - // Actor actuator = a; - // - // aLoop.getActors().add(actuator); - // - // // Add a sensor for the readback - // String name = ap.getReadback(); - // if (name == null) { - // name = ap.getName(); - // } - // ChannelAccessDoubleSensor sensor = new - // ChannelAccessDoubleSensor(cservice, ap.getId(), name); - // aLoop.getSensors().add(sensor); - // } else if (p instanceof RegionPositioner) { - // RegionPositioner rp = (RegionPositioner) p; - // - // ComplexActuator actuator = new ComplexActuator(); - // /* - // * Regions are translated into a complex actor consisting of a - // * LinearActuator If consecutive regions are overlapping, i.e. - // * end point of region a equals the start point of region b then - // * the start point for the LinearActuator of region b is changes - // * to its next step (start+/-stepSize depending on whether end - // * position of the region is > or < start of the region) - // */ - // Region lastRegion = null; - // for (Region r : rp.getRegion()) { - // // Normal region - // if (r.getFunction() == null) { - // - // // Check whether regions are consecutive - // double start = r.getStart(); - // if (lastRegion != null && start == lastRegion.getEnd()) { // TODO - // // verify - // // whether - // // double - // // comparison - // // is - // // ok - // if (r.getStart() < r.getEnd()) { - // start = start + r.getStepSize(); - // } else { - // start = start - r.getStepSize(); - // } - // } - // - // // Create actuator - // ChannelAccessLinearActuator act; - // if (rp.getType().equals("String")) { - // act = new ChannelAccessLinearActuator(cservice, rp.getName(), - // rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), start, - // r.getEnd(), r.getStepSize(), moveTimeout); - // } else if (rp.getType().equals("Double")) { - // act = new ChannelAccessLinearActuator(cservice, rp.getName(), - // rp.getDone(), Double.parseDouble(rp.getDoneValue()), - // rp.getDoneDelay(), start, r.getEnd(), - // r.getStepSize(), moveTimeout); - // } else { - // // Default - // act = new ChannelAccessLinearActuator(cservice, - // rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), - // rp.getDoneDelay(), start, r.getEnd(), - // r.getStepSize(), moveTimeout); - // } - // - // act.setAsynchronous(rp.isAsynchronous()); - // Actor a = act; - // - // ComplexActuator ca = new ComplexActuator(); - // ca.getActors().add(a); - // ca.getPreActions().addAll(mapActions(r.getPreAction())); - // actuator.getActors().add(ca); - // lastRegion = r; - // } else { - // // Function based region - // - // // Cannot check whether the regions are consecutive as - // // the function - // // used might change the start value to something else - // // [THIS LIMITATION NEEDS TO BE SOMEHOW RESOLVED IN THE - // // NEXT VERSIONS] - // JythonFunction function = mapFunction(r.getFunction()); - // ChannelAccessFunctionActuator act; - // if (rp.getType().equals("String")) { - // act = new ChannelAccessFunctionActuator(cservice, - // rp.getName(), rp.getDone(), rp.getDoneValue(), rp.getDoneDelay(), - // function, r.getStart(), r.getEnd(), - // r.getStepSize(), moveTimeout); - // } else if (rp.getType().equals("Double")) { - // act = new ChannelAccessFunctionActuator(cservice, - // rp.getName(), rp.getDone(), Double.parseDouble(rp.getDoneValue()), - // rp.getDoneDelay(), function, r.getStart(), - // r.getEnd(), r.getStepSize(), moveTimeout); - // } else { - // // Default - // act = new ChannelAccessFunctionActuator(cservice, - // rp.getName(), rp.getDone(), Integer.parseInt(rp.getDoneValue()), - // rp.getDoneDelay(), function, r.getStart(), - // r.getEnd(), r.getStepSize(), moveTimeout); - // } - // - // act.setAsynchronous(rp.isAsynchronous()); - // Actor a = act; - // - // ComplexActuator ca = new ComplexActuator(); - // ca.getActors().add(a); - // ca.getPreActions().addAll(mapActions(r.getPreAction())); - // actuator.getActors().add(ca); - // lastRegion = r; - // } - // } - // aLoop.getActors().add(actuator); - // - // // Add a sensor for the readback - // String name = rp.getReadback(); - // if (name == null) { - // name = rp.getName(); - // } - // ChannelAccessDoubleSensor sensor = new - // ChannelAccessDoubleSensor(cservice, rp.getId(), name); - // aLoop.getSensors().add(sensor); - // } else if (p instanceof PseudoPositioner) { - // PseudoPositioner pp = (PseudoPositioner) p; - // PseudoActuatorSensor actorSensor = new - // PseudoActuatorSensor(pp.getId(), pp.getCounts()); - // - // // Register as actor - // aLoop.getActors().add(actorSensor); - // - // // Register as sensor - // aLoop.getSensors().add(actorSensor); - // } else { - // // Not supported - // logger.warning("Mapping for " + p.getClass().getName() + - // " not available"); - // } - // } - } - /** * Get unique variable names that do not collide with others. (at least have * an extreme unlikeness to do so) diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java index b13aad0..ca14fe9 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java @@ -25,8 +25,10 @@ import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestChannels; +import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; +import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; @@ -78,22 +80,34 @@ public class AcquisitionEngineNGTest { // Wait for value ca = new ChannelAction(); ca.setChannel(TestChannels.ANALOG_OUT); - ca.setValue("13"); + ca.setValue("12"); // use other value than 12 to test ca.setOperation("wait"); ca.setTimeout(10.0); ca.setType("Double"); config.getScan().getPreAction().add(ca); - ScriptAction sa = new ScriptAction(); sa.setScript("for i in range(0, 3):\n logger.info('hello %d' %i)\n"); + + // Add discrete step dimension + DiscreteStepDimension dimension = new DiscreteStepDimension(); + + ArrayPositioner positioner = new ArrayPositioner(); + positioner.setName(TestChannels.ANALOG_OUT); + positioner.setPositions(" 1 2 3 4 5 6 7"); + dimension.getPositioner().add(positioner); + + dimension.getAction().add(sa); + + config.getScan().getDimension().add(dimension); + ShellAction a = new ShellAction(); a.setCommand("echo hello world this is a test"); // a.setExitValue(1); - config.getScan().getPostAction().add(sa); +// config.getScan().getPostAction().add(sa); config.getScan().getPostAction().add(a); @@ -106,5 +120,54 @@ public class AcquisitionEngineNGTest { engine.execute(mapper.getResourceDescriptors(), mapper.getScript()); } + + @Test + public void testExecuteDimensionActuators() { + + Configuration config = new Configuration(); + config.setScan(new Scan()); + + // Add discrete step dimension + DiscreteStepDimension dimension = new DiscreteStepDimension(); + + ArrayPositioner positioner = new ArrayPositioner(); + positioner.setName(TestChannels.ANALOG_OUT); +// positioner.setReadback(TestChannels.BINARY_OUT); + positioner.setPositions(" 1 2 3 4 5 6 7"); + dimension.getPositioner().add(positioner); + + positioner = new ArrayPositioner(); + positioner.setName(TestChannels.BINARY_OUT); + positioner.setType("Double"); + positioner.setPositions(" 10 20 30 40 50 60 70"); + dimension.getPositioner().add(positioner); + + config.getScan().getDimension().add(dimension); + + + dimension = new DiscreteStepDimension(); + + positioner = new ArrayPositioner(); + positioner.setName(TestChannels.BINARY_OUT_TWO); + positioner.setType("Double"); +// positioner.setReadback(TestChannels.BINARY_OUT); + positioner.setPositions(" 0.1 0.2 0.3 0.4 0.5 0.6 0.7"); + dimension.getPositioner().add(positioner); + + config.getScan().getDimension().add(dimension); + + ScanMapperNG mapper = new ScanMapperNG(); + mapper.map(config); + + logger.info("Resources to create: "+mapper.getResourceDescriptors()); + logger.info("Script to execute: "+mapper.getScript()); + + long start, end, elapsed; + start = System.currentTimeMillis(); + engine.execute(mapper.getResourceDescriptors(), mapper.getScript()); + end = System.currentTimeMillis(); + elapsed = end-start; + logger.info("Elapsed time: "+elapsed); + } } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java index a123b4a..fa6c5c6 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java @@ -27,6 +27,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import ch.psi.fda.TestChannels; +import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; import ch.psi.fda.model.v1.DiscreteStepDimension; @@ -85,7 +87,13 @@ public class ScanMapperNGTest { DiscreteStepDimension d = new DiscreteStepDimension(); + + ArrayPositioner positioner = new ArrayPositioner(); + positioner.setName(TestChannels.ANALOG_OUT); + positioner.setPositions(" 1 2 3 4 5 6 7"); + d.getPreAction().add(a); + d.getPositioner().add(positioner); d.getAction().add(sa); d.getPostAction().add(a); From f84a5696b07cfa13be5e11f18919ad76d2daa88d Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 30 Jul 2013 11:36:26 +0200 Subject: [PATCH 06/12] reorganized package structure for new dataacquisition engine --- .../main/java/ch/psi/fda/aq/Acquisition.java | 66 +++++++++++++------ .../fda/aq/{ => ng}/AcquisitionEngineNG.java | 26 ++++++-- .../fda/aq/{ => ng}/ChannelProbeResource.java | 44 +++++++++++-- .../psi/fda/aq/{ => ng}/ProbeDescriptor.java | 2 +- .../ch/psi/fda/aq/{ => ng}/ScanMapperNG.java | 54 ++++++++++++++- .../psi/fda/aq/{ => ng}/ShellDescriptor.java | 2 +- .../ch/psi/fda/aq/{ => ng}/ShellResource.java | 2 +- .../aq/{ => ng}/AcquisitionEngineNGTest.java | 6 +- .../psi/fda/aq/{ => ng}/ScanMapperNGTest.java | 32 ++++++++- 9 files changed, 197 insertions(+), 37 deletions(-) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/AcquisitionEngineNG.java (78%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/ChannelProbeResource.java (56%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/ProbeDescriptor.java (97%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/ScanMapperNG.java (87%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/ShellDescriptor.java (97%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/{ => ng}/ShellResource.java (98%) rename ch.psi.fda/src/test/java/ch/psi/fda/aq/{ => ng}/AcquisitionEngineNGTest.java (96%) rename ch.psi.fda/src/test/java/ch/psi/fda/aq/{ => ng}/ScanMapperNGTest.java (76%) diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java index 6a1ef4e..9478a4c 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java @@ -35,6 +35,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; +import ch.psi.fda.aq.ng.AcquisitionEngineNG; +import ch.psi.fda.aq.ng.ScanMapperNG; import ch.psi.fda.core.ActionLoop; import ch.psi.fda.core.Actor; import ch.psi.fda.core.EngineConfiguration; @@ -127,6 +129,8 @@ import ch.psi.jcae.impl.DefaultChannelService; */ public class Acquisition { + private static boolean NEW_ENGINE = true; + // Get Logger private static Logger logger = Logger.getLogger(Acquisition.class.getName()); @@ -134,6 +138,8 @@ public class Acquisition { private ActionLoop actionLoop; private Collector collector; + private ScanMapperNG mapper; + private AcquisitionEngineNG acquisitionEngine; private DataDispatcher dispatcher; private Manipulator manipulator; private DataSerializerTXT serializer; @@ -240,20 +246,29 @@ public class Acquisition { // Configure core engine EngineConfiguration.getInstance().setFailOnSensorError(smodel.isFailOnSensorError()); + if(NEW_ENGINE){ + acquisitionEngine = new AcquisitionEngineNG(cservice); + mapper = new ScanMapperNG(); + mapper.map(smodel); + + this.manipulator = new Manipulator(new DataQueue( acquisitionEngine.getOutQueue(), mapper.getDataMessageMetadata()), this.manipulations); + } + else{ + logger.fine("Map Model to internal logic"); + + // Map scan to base model + // After this call actionLoop and collector will be initialized + mapScan(smodel); + + logger.fine("ActionLoop and Collector initialized"); + + // TODO Remove this workaround + Collections.reverse(collector.getQueues()); + + // Add manipulator into processing chain + this.manipulator = new Manipulator(collector.getOutQueue(), this.manipulations); + } - logger.fine("Map Model to internal logic"); - - // Map scan to base model - // After this call actionLoop and collector will be initialized - mapScan(smodel); - - logger.fine("ActionLoop and Collector initialized"); - - // TODO Remove this workaround - Collections.reverse(collector.getQueues()); - - // Add manipulator into processing chain - this.manipulator = new Manipulator(collector.getOutQueue(), this.manipulations); // // Insert dispatcher into processing chain this.dispatcher = new DataDispatcher(manipulator.getOutQueue()); @@ -287,8 +302,11 @@ public class Acquisition { try{ active = true; - Thread tc = new Thread(collector); - tc.start(); + Thread tc = null; + if(!NEW_ENGINE){ + tc = new Thread(collector); + tc.start(); + } Thread tm = new Thread(manipulator); tm.start(); @@ -299,15 +317,25 @@ public class Acquisition { Thread t = new Thread(serializer); t.start(); - actionLoop.prepare(); - actionLoop.execute(); - actionLoop.cleanup(); + if(NEW_ENGINE){ + acquisitionEngine.execute(mapper.getResourceDescriptors(), mapper.getScript()); + } + else { + actionLoop.prepare(); + actionLoop.execute(); + actionLoop.cleanup(); + } + + + // Wait for data collector threads // Do this with a Latch or something like that // Give the threads 1 minute to catch up - tc.join(60000); + if(!NEW_ENGINE){ + tc.join(60000); + } tm.join(60000); td.join(60000); t.join(60000); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java similarity index 78% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java index 0d8dd87..e26ab53 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java @@ -16,11 +16,13 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeoutException; import java.util.logging.Logger; @@ -28,6 +30,9 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import ch.psi.fda.core.messages.ComponentMetadata; +import ch.psi.fda.core.messages.DataMessageMetadata; +import ch.psi.fda.core.messages.Message; import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelDescriptor; import ch.psi.jcae.ChannelException; @@ -42,9 +47,11 @@ public class AcquisitionEngineNG { private static final Logger logger = Logger.getLogger(AcquisitionEngineNG.class.getName()); private ChannelService cservice; + private BlockingQueue outQueue; public AcquisitionEngineNG(ChannelService cservice) { this.cservice = cservice; + this.outQueue = new LinkedBlockingQueue(1000); // Create bounded queue to prevent running out of memory ... // Workaround for Jython memory leak // http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/ @@ -52,6 +59,12 @@ public class AcquisitionEngineNG { } public void execute(Map resourceDescriptors, String script){ + + // TODO Remove debugging messages + // For debugging purpose only + logger.info("Resources to create: "+resourceDescriptors); + logger.info("Script to execute: "+script); + try { ScriptEngine engine = new ScriptEngineManager().getEngineByName("python"); @@ -73,16 +86,17 @@ public class AcquisitionEngineNG { } else if(resourceDescriptors.get(k) instanceof ProbeDescriptor){ ProbeDescriptor descriptor = (ProbeDescriptor) resourceDescriptors.get(k); - List> descriptors = new ArrayList<>(); + List> channels = new ArrayList<>(); for(ChannelDescriptor s: descriptor.getSensors()){ try { - descriptors.add(cservice.createChannel(s)); + channels.add(cservice.createChannel(s)); + } catch (ChannelException | InterruptedException | TimeoutException e) { throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e); } } - engine.put(k, new ChannelProbeResource(descriptors)); + engine.put(k, new ChannelProbeResource(channels, outQueue)); } else{ throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName()); @@ -97,5 +111,9 @@ public class AcquisitionEngineNG { throw new RuntimeException("Action failed while executing the Jython script",e); } } + + public BlockingQueue getOutQueue(){ + return outQueue; + } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java similarity index 56% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java index 36b69bf..a816f1e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ChannelProbeResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java @@ -16,14 +16,17 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; -import java.util.ArrayList; import java.util.List; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import ch.psi.fda.core.messages.DataMessage; +import ch.psi.fda.core.messages.EndOfStreamMessage; +import ch.psi.fda.core.messages.Message; +import ch.psi.fda.core.messages.StreamDelimiterMessage; import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelException; @@ -34,12 +37,16 @@ import ch.psi.jcae.ChannelException; public class ChannelProbeResource { private final List> channels; - + private BlockingQueue queue; - public ChannelProbeResource(List> channels){ + public ChannelProbeResource(List> channels, BlockingQueue queue){ this.channels = channels; + this.queue = queue; } + /** + * Read configured channels and send out data message + */ public void read(){ try{ DataMessage message = new DataMessage(); @@ -50,9 +57,38 @@ public class ChannelProbeResource { message.getData().add(o); } System.out.println("MESSAGE: "+message); + queue.put(message); } catch (InterruptedException | TimeoutException | ChannelException | ExecutionException e) { throw new RuntimeException(e); } } + + /** + * Send a stream delimiter message for the given index + * @param index + * @param iflag + */ + public void delimiter(int index, boolean iflag){ + try { + StreamDelimiterMessage message = new StreamDelimiterMessage(index, iflag); + System.out.println(message); + queue.put(message); + } catch (InterruptedException e) { + throw new RuntimeException("Unable to send delimiter message", e); + } + } + + /** + * Send end of stream message + */ + public void terminateStream(){ + try { + EndOfStreamMessage message = new EndOfStreamMessage(); + System.out.println(message); + queue.put(message); + } catch (InterruptedException e) { + throw new RuntimeException("Unable to send end of stream message", e); + } + } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java similarity index 97% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java index b2a1309..67e6325 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ProbeDescriptor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import java.util.ArrayList; import java.util.List; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java similarity index 87% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java index 4104543..6d12c1e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import java.util.ArrayList; import java.util.HashMap; @@ -27,6 +27,8 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Logger; +import ch.psi.fda.core.messages.ComponentMetadata; +import ch.psi.fda.core.messages.DataMessageMetadata; import ch.psi.fda.model.v1.Action; import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; @@ -37,6 +39,8 @@ import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.DiscreteStepPositioner; import ch.psi.fda.model.v1.FunctionPositioner; import ch.psi.fda.model.v1.LinearPositioner; +import ch.psi.fda.model.v1.PseudoPositioner; +import ch.psi.fda.model.v1.RegionPositioner; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; @@ -65,6 +69,8 @@ public class ScanMapperNG { private Map resourceDescriptors = new HashMap<>(); private ProbeDescriptor probeDescriptor = new ProbeDescriptor(); + private DataMessageMetadata dataMessageMetadata = new DataMessageMetadata(); + private String indentation = ""; @@ -124,6 +130,14 @@ public class ScanMapperNG { return resourceDescriptors; } + /** + * TODO need to be moved somewhere else + * @return + */ + public DataMessageMetadata getDataMessageMetadata(){ + return dataMessageMetadata; + } + private void mapDimensions(List dimensions, int index) { if(dimensions.size()<1){ @@ -161,12 +175,29 @@ public class ScanMapperNG { // Use readback probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getReadback(), false)); } + System.out.println(positioner.getId()); + dataMessageMetadata.getComponents().add(new ComponentMetadata(positioner.getId(), (dimensions.size()-1-index))); // TODO Done resource if(positioner instanceof LinearPositioner){ + // Calculate steps and add it to position array LinearPositioner lpositioner = (LinearPositioner) positioner; + boolean first = true; + StringBuffer b = new StringBuffer(); + b.append("["); + for(double i=0;(lpositioner.getStart()+i*lpositioner.getStepSize())<=lpositioner.getEnd();i++){ + if(first){ + first=false; + } + else{ + b.append(","); + } + b.append(String.format("%f", (lpositioner.getStart()+i*lpositioner.getStepSize()))); + } + b.append("]"); + script.append(indentation + var+"_positions="+b.toString()+"\n"); } else if(positioner instanceof ArrayPositioner){ ArrayPositioner apositioner = (ArrayPositioner) positioner; @@ -192,6 +223,12 @@ public class ScanMapperNG { FunctionPositioner fpositioner = (FunctionPositioner) positioner; // TODO take variable mappings into account ! } + else if(positioner instanceof PseudoPositioner){ + // TODO implement + } + else if(positioner instanceof RegionPositioner){ + // TODO implement + } } // Create dimension loop @@ -208,6 +245,7 @@ public class ScanMapperNG { mapActions(d.getAction()); // TODO map guard and sensors + // Check whether final dimension reached if ((index + 1) < dimensions.size()) { @@ -219,8 +257,17 @@ public class ScanMapperNG { script.append(indentation + PROBE_RESOURCE_ID+".read()\n"); } - indentation = indentation.replaceFirst(INDENT, ""); // decrease - // indentation + indentation = indentation.replaceFirst(INDENT, ""); // decrease indentation + + + script.append(indentation + PROBE_RESOURCE_ID+".delimiter("+(dimensions.size()-1-index)+", "+(d.isDataGroup()?"True":"False")+")\n"); + // send delimiter for this dimension + // if lowest dimension end of stream message + // if highest dimension no delimiter + if(index==0){ + script.append(indentation + PROBE_RESOURCE_ID+".terminateStream()\n"); + } + mapActions(d.getPostAction()); } else if (dimension instanceof ContinuousDimension) { // ContinuousDimension d = (ContinuousDimension) dimension; @@ -353,4 +400,5 @@ public class ScanMapperNG { resourceDescriptors.put(varname, new ChannelDescriptor<>(type, channelName, monitor)); return varname; } + } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java similarity index 97% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java index a1f8e0a..900b3a7 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellDescriptor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; /** * Resource descriptor of an operating system shell. diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java similarity index 98% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java index 14f15ca..5e516db 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ShellResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import java.io.BufferedReader; import java.io.IOException; diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java similarity index 96% rename from ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java rename to ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java index ca14fe9..682e339 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import java.util.logging.Logger; @@ -25,6 +25,8 @@ import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestChannels; +import ch.psi.fda.aq.ng.AcquisitionEngineNG; +import ch.psi.fda.aq.ng.ScanMapperNG; import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; @@ -60,7 +62,7 @@ public class AcquisitionEngineNGTest { } /** - * Test method for {@link ch.psi.fda.aq.AcquisitionEngineNG#execute(java.lang.String)}. + * Test method for {@link ch.psi.fda.aq.ng.AcquisitionEngineNG#execute(java.lang.String)}. */ @Test public void testExecuteChannelAction() { diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java similarity index 76% rename from ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java rename to ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java index fa6c5c6..ec1e220 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ScanMapperNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq; +package ch.psi.fda.aq.ng; import static org.junit.Assert.*; @@ -28,10 +28,12 @@ import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestChannels; +import ch.psi.fda.aq.ng.ScanMapperNG; import ch.psi.fda.model.v1.ArrayPositioner; import ch.psi.fda.model.v1.ChannelAction; import ch.psi.fda.model.v1.Configuration; import ch.psi.fda.model.v1.DiscreteStepDimension; +import ch.psi.fda.model.v1.LinearPositioner; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; @@ -61,7 +63,7 @@ public class ScanMapperNGTest { } /** - * Test method for {@link ch.psi.fda.aq.ScanMapperNG#mapActions(java.util.List)}. + * Test method for {@link ch.psi.fda.aq.ng.ScanMapperNG#mapActions(java.util.List)}. */ @Test public void testMap() { @@ -101,6 +103,32 @@ public class ScanMapperNGTest { config.getScan().getDimension().add(d); + mapper.map(config); + String script = mapper.getScript(); + + System.out.println(script); + } + + @Test + public void testMapLinearPositioner() { + + Configuration config = new Configuration(); + config.setScan(new Scan()); + + DiscreteStepDimension d = new DiscreteStepDimension(); + + LinearPositioner positioner = new LinearPositioner(); + positioner.setName(TestChannels.ANALOG_OUT); + positioner.setStart(0.1); + positioner.setEnd(2.2); + positioner.setStepSize(0.1); + + d.getPositioner().add(positioner); + + config.getScan().getDimension().add(d); +// config.getScan().getDimension().add(d); + + mapper.map(config); String script = mapper.getScript(); From 6fedd86d23ffc0e438c92f65d010617806963dae Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 30 Jul 2013 13:19:55 +0200 Subject: [PATCH 07/12] reorganized again debugging some channel access problems ... --- .../ch/psi/fda/aq/ng/AcquisitionEngineNG.java | 6 ++-- .../java/ch/psi/fda/aq/ng/ScanMapperNG.java | 2 ++ .../{ => rdescriptors}/ProbeDescriptor.java | 2 +- .../{ => rdescriptors}/ShellDescriptor.java | 2 +- .../{ => resources}/ChannelProbeResource.java | 2 +- .../aq/ng/{ => resources}/ShellResource.java | 2 +- .../fda/aq/ng/AcquisitionEngineNGTest.java | 32 +++++++++++++++++++ .../home/scans/templates/scan1d-table.xml | 22 +++++++++++++ 8 files changed, 64 insertions(+), 6 deletions(-) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/{ => rdescriptors}/ProbeDescriptor.java (96%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/{ => rdescriptors}/ShellDescriptor.java (95%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/{ => resources}/ChannelProbeResource.java (98%) rename ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/{ => resources}/ShellResource.java (98%) create mode 100644 ch.psi.fda/src/test/resources/home/scans/templates/scan1d-table.xml diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java index e26ab53..cccda42 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java @@ -30,8 +30,10 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import ch.psi.fda.core.messages.ComponentMetadata; -import ch.psi.fda.core.messages.DataMessageMetadata; +import ch.psi.fda.aq.ng.rdescriptors.ProbeDescriptor; +import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor; +import ch.psi.fda.aq.ng.resources.ChannelProbeResource; +import ch.psi.fda.aq.ng.resources.ShellResource; import ch.psi.fda.core.messages.Message; import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelDescriptor; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java index 6d12c1e..bfeac41 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java @@ -27,6 +27,8 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Logger; +import ch.psi.fda.aq.ng.rdescriptors.ProbeDescriptor; +import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor; import ch.psi.fda.core.messages.ComponentMetadata; import ch.psi.fda.core.messages.DataMessageMetadata; import ch.psi.fda.model.v1.Action; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java similarity index 96% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java index 67e6325..76a1f7b 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ProbeDescriptor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq.ng; +package ch.psi.fda.aq.ng.rdescriptors; import java.util.ArrayList; import java.util.List; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ShellDescriptor.java similarity index 95% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ShellDescriptor.java index 900b3a7..19d0d4a 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellDescriptor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ShellDescriptor.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq.ng; +package ch.psi.fda.aq.ng.rdescriptors; /** * Resource descriptor of an operating system shell. diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ChannelProbeResource.java similarity index 98% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ChannelProbeResource.java index a816f1e..f5ab025 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ChannelProbeResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ChannelProbeResource.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq.ng; +package ch.psi.fda.aq.ng.resources; import java.util.List; import java.util.concurrent.BlockingQueue; diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java similarity index 98% rename from ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java rename to ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java index 5e516db..50349ac 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ShellResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java @@ -16,7 +16,7 @@ * along with this code. If not, see . * */ -package ch.psi.fda.aq.ng; +package ch.psi.fda.aq.ng.resources; import java.io.BufferedReader; import java.io.IOException; diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java index 682e339..deeab3b 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java @@ -18,6 +18,10 @@ */ package ch.psi.fda.aq.ng; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import org.junit.After; @@ -34,6 +38,10 @@ import ch.psi.fda.model.v1.DiscreteStepDimension; import ch.psi.fda.model.v1.Scan; import ch.psi.fda.model.v1.ScriptAction; import ch.psi.fda.model.v1.ShellAction; +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; /** @@ -171,5 +179,29 @@ public class AcquisitionEngineNGTest { elapsed = end-start; logger.info("Elapsed time: "+elapsed); } + + @Test + public void testCustomScript() { + Map rdescriptors = new HashMap<>(); + rdescriptors.put("x", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false)); + rdescriptors.put("xr", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT2.RBV", false)); + String script = "for i in range(1,5,1):\n"+ + " x.setValueAsync(float(i))\n"+ +// " print xr.getValue()\n"; + " print 'done'\n"; + + engine.execute(rdescriptors, script); + } + + @Test + public void testT() throws ChannelException, InterruptedException, TimeoutException, ExecutionException{ + ChannelService c = new DefaultChannelService(); + Channel ch = c.createChannel(new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false)); + for(double i=0;i<=5.0; i=i+1){ + ch.setValueAsync(i); +// System.out.println(ch.getValue()); + System.out.println("done"); + } + } } diff --git a/ch.psi.fda/src/test/resources/home/scans/templates/scan1d-table.xml b/ch.psi.fda/src/test/resources/home/scans/templates/scan1d-table.xml new file mode 100644 index 0000000..5255c39 --- /dev/null +++ b/ch.psi.fda/src/test/resources/home/scans/templates/scan1d-table.xml @@ -0,0 +1,22 @@ + + + + + + + + 0.0 1.0 2.0 3.0 4.0 + + + + + + + + + + + From 26f2897a7e827d02fcc8cdc82062fe247dd68c6d Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 30 Jul 2013 15:37:06 +0200 Subject: [PATCH 08/12] Fixed asynchronous/nowait confusion --- ch.psi.fda/pom.xml | 2 +- ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java | 3 +-- .../main/java/ch/psi/fda/core/actions/ChannelAccessPut.java | 2 +- .../ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java | 2 +- .../ch/psi/fda/core/actors/ChannelAccessLinearActuator.java | 2 +- .../ch/psi/fda/core/actors/ChannelAccessTableActuator.java | 2 +- ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java | 2 +- .../java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index 24d7835..11b2e01 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -9,7 +9,7 @@ ch.psi jcae - 2.1.10 + 2.1.11 diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java index bfeac41..5fe21e8 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java @@ -222,7 +222,6 @@ public class ScanMapperNG { script.append(indentation + var+"_positions="+b.toString()+"\n"); } else if(positioner instanceof FunctionPositioner){ - FunctionPositioner fpositioner = (FunctionPositioner) positioner; // TODO take variable mappings into account ! } else if(positioner instanceof PseudoPositioner){ @@ -307,7 +306,7 @@ public class ScanMapperNG { } break; case "putq": - script.append(var+".setValueAsync("+getPythonValue(ca.getValue(), type)+")\n"); + script.append(var+".setValueNoWait("+getPythonValue(ca.getValue(), type)+")\n"); break; case "wait": script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+waitTimeout+")\n"); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java index 809b4c0..60b6387 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actions/ChannelAccessPut.java @@ -105,7 +105,7 @@ public class ChannelAccessPut implements Action { logger.finest("Put to channel: "+channel.getName()+ " asynchronous: "+asynchronous); try{ if(asynchronous){ - channel.setValueAsync(value); + channel.setValueNoWait(value); } else{ if(timeout==null){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java index 719492c..74f6a8b 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java @@ -217,7 +217,7 @@ public class ChannelAccessFunctionActuator implements Actor { } } else{ - channel.setValueAsync(fvalue); + channel.setValueNoWait(fvalue); } if(doneChannel != null){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java index ea42a55..7f108b8 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java @@ -198,7 +198,7 @@ public class ChannelAccessLinearActuator implements Actor { } } else{ - channel.setValueAsync(value); + channel.setValueNoWait(value); } if(doneChannel != null){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java index 2d849d4..b167451 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java @@ -183,7 +183,7 @@ public class ChannelAccessTableActuator implements Actor { } } else{ - channel.setValueAsync(table[count]); + channel.setValueNoWait(table[count]); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java index 9bd99d6..825496b 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/OTFBean.java @@ -175,7 +175,7 @@ public class OTFBean { this.command.setValue(Command.STOP.ordinal()); // Do not wait for put to return - this.running.setValueAsync(false); + this.running.setValueNoWait(false); } catch(Exception e){ throw new RuntimeException("Unable to abort OTF logic" ,e); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java index f96f818..ff3ae6a 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java @@ -116,7 +116,7 @@ public class ParallelCrlogicTest { ParallelCrlogic pcrlogic = new ParallelCrlogic(crlogic, scrlogic); logger.info("Start scaler"); - scalertemplate.getCommand().setValueAsync(VSC16ScalerChannelsTemplate.Command.Count.ordinal()); + scalertemplate.getCommand().setValueNoWait(VSC16ScalerChannelsTemplate.Command.Count.ordinal()); pcrlogic.prepare(); pcrlogic.execute(); From ef1b318017016b8d844db4e950ff98b8e7a685fd Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Wed, 31 Jul 2013 13:03:37 +0200 Subject: [PATCH 09/12] Latest ideas and tests for FDA NG --- ch.psi.fda/pom.xml | 26 ++++ .../aq/ng/AcquisitionEngineNGResource.java | 73 +++++++++++ .../main/java/ch/psi/fda/aq/ng/LManager.java | 36 ++++++ .../main/java/ch/psi/fda/aq/ng/NGServer.java | 119 ++++++++++++++++++ .../java/ch/psi/fda/aq/ng/ResourceBinder.java | 31 +++++ .../fda/aq/ng/AcquisitionEngineNGTest.java | 8 +- 6 files changed, 289 insertions(+), 4 deletions(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ResourceBinder.java diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index 11b2e01..b7a7982 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -78,6 +78,32 @@ junit 4.11 + + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + 2.0 + + + + org.glassfish.jersey.media + jersey-media-sse + 2.0 + + + + org.glassfish.jersey.media + jersey-media-json-jackson + 2.0 + + + + commons-cli + commons-cli + 1.2 + + diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java new file mode 100644 index 0000000..cbe503b --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq.ng; + +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +/** + * @author ebner + * + */ +@Path("/") +public class AcquisitionEngineNGResource { + + @Inject + private AcquisitionEngineNG engine; + + @Inject + private LManager lmanager; + + @PUT + @Path("logic") + public void execute(String logic){ + Map map = new HashMap<>(); + engine.execute(map, logic); + } + + @PUT + @Path("logic/{id}") + public void setLogic(@PathParam("id") String id, String logic){ + lmanager.getLogics().put(id, logic); + } + + @GET + @Path("logic/{id}") + public String getLogic(@PathParam("id") String id){ + String logic = lmanager.getLogics().get(id); + if(logic==null){ + throw new NotFoundException(); + } + return logic; + } + + @POST + @Path("logic/{id}") + public void executeLogic(@PathParam("id") String id, String logic){ + lmanager.getLogics().put(id, logic); + } +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java new file mode 100644 index 0000000..f2dc445 --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq.ng; + +import java.util.HashMap; +import java.util.Map; + +/** + * Logic Manager + * Basically a map holding id->logic pairs + * + * also holds default resource profiles for logics (rprofiles) + */ +public class LManager { + private final Map logics = new HashMap<>(); + + public Map getLogics(){ + return logics; + } +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java new file mode 100644 index 0000000..84329bf --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/NGServer.java @@ -0,0 +1,119 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq.ng; + +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.concurrent.CountDownLatch; +import java.util.logging.Logger; + +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriBuilderException; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.grizzly.http.server.StaticHttpHandler; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.media.sse.SseFeature; +import org.glassfish.jersey.server.ResourceConfig; + +import sun.misc.Signal; +import sun.misc.SignalHandler; + +/** + * @author ebner + * + */ +@SuppressWarnings("restriction") +public class NGServer { + + private static final Logger logger = Logger.getLogger(NGServer.class.getName()); + + /** + * @param args + * @throws ParseException + * @throws UnknownHostException + * @throws UriBuilderException + * @throws IllegalArgumentException + */ + public static void main(String[] args) throws ParseException, IllegalArgumentException, UriBuilderException, UnknownHostException { + // Option handling + int port = 8080; + + Options options = new Options(); + options.addOption("h", false, "Help"); + options.addOption("p", true, "Server port (default: " + port + ")"); + + GnuParser parser = new GnuParser(); + CommandLine line = parser.parse(options, args); + + if (line.hasOption("p")) { + port = Integer.parseInt(line.getOptionValue("p")); + } + if (line.hasOption("h")) { + HelpFormatter f = new HelpFormatter(); + f.printHelp("dae", options); // definition dae - http://www.urbandictionary.com/define.php?term=dae + return; + } + + URI baseUri = UriBuilder.fromUri("http://" + InetAddress.getLocalHost().getHostName() + "/").port(port).build(); + + // final ResourceConfig resourceConfig = new + // ResourceConfig(ServerSentEventsResource.class, SseFeature.class); + ResourceConfig resourceConfig = new ResourceConfig(SseFeature.class, JacksonFeature.class); + resourceConfig.packages(AcquisitionEngineNGResource.class.getPackage().getName()); + resourceConfig.register(new ResourceBinder()); + HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig); + + // Static content + String home = System.getenv("DAE_BASE"); + if (home == null) { + home = "src/main/assembly"; + } + home = home + "/www"; + server.getServerConfiguration().addHttpHandler(new StaticHttpHandler(home), "/static"); + + logger.info("dae started"); + logger.info(String.format("Management interface available at %sstatic/", baseUri)); + logger.info("Use ctrl+c to stop ..."); + + // Signal handling + final CountDownLatch latch = new CountDownLatch(1); + Signal.handle(new Signal("INT"), new SignalHandler() { + public void handle(Signal sig) { + latch.countDown(); + } + }); + + // Wait for termination, i.e. wait for ctrl+c + try { + latch.await(); + } catch (InterruptedException e) { + } + + server.stop(); + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ResourceBinder.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ResourceBinder.java new file mode 100644 index 0000000..17b849d --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ResourceBinder.java @@ -0,0 +1,31 @@ +package ch.psi.fda.aq.ng; + +import org.glassfish.hk2.utilities.binding.AbstractBinder; +//import org.glassfish.jersey.media.sse.SseBroadcaster; + +//import ch.psi.da.hub.model.Keystore; +import ch.psi.jcae.impl.DefaultChannelService; + +public class ResourceBinder extends AbstractBinder { + + @Override + protected void configure() { + // request scope binding +// bind(MyInjectablePerRequest.class).to(MyInjectablePerRequest.class).in(RequestScope.class); + // singleton binding +// bind(MyInjectableSingleton.class).in(Singleton.class); + // singleton instance binding + +// KeystoreSerializer serializer = new KeystoreSerializer(); +// Keystore keystore = serializer.deserialize(); + +// bind(new SseBroadcaster()).to(SseBroadcaster.class); +// bind(serializer).to(KeystoreSerializer.class); +// bind(new KeystoreBroadcaster()).to(KeystoreBroadcaster.class); +// bind(keystore).to(Keystore.class); + + bind(new AcquisitionEngineNG(new DefaultChannelService())).to(AcquisitionEngineNG.class); + bind(new LManager()).to(LManager.class); + } + +} \ No newline at end of file diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java index deeab3b..3f4fdd5 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java @@ -184,11 +184,11 @@ public class AcquisitionEngineNGTest { public void testCustomScript() { Map rdescriptors = new HashMap<>(); rdescriptors.put("x", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false)); - rdescriptors.put("xr", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT2.RBV", false)); + rdescriptors.put("xr", new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1.RBV", false)); String script = "for i in range(1,5,1):\n"+ - " x.setValueAsync(float(i))\n"+ -// " print xr.getValue()\n"; - " print 'done'\n"; + " x.setValueNoWait(float(i))\n"+ + " print xr.getValue()\n"; +// " print 'done'\n"; engine.execute(rdescriptors, script); } From d91513728838cb39bba2b3dadf20df2f0a7ed364 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Fri, 2 Aug 2013 12:38:58 +0200 Subject: [PATCH 10/12] Added test code for r/edescriptors ... --- .../ch/psi/fda/aq/ng/AcquisitionEngineNG.java | 1 + .../aq/ng/AcquisitionEngineNGResource.java | 108 ++++++++++++++++-- .../java/ch/psi/fda/aq/ng/EDescriptor.java | 52 +++++++++ .../main/java/ch/psi/fda/aq/ng/LManager.java | 26 ++++- .../java/ch/psi/fda/aq/ng/RDescriptor.java | 58 ++++++++++ .../fda/aq/ng/resources/ShellResource.java | 14 +++ 6 files changed, 249 insertions(+), 10 deletions(-) create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/EDescriptor.java create mode 100644 ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/RDescriptor.java diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java index cccda42..5541eaf 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java @@ -110,6 +110,7 @@ public class AcquisitionEngineNG { } catch (ScriptException e) { + logger.info(e.getMessage()); throw new RuntimeException("Action failed while executing the Jython script",e); } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java index cbe503b..7befece 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java @@ -20,14 +20,21 @@ package ch.psi.fda.aq.ng; import java.util.HashMap; import java.util.Map; +import java.util.Set; import javax.inject.Inject; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor; +import ch.psi.jcae.ChannelDescriptor; /** * @author ebner @@ -42,23 +49,30 @@ public class AcquisitionEngineNGResource { @Inject private LManager lmanager; - @PUT +// @PUT +// @Path("logic") +// public void execute(String logic){ +// Map map = new HashMap<>(); +// engine.execute(map, logic); +// } + + @GET @Path("logic") - public void execute(String logic){ - Map map = new HashMap<>(); - engine.execute(map, logic); + @Produces(MediaType.APPLICATION_JSON) + public Set getLogics(){ + return lmanager.getLogics(); } @PUT @Path("logic/{id}") public void setLogic(@PathParam("id") String id, String logic){ - lmanager.getLogics().put(id, logic); + lmanager.addLogic(id, logic); } @GET @Path("logic/{id}") public String getLogic(@PathParam("id") String id){ - String logic = lmanager.getLogics().get(id); + String logic = lmanager.getLogic(id); if(logic==null){ throw new NotFoundException(); } @@ -67,7 +81,85 @@ public class AcquisitionEngineNGResource { @POST @Path("logic/{id}") - public void executeLogic(@PathParam("id") String id, String logic){ - lmanager.getLogics().put(id, logic); + @Consumes(MediaType.APPLICATION_JSON) + public void executeLogic(@PathParam("id") String id, EDescriptor edescriptor){ + + // Before executing the logic first merge the default descriptors and provided descriptors + // Where the provided descriptors take precedence over the default onces. + Map rdesc = new HashMap<>(); + rdesc.putAll(lmanager.getResources(id)); + if (edescriptor.getResources() != null) { + rdesc.putAll(edescriptor.getResources()); + } + + Map map =createResourceDescriptors(rdesc); + engine.execute(map, lmanager.getLogic(id)); + } + + @PUT + @Path("logic/{id}/resources") + public void setLogicResources(@PathParam("id") String id, Map rprofile){ + lmanager.addResources(id, rprofile); + } + + @GET + @Path("logic/{id}/resources") + public Map getLogicResources(@PathParam("id") String id){ + Map rprofile = lmanager.getResources(id); + if(rprofile==null){ + throw new NotFoundException(); + } + return rprofile; + } + + /** + * Create internal resource descriptors based on the rdescriptors passed to the method. + * + * Currently following rdescriptor types are supported: + * - channel + * - shell + * + * @param descriptor + * @return + */ + private Map createResourceDescriptors(Map resourceDescriptors) { + Map map = new HashMap<>(); + + for (String k : resourceDescriptors.keySet()) { + RDescriptor r = resourceDescriptors.get(k); + if (r.getType().equals("channel")) { + Class c; + switch (r.getParameter().get("type").toLowerCase()) { + case "double": + c = Double.class; + break; + case "integer": + c = Integer.class; + break; + case "boolean": + c = Boolean.class; + break; + case "String": + c = String.class; + break; + default: + c = String.class; + } + ; + String name = r.getParameter().get("name"); + boolean monitored = false; + if(r.getParameter().get("monitor")!=null){ + monitored = new Boolean(r.getParameter().get("monitor")); + } + + // Create channel descriptor + ChannelDescriptor cd = new ChannelDescriptor<>(c, name, monitored); + map.put(k, cd); + } + else if (r.getType().equals("shell")) { + map.put(k, new ShellDescriptor()); + } + } + return map; } } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/EDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/EDescriptor.java new file mode 100644 index 0000000..3ddec88 --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/EDescriptor.java @@ -0,0 +1,52 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq.ng; + +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; + +/** + * Execution descriptor - Describes resources and parameters used to execute a logic + */ +@XmlRootElement +@JsonSerialize(include = Inclusion.NON_NULL) // Do not serialize NULL values +public class EDescriptor { + + private Map resources; + private List parameter; + + public Map getResources() { + return resources; + } + public void setResources(Map resources) { + this.resources = resources; + } + public List getParameter() { + return parameter; + } + public void setParameter(List parameter) { + this.parameter = parameter; + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java index f2dc445..f5e9b74 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/LManager.java @@ -20,6 +20,7 @@ package ch.psi.fda.aq.ng; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * Logic Manager @@ -30,7 +31,28 @@ import java.util.Map; public class LManager { private final Map logics = new HashMap<>(); - public Map getLogics(){ - return logics; + /** Default resourses assigned to a logic */ + private final Map> resources = new HashMap<>(); + + public void addLogic(String id, String logic){ + logics.put(id, logic); + resources.put(id, new HashMap()); // No default resources attached to logic } + + public void addResources(String id, Map lresources){ + resources.put(id, lresources); + } + + public String getLogic(String id){ + return logics.get(id); + } + + public Set getLogics(){ + return logics.keySet(); + } + + public Map getResources(String id){ + return resources.get(id); + } + } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/RDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/RDescriptor.java new file mode 100644 index 0000000..494b77d --- /dev/null +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/RDescriptor.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2013 Paul Scherrer Institute. All rights reserved. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This code is distributed in the hope that it will be useful, but without any + * warranty; without even the implied warranty of merchantability or fitness for + * a particular purpose. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + * + */ +package ch.psi.fda.aq.ng; + +import java.util.Map; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; + +/** + * Resource descriptor - Used to identify and/or create resource on server + */ +@XmlRootElement +@JsonSerialize(include = Inclusion.NON_NULL) // Do not serialize NULL values +public class RDescriptor { + + private String ref; + private String type; + private Map parameter; + + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public Map getParameter() { + return parameter; + } + public void setParameter(Map parameter) { + this.parameter = parameter; + } + +} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java index 50349ac..a629b7e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/resources/ShellResource.java @@ -31,6 +31,20 @@ public class ShellResource { private static final Logger logger = Logger.getLogger(ShellResource.class.getName()); + /** + * Execute script/command in shell + * @param script + */ + public void execute(String script){ + execute(script, 0, true); + } + + /** + * Execute script/command in shell + * @param script + * @param returnValue + * @param checkReturnValue + */ public void execute(String script, int returnValue, boolean checkReturnValue){ ProcessBuilder pb = new ProcessBuilder(new String[]{"/bin/bash","-c",script}); pb.redirectErrorStream(true); From 7f59fc1ab2e9cb9de8962d9555ab9f00c2a11c86 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Fri, 2 Aug 2013 15:18:18 +0200 Subject: [PATCH 11/12] Changes for parameters, ... --- .../main/java/ch/psi/fda/aq/Acquisition.java | 2 +- .../ch/psi/fda/aq/ng/AcquisitionEngineNG.java | 79 +++++++++++-------- .../aq/ng/AcquisitionEngineNGResource.java | 12 ++- .../fda/aq/ng/AcquisitionEngineNGTest.java | 7 +- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java index 9478a4c..b30fafc 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java @@ -318,7 +318,7 @@ public class Acquisition { t.start(); if(NEW_ENGINE){ - acquisitionEngine.execute(mapper.getResourceDescriptors(), mapper.getScript()); + acquisitionEngine.execute(mapper.getResourceDescriptors(), mapper.getScript(), new ArrayList()); } else { actionLoop.prepare(); diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java index 5541eaf..ebe7bf3 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java @@ -19,6 +19,7 @@ package ch.psi.fda.aq.ng; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.BlockingQueue; @@ -60,7 +61,7 @@ public class AcquisitionEngineNG { System.setProperty("python.options.internalTablesImpl", "weak"); } - public void execute(Map resourceDescriptors, String script){ + public void execute(Map resourceDescriptors, String script, List parameter){ // TODO Remove debugging messages // For debugging purpose only @@ -73,36 +74,14 @@ public class AcquisitionEngineNG { // Set logger engine.put("logger", logger); - // Retrieve and set resources - for(String k: resourceDescriptors.keySet()){ - if(resourceDescriptors.get(k) instanceof ChannelDescriptor){ - ChannelDescriptor descriptor = (ChannelDescriptor)resourceDescriptors.get(k); - try { - engine.put(k, cservice.createChannel(descriptor)); - } catch (ChannelException | InterruptedException | TimeoutException e) { - throw new RuntimeException("Unable to create resource for channel: "+descriptor.getName(),e); - } - } - else if(resourceDescriptors.get(k) instanceof ShellDescriptor){ - engine.put(k, new ShellResource()); - } - else if(resourceDescriptors.get(k) instanceof ProbeDescriptor){ - ProbeDescriptor descriptor = (ProbeDescriptor) resourceDescriptors.get(k); - List> channels = new ArrayList<>(); - - for(ChannelDescriptor s: descriptor.getSensors()){ - try { - channels.add(cservice.createChannel(s)); - - } catch (ChannelException | InterruptedException | TimeoutException e) { - throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e); - } - } - engine.put(k, new ChannelProbeResource(channels, outQueue)); - } - else{ - throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName()); - } + // Set parameters + engine.put("parameter", parameter); + + // Create/retrieve and set resources + Map resources = createResources(resourceDescriptors); + engine.put("resources", resources); + for(String k: resources.keySet()){ // For convenience make resources also available as variable named by the resource id + engine.put(k, resources.get(k)); } // Execute script @@ -115,6 +94,44 @@ public class AcquisitionEngineNG { } } + private Map createResources(Map resourceDescriptors){ + Map resources = new HashMap<>(); + for(String k: resourceDescriptors.keySet()){ + if(resourceDescriptors.get(k) instanceof ChannelDescriptor){ + ChannelDescriptor descriptor = (ChannelDescriptor)resourceDescriptors.get(k); + try { + resources.put(k, cservice.createChannel(descriptor)); +// engine.put(k, cservice.createChannel(descriptor)); + } catch (ChannelException | InterruptedException | TimeoutException e) { + throw new RuntimeException("Unable to create resource for channel: "+descriptor.getName(),e); + } + } + else if(resourceDescriptors.get(k) instanceof ShellDescriptor){ + resources.put(k, new ShellResource()); +// engine.put(k, new ShellResource()); + } + else if(resourceDescriptors.get(k) instanceof ProbeDescriptor){ + ProbeDescriptor descriptor = (ProbeDescriptor) resourceDescriptors.get(k); + List> channels = new ArrayList<>(); + + for(ChannelDescriptor s: descriptor.getSensors()){ + try { + channels.add(cservice.createChannel(s)); + + } catch (ChannelException | InterruptedException | TimeoutException e) { + throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e); + } + } + resources.put(k, new ChannelProbeResource(channels, outQueue)); +// engine.put(k, new ChannelProbeResource(channels, outQueue)); + } + else{ + throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName()); + } + } + return resources; + } + public BlockingQueue getOutQueue(){ return outQueue; } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java index 7befece..0541b22 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNGResource.java @@ -18,7 +18,9 @@ */ package ch.psi.fda.aq.ng; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -92,8 +94,14 @@ public class AcquisitionEngineNGResource { rdesc.putAll(edescriptor.getResources()); } - Map map =createResourceDescriptors(rdesc); - engine.execute(map, lmanager.getLogic(id)); + Map map = createResourceDescriptors(rdesc); + + List parameters = new ArrayList<>(); + if(edescriptor.getParameter()!=null){ + parameters = edescriptor.getParameter(); + } + + engine.execute(map, lmanager.getLogic(id), parameters); } @PUT diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java index 3f4fdd5..578af2c 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/AcquisitionEngineNGTest.java @@ -18,6 +18,7 @@ */ package ch.psi.fda.aq.ng; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -128,7 +129,7 @@ public class AcquisitionEngineNGTest { logger.info("Script to execute: "+mapper.getScript()); - engine.execute(mapper.getResourceDescriptors(), mapper.getScript()); + engine.execute(mapper.getResourceDescriptors(), mapper.getScript(), new ArrayList()); } @Test @@ -174,7 +175,7 @@ public class AcquisitionEngineNGTest { long start, end, elapsed; start = System.currentTimeMillis(); - engine.execute(mapper.getResourceDescriptors(), mapper.getScript()); + engine.execute(mapper.getResourceDescriptors(), mapper.getScript(), new ArrayList()); end = System.currentTimeMillis(); elapsed = end-start; logger.info("Elapsed time: "+elapsed); @@ -190,7 +191,7 @@ public class AcquisitionEngineNGTest { " print xr.getValue()\n"; // " print 'done'\n"; - engine.execute(rdescriptors, script); + engine.execute(rdescriptors, script, new ArrayList()); } @Test From cbef08682a74cc157ae84a89e4cc42ddca78b598 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Thu, 29 Aug 2013 08:11:35 +0200 Subject: [PATCH 12/12] Added comments and modified some test --- .../ch/psi/fda/aq/ng/AcquisitionEngineNG.java | 17 ++++++++++++++++- .../java/ch/psi/fda/aq/ng/ScanMapperNG.java | 4 ++-- .../fda/aq/ng/rdescriptors/ProbeDescriptor.java | 1 + .../java/ch/psi/fda/aq/ng/ScanMapperNGTest.java | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java index ebe7bf3..b196e08 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/AcquisitionEngineNG.java @@ -61,6 +61,12 @@ public class AcquisitionEngineNG { System.setProperty("python.options.internalTablesImpl", "weak"); } + /** + * Execute the specified script/logic while using the specified resources and paramters + * @param resourceDescriptors + * @param script + * @param parameter + */ public void execute(Map resourceDescriptors, String script, List parameter){ // TODO Remove debugging messages @@ -94,6 +100,14 @@ public class AcquisitionEngineNG { } } + /** + * Create resources based on the passed rDescriptors + * Supported descriptor types are: + * ChannelDescriptor, ShellDescriptor, ProbeDescriptor + * + * @param resourceDescriptors + * @return + */ private Map createResources(Map resourceDescriptors){ Map resources = new HashMap<>(); for(String k: resourceDescriptors.keySet()){ @@ -122,7 +136,8 @@ public class AcquisitionEngineNG { throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e); } } - resources.put(k, new ChannelProbeResource(channels, outQueue)); + // TODO Remove workaround ... + resources.put(k, new ChannelProbeResource(channels, outQueue)); // Configure the probe to use the acquisitions out queue for writing data into // engine.put(k, new ChannelProbeResource(channels, outQueue)); } else{ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java index 5fe21e8..aee0cd7 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/ScanMapperNG.java @@ -52,7 +52,7 @@ import ch.psi.jcae.util.ComparatorOR; import ch.psi.jcae.util.ComparatorREGEX; /** - * @author ebner + * Mapper to transform a FDA v1 xml into the new internal model * */ public class ScanMapperNG { @@ -177,7 +177,7 @@ public class ScanMapperNG { // Use readback probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getReadback(), false)); } - System.out.println(positioner.getId()); +// System.out.println(positioner.getId()); dataMessageMetadata.getComponents().add(new ComponentMetadata(positioner.getId(), (dimensions.size()-1-index))); // TODO Done resource diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java index 76a1f7b..d255f8e 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/ng/rdescriptors/ProbeDescriptor.java @@ -30,6 +30,7 @@ import ch.psi.jcae.ChannelDescriptor; public class ProbeDescriptor { private List> sensors = new ArrayList<>(); + public List> getSensors(){ return sensors; } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java index ec1e220..eddb080 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/aq/ng/ScanMapperNGTest.java @@ -121,7 +121,7 @@ public class ScanMapperNGTest { positioner.setName(TestChannels.ANALOG_OUT); positioner.setStart(0.1); positioner.setEnd(2.2); - positioner.setStepSize(0.1); + positioner.setStepSize(0.000001); d.getPositioner().add(positioner);