*
* @return
* @throws SalsaDeviceException
*/
public IScanResult1D readScanResult() throws SalsaDeviceException {
IScanResult1D scanResult = null;
DeviceProxy scanServerProxy = ScanServerManager.getScanServerProxy(scanServerName);
if (scanServerProxy != null) {
if (isScanResultReady()) {
int pointIndex;
try {
// Type
DeviceAttribute scanTypeAttribute = scanServerProxy.read_attribute("scanType");
int scanType = scanTypeAttribute.extractLong();
if (scanType != 1 && scanType != 0) {
return null;
}
scanResult = new ScanResult1DImpl();
scanResult.setScanServer(scanServerName);
scanResult.setResultType(IScanResult.ResultType.RESULT_1D);
// Name.
DeviceAttribute runNameAttribute = scanServerProxy.read_attribute("runName");
String runName = runNameAttribute.extractString();
scanResult.setRunName(runName);
// Time
double[] timesArray = scanServerProxy.read_attribute("sensorsTimeStamps")
.extractDoubleArray();
List<IScanPoint> scanPointsList = new ArrayList<IScanPoint>(timesArray.length);
IScanPoint scanPoint;
for (double time : timesArray) {
scanPoint = new ScanPointImpl();
scanPoint.setTime(time);
scanPointsList.add(scanPoint);
}
// Sensors
String[] sensorsNamesArrayTmp = scanServerProxy.read_attribute("sensors")
.extractStringArray();
// The sensorsNamesArrayTmp contains the data twice : once for reading and once
// for
// writing.
String[] sensorsNamesArray = new String[sensorsNamesArrayTmp.length / 2];
for (int sensorIndex = 0; sensorIndex < sensorsNamesArray.length; ++sensorIndex) {
sensorsNamesArray[sensorIndex] = sensorsNamesArrayTmp[sensorIndex];
}
String[] sensorsValueKeysArray = scanServerProxy.read_attribute(
"sensorsDataList").extractStringArray();
ISensor sensor;
String sensorValueKey;
String sensorName;
double[] sensorValuesArray;
TangoAttribute attribute;
for (int sensorIndex = 0; sensorIndex < sensorsNamesArray.length
&& sensorIndex < sensorsValueKeysArray.length; ++sensorIndex) {
sensorName = sensorsNamesArray[sensorIndex];
sensor = new SensorImpl();
sensor.setName(sensorName);
sensor.setEnabled(true);
scanResult.getSensorsList().add(sensor);
sensorValueKey = sensorsValueKeysArray[sensorIndex];
attribute = new TangoAttribute(scanServerName + "/" + sensorValueKey);
sensorValuesArray = (double[]) attribute.readArray(Double.TYPE);
sensor.setScanServerAttributeName(scanServerProxy.get_name() + "/"
+ sensorValueKey);
pointIndex = 0;
for (double sensorValue : sensorValuesArray) {
// The reading can occur during the scan. Because of this, more values
// can
// have been added since
// scanPointsList was initialized. Hence the test scanPointsList.size()
// >
// pointIndex.
if (scanPointsList.size() > pointIndex) {
scanPoint = scanPointsList.get(pointIndex);
scanPoint.getSensorsValuesMap().put(sensor, sensorValue);
}
++pointIndex;
}
}
// Actuators dimension X
String[] actuatorsXNamesArrayTmp = scanServerProxy.read_attribute("actuators")
.extractStringArray();
// The actuatorsXNamesArrayTmp contains the data twice : once for reading and
// once
// for writing.
String actuatorXName;
String[] actuatorsXNamesArray = new String[actuatorsXNamesArrayTmp.length / 2];
for (int actuatorXIndex = 0; actuatorXIndex < actuatorsXNamesArray.length; ++actuatorXIndex) {
actuatorsXNamesArray[actuatorXIndex] = actuatorsXNamesArrayTmp[actuatorXIndex];
}
String[] actuatorsXValueKeysArray = scanServerProxy.read_attribute(
"actuatorsDataList").extractStringArray();
IActuator actuatorX;
String actuatorXValueKey;
double[] actuatorXValuesArray;
for (int actuatorXIndex = 0; actuatorXIndex < actuatorsXNamesArray.length
&& actuatorXIndex < actuatorsXValueKeysArray.length; ++actuatorXIndex) {
actuatorXName = actuatorsXNamesArray[actuatorXIndex];
actuatorX = new ActuatorImpl();
actuatorX.setName(actuatorXName);
actuatorX.setEnabled(true);
scanResult.getActuatorsXList().add(actuatorX);
actuatorXValueKey = actuatorsXValueKeysArray[actuatorXIndex];
attribute = new TangoAttribute(scanServerName + "/" + actuatorXValueKey);
actuatorXValuesArray = (double[]) attribute.readArray(Double.TYPE);
actuatorX.setScanServerAttributeName(scanServerProxy.get_name() + "/"
+ actuatorXValueKey);
pointIndex = 0;
for (double actuatorXValue : actuatorXValuesArray) {
// The reading can occur during the scan. Because of this, more values
// can have been added since scanPointsList was initialized. Hence the
// test scanPointsList.size() > pointIndex.
if (scanPointsList.size() > pointIndex) {
scanPoint = scanPointsList.get(pointIndex);
scanPoint.getActuatorsXValuesMap().put(actuatorX, actuatorXValue);
}
++pointIndex;
}
}
scanResult.setScanPointsList(scanPointsList);
}
catch (DevFailed e) {
e.printStackTrace();
String errorMessage = "Error while reading the scan result.";
if (e.getMessage() != null) {