* @throws SalsaDeviceException
*/
public void doScanFunction(String scanServerName, Behaviour behaviour, ISensor sensor,
IActuator actuator) throws SalsaDeviceException {
try {
DeviceProxy scanServerProxy = getScanServerProxy(scanServerName);
DeviceAttribute afterRunActionType = new DeviceAttribute("afterRunActionType");
afterRunActionType.insert(behaviour.getType());
scanServerProxy.write_attribute(afterRunActionType);
if (sensor != null) {
// We need the sensor position.
String sensorName = sensor.getName();
if (sensorName != null && !sensorName.trim().equals("")) {
String[] sensorsNamesArray = scanServerProxy.read_attribute("sensors")
.extractStringArray();
int sensorPosition;
for (sensorPosition = 0; sensorPosition < sensorsNamesArray.length; ++sensorPosition) {
if (sensorName.equals(sensorsNamesArray[sensorPosition])) {
break;
}
}
if (sensorPosition < sensorsNamesArray.length) {
DeviceAttribute afterRunActionSensor = new DeviceAttribute(
"afterRunActionSensor");
afterRunActionSensor.insert(sensorPosition);
scanServerProxy.write_attribute(afterRunActionSensor);
}
else {
throw new SalsaDeviceException("Error : sensor " + sensor.getName()
+ " is unknow on the scan server " + scanServerName + ".");
}
}
}
if (actuator != null) {
// We need the actuator position.
String actuatorName = actuator.getName();
if (actuatorName != null && !actuatorName.trim().equals("")) {
String[] actuatorsNamesArray = scanServerProxy.read_attribute("actuators")
.extractStringArray();
int actuatorPosition;
for (actuatorPosition = 0; actuatorPosition < actuatorsNamesArray.length; ++actuatorPosition) {
if (actuatorName.equals(actuatorsNamesArray[actuatorPosition])) {
break;
}
}
if (actuatorPosition < actuatorsNamesArray.length) {
DeviceAttribute afterRunActionActuator = new DeviceAttribute(
"afterRunActionActuator");
afterRunActionActuator.insert(actuatorPosition);
scanServerProxy.write_attribute(afterRunActionActuator);
}
else {
throw new SalsaDeviceException("Error : actuator " + actuator.getName()
+ " is unknow on the scan server " + scanServerName + ".");
}
}
}
scanServerProxy.command_inout("ExecuteAction");
}
catch (DevFailed e) {
invalidateScanServerProxy(scanServerName);
e.printStackTrace();