public void startScan(IConfigK config, String scanServerName) throws SalsaDeviceException {
if (config.getDimensionX().getActuatorsList().size() == 0) {
throw new SalsaDeviceException("Cannot start scan : no actuators were defined.");
}
int timeOut;
DeviceProxy scanServerProxy = ScanServerManager.getScanServerProxy(scanServerName);
if (scanServerProxy != null) {
try {
// Reads the initial value of the time out.
timeOut = scanServerProxy.get_timeout_millis();
try {
// Time out
scanServerProxy.set_timeout_millis(5000);
// Clean
command("Clean");
// ? Scan sequencing.
// scanServerProxy.write_attribute(new DeviceAttribute("scanSequencing", (short)
// 1));
// Partial mode for recording, must be manage by an external client
// setAttribute("dataRecorderPartialMode", false);
// Run name.
String runName = config.getName();
IDirectory directory = config.getDirectory();
while (directory != null) {
runName = directory.getName() + "." + runName;
directory = directory.getDirectory();
}
setAttribute("runName", runName);
// Scan number.
setAttribute("scanNumber", config.getScanNumber());
// Timebases.
List<ITimebase> timebasesList = config.getTimebaseList();
List<String> timebasesNameList = new ArrayList<String>(timebasesList.size());
for (ITimebase timebase : timebasesList) {
if (timebase.isEnabled()) {
timebasesNameList.add(timebase.getName());
}
}
String[] timebasesNameArray = timebasesNameList
.toArray(new String[timebasesNameList.size()]);
setAttribute("timebases", timebasesNameArray);
// Sensors
List<ISensor> sensorsList = config.getSensorsList();
List<String> sensorsNameList = new ArrayList<String>(sensorsList.size());
for (ISensor sensor : sensorsList) {
if (sensor.isEnabled()) {
sensorsNameList.add(sensor.getName());
}
}
String[] sensorsNameArray = sensorsNameList.toArray(new String[sensorsNameList
.size()]);
setAttribute("sensors", sensorsNameArray);
// Actuators
List<IActuator> actuatorsList;
List<String> actuatorsNamesList;
String[] actuatorsNamesArray;
IDimensionK dimension = config.getDimensionX();
actuatorsList = dimension.getActuatorsList();
actuatorsNamesList = new ArrayList<String>(actuatorsList.size());
for (IActuator actuator : actuatorsList) {
if (actuator.isEnabled()) {
actuatorsNamesList.add(actuator.getName());
}
}
actuatorsNamesArray = actuatorsNamesList.toArray(new String[actuatorsNamesList
.size()]);
setAttribute("actuators", actuatorsNamesArray);
// Dimension
// A scan K has a single dimension, a single range, a single trajectory.
ITrajectoryK trajectoryK = config.getDimensionX().getRangeX().getTrajectory();
double[] trajectoriesPositionsArray = TrajectoryCalculator
.calculateKTrajectoriesPosition(trajectoryK);
double[] integrationsTimesArray = TrajectoryCalculator
.calculateIntegrationTimesK(trajectoryK);
int pointNumber = trajectoriesPositionsArray.length;
setAttribute("pointNumber", pointNumber);
DeviceAttribute trajectoriesAttribute = new DeviceAttribute("trajectories");
trajectoriesAttribute.insert(trajectoriesPositionsArray, pointNumber, 1);
scanServerProxy.write_attribute(trajectoriesAttribute);
setAttribute("integrationTimes", integrationsTimesArray);
// Actuator delay.
double actuatorsDelay = config.getActuatorsDelay();
setAttribute("actuatorsDelay", actuatorsDelay);
// Zig zag.
boolean zigzag = config.isZigzag();
setAttribute("zigzag", zigzag);
// Enable actuator speed.
boolean enableScanSpeed = config.isEnableScanSpeed();
setAttribute("enableScanSpeed", enableScanSpeed);
// Post scan behaviour.
IPostScanBehaviour postScanBehaviour = config.getScanAddOn()
.getPostScanBehaviour();
Behaviour behaviour = postScanBehaviour.getBehaviour();
if (behaviour == null) {
behaviour = Behaviour.NOOP;
}
int behaviourType = behaviour.getType();
setAttribute("afterRunActionType", behaviourType);
if (behaviour.getArgumentCount() >= 1) {
int behaviourSensorIndex = postScanBehaviour.getSensor();
setAttribute("afterRunActionSensor", behaviourSensorIndex);
}
else if (behaviour.getArgumentCount() >= 2) {
int behaviourActuatorIndex = postScanBehaviour.getActuator();
setAttribute("afterRunActionActuator", behaviourActuatorIndex);
}
// Error strategies.
if (config.getScanAddOn() != null
&& config.getScanAddOn().getErrorStrategy() != null) {
IErrorStrategy errorStrat = config.getScanAddOn().getErrorStrategy();
IErrorStrategyItem[] categoriesESI = new IErrorStrategyItem[] {
errorStrat.getActuatorsErrorStrategy(),
errorStrat.getSensorsErrorStrategy(),
errorStrat.getTimebasesErrorStrategy(),
errorStrat.getHooksErrorStrategy() };
String[] categoriesStr = new String[] { "actuators", "sensors",
"timebases", "hooks" };
for (int i = 0; i < categoriesStr.length; i++) {
String cat = categoriesStr[i];
IErrorStrategyItem esi = categoriesESI[i];
double errorStrategyTimeOut = esi.getTimeOut();
int errorStrategyRetryCount = esi.getRetryCount();
double errorStrategyRetryTimeOut = esi.getTimeBetweenRetries();
int errorStrategyType = esi.getStrategy().ordinal();
// Time out.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "TimeOut",
errorStrategyTimeOut));
// Retry count.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "RetryCount",
errorStrategyRetryCount));
// Retry time out.
scanServerProxy.write_attribute(new DeviceAttribute(cat
+ "RetryTimeOut", errorStrategyRetryTimeOut));
// Error strategy.
scanServerProxy.write_attribute(new DeviceAttribute(cat
+ "ErrorStrategy", errorStrategyType));
}
// Context validation error strategy.
scanServerProxy.write_attribute(new DeviceAttribute(
"contextValidationErrorStrategy", errorStrat
.getContextValidationStrategy().ordinal()));
scanServerProxy.write_attribute(new DeviceAttribute("contextValidation",
errorStrat.getContextValidationDevice()));
}
/* Hooks */
SetHooks(config.getScanAddOn(), scanServerProxy);
// Hardware continuous scan : no.
setAttribute("hwContinuous", false);
// On the fly mode (software continuous mode).
boolean onTheFly = config.isOnTheFly();
setAttribute("onTheFly", onTheFly);
// Fin configuration du scan.
// D�marrage du scan.
command("Start");
}
finally {
// Sets the time out back to the initial value.
scanServerProxy.set_timeout_millis(timeOut);
}
}
catch (DevFailed e) {
e.printStackTrace();
String message = e.getMessage();