Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceProxy


            throw new SalsaDeviceException("Error : invalid device name " + name + " : no \"/\".",
                    false);
        }
        String deviceName = name.substring(0, separatorPos);
        String attributeName = name.substring(separatorPos + 1);
        DeviceProxy proxy = getDeviceProxy(deviceName);
        if (proxy == null) {
            return null;
        }
        return getDeviceAttribute(proxy, attributeName);
    }
View Full Code Here


     * @return
     * @throws SalsaDeviceException
     */
    private static void writeAttribute(IDevice device, DeviceAttribute attribute)
            throws SalsaDeviceException {
        DeviceProxy proxy = getDeviceProxy(device);
        try {
            if (proxy != null && attribute != null) {
                proxy.write_attribute(attribute);
            }
        }
        catch (DevFailed e) {
            e.printStackTrace();
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
View Full Code Here

        if (separatorPos < 0) {
            throw new SalsaDeviceException("Error : invalid device name " + name + " : no \"/\".",
                    false);
        }
        String attributeName = name.substring(separatorPos + 1);
        DeviceProxy proxy = getDeviceProxy(device);
        if (proxy == null) {
            return null;
        }
        AttributeInfo info = getAttributeInfo(proxy, attributeName);
        return info;
View Full Code Here

                    false);
        }
        String deviceName = name.substring(0, separatorPos);
        String attributeName = name.substring(separatorPos + 1);

        DeviceProxy proxy = getDeviceProxy(deviceName);
        DeviceAttribute attribute = getDeviceAttribute(proxy, attributeName);
        AttributeInfo info = getAttributeInfo(proxy, attributeName);
        // Report.

        // Readable / writable.
        boolean readable;
        boolean writeable;
        switch (info.writable.value()) {
            case AttrWriteType._READ:
                readable = true;
                writeable = false;
                break;
            case AttrWriteType._READ_WITH_WRITE:
            case AttrWriteType._READ_WRITE:
                readable = true;
                writeable = true;
                break;
            case AttrWriteType._WRITE:
                readable = false;
                writeable = true;
                break;
            default:
                // Normally impossible.
                throw new SalsaDeviceException("Unknown write type for the device " + name + ".");
        }
        report.setReadable(readable);
        report.setWriteable(writeable);

        // Data and data format.
        try {
            TangoAttribute tangoAttribute = new TangoAttribute(name);

            double[] rawData;
            switch (info.data_format.value()) {
                case AttrDataFormat._SCALAR:
                    report.setDimensionType(DimensionType.SCALAR);
                    rawData = AttributeHelper.extractToDoubleArray(attribute);
                    if (readable) {
                        report.setReadScalarData(rawData[0]);
                    }
                    else {
                        report.setReadScalarData(null);
                    }
                    if (writeable) {
                        Double dataWritten = tangoAttribute.readWritten(Double.class);
                        report.setWriteScalarData(dataWritten);
                    }
                    else {
                        report.setWriteScalarData(null);
                    }
                    report.setReadSpectrumData(null);
                    report.setWriteSpectrumData(null);
                    report.setReadImageData(null);
                    report.setWriteImageData(null);
                    break;
                case AttrDataFormat._SPECTRUM:
                    report.setDimensionType(DimensionType.SPECTRUM);
                    rawData = AttributeHelper.extractToDoubleArray(attribute);
                    int spectrumLength = attribute.getDimX();
                    Double[] readSpectrumData = null;
                    Double[] writeSpectrumData = null;

                    if (readable) {
                        readSpectrumData = new Double[spectrumLength];
                        writeSpectrumData = null;
                        for (int index = 0; index < spectrumLength; ++index) {
                            readSpectrumData[index] = rawData[index];
                        }
                    }

                    if (writeable) {
                        writeSpectrumData = new Double[spectrumLength];
                        for (int index = 0; index < spectrumLength; ++index) {
                            writeSpectrumData = tangoAttribute.readSpecOrImage(Double.class);

                        }

                    }
                    report.setReadScalarData(null);
                    report.setWriteScalarData(null);
                    report.setReadSpectrumData(readSpectrumData);
                    report.setWriteSpectrumData(writeSpectrumData);
                    report.setReadImageData(null);
                    report.setWriteImageData(null);
                    break;
                case AttrDataFormat._IMAGE:
                    report.setDimensionType(DimensionType.IMAGE);
                    rawData = AttributeHelper.extractToDoubleArray(attribute);
                    int xDim = attribute.getDimX();
                    int yDim = attribute.getDimY();
                    Double[][] readImageData;
                    Double[][] writeImageData;
                    Double[] writtenImage = tangoAttribute.readSpecOrImage(Double.class);
                    int yOffset;
                    if (readable) {
                        readImageData = new Double[yDim][xDim];
                        if (writeable) {
                            writeImageData = new Double[yDim][xDim];

                            for (int yPos = 0; yPos < yDim; ++yPos) {
                                yOffset = yPos * xDim;

                                for (int xPos = 0; xPos < xDim; ++xPos) {
                                    readImageData[yPos][xPos] = rawData[xPos + yOffset];
                                    writeImageData[yPos][xPos] = writtenImage[xPos + yOffset];

                                }
                            }
                        }
                        else {
                            writeImageData = null;
                            for (int yPos = 0; yPos < yDim; ++yPos) {
                                yOffset = yPos * xDim;
                                for (int xPos = 0; xPos < xDim; ++xPos) {
                                    readImageData[yPos][xPos] = rawData[xPos + yOffset];
                                }
                            }
                        }
                    }
                    else {
                        readImageData = null;
                        if (writeable) {
                            writeImageData = new Double[yDim][xDim];
                            for (int yPos = 0; yPos < yDim; ++yPos) {
                                yOffset = yPos * xDim;
                                for (int xPos = 0; xPos < xDim; ++xPos) {
                                    writeImageData[yPos][xPos] = writtenImage[xPos + yOffset];
                                }
                            }
                        }
                        else {
                            writeImageData = null;
                        }
                    }
                    report.setReadScalarData(null);
                    report.setWriteScalarData(null);
                    report.setReadSpectrumData(null);
                    report.setWriteSpectrumData(null);
                    report.setReadImageData(readImageData);
                    report.setWriteImageData(writeImageData);
                    break;
                default:
                    // Normally impossible.
                    throw new SalsaDeviceException("Unknown data format for the device " + name
                            + ".");
            }
        }
        catch (DevFailed e) {
            e.printStackTrace();
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                    "Error while trying to read the TangORB attribute data for the device "
                            + device.getName() + ".", e);
            throw salsaDeviceException;
        }

        String quality;
        try {
            quality = QualityUtilities.getNameForQuality(attribute.getQuality());
        }
        catch (DevFailed e) {
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                    "Error while trying to read the quality of the TangORB attribute value for the device "
                            + device.getName() + ".", e);
            throw salsaDeviceException;
        }
        report.setQuality(quality);

        String state;
        try {
            state = StateUtilities.getNameForState(proxy.state());
        }
        catch (DevFailed e) {
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                    "Error while trying to read the state of the TangORB attribute value for the device "
                            + device.getName() + ".", e);
View Full Code Here

     * @throws SalsaDeviceException
     */
    public static String getState(ITimebase timebase) throws SalsaDeviceException {
        String state = null;
        try {
            DeviceProxy proxy = getDeviceProxy(timebase);
            DevState tmpDevState = proxy.state();
            state = StateUtilities.getNameForState(tmpDevState);

        }
        catch (DevFailed e) {
            state = StateUtilities.getNameForState(DevState.UNKNOWN);
View Full Code Here

     * @throws SalsaDeviceException
     */
    private static DeviceProxy getDeviceProxy(ITimebase timebase) throws SalsaDeviceException {
        String deviceName = timebase.getName();
       
        DeviceProxy proxy;
        try {
            proxy = new DeviceProxy(deviceName);
        }
        catch(DevFailed e) {
            e.printStackTrace();
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                    "Error while creating a TangORB device for the timebase " + timebase.getName() + ".", e);
View Full Code Here

        }
    }

    protected void initScanCommon(IConfig<?> config, String scanServerName) throws SalsaDeviceException {
        LOGGER.trace("initScanCommon({})", config);
        DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
        if (scanServerProxy != null) {
            try {

                // Time out
                actionName = "set_timeout_millis(10000)";
                LOGGER.trace("{}/{}", scanServerName, actionName);
                scanServerProxy.set_timeout_millis(10000);

                // First Init Clean
                // command("Clean");//The Clean command do not clean anything
                // bug 0023724
                command("Init");

                // Partial mode for recording,clean set mode to false
                boolean isPartialMode = isDataRecorderPartialMode();
                actionName = writeAttributeLog(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE,
                        String.valueOf(isPartialMode));
                setAttribute(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE, isPartialMode, false);

                // Run name JIRA SCAN-163
                String runName = config.getRunName();
                if ((runName == null) || runName.trim().isEmpty()) {
                    String configName = config.getName();

                    IDirectory directory = config.getDirectory();
                    while (directory != null) {
                        configName = directory.getName() + "." + configName;
                        directory = directory.getDirectory();
                    }
                    runName = configName;
                }

                actionName = writeAttributeLog(CurrentScanDataModel.RUN_NAME, runName);
                setAttribute(CurrentScanDataModel.RUN_NAME, runName, false);

                // Scan number.
                int scanNumber = config.getScanNumber();
                actionName = writeAttributeLog(CurrentScanDataModel.SCAN_NUMBER, String.valueOf(scanNumber));
                setAttribute(CurrentScanDataModel.SCAN_NUMBER, scanNumber, false);

                // Timebases
                List<ITimebase> timebasesList = config.getTimebaseList();
                List<String> timebasesNameList = new ArrayList<String>(timebasesList.size());
                String deviceName = null;
                for (ITimebase timebase : timebasesList) {
                    deviceName = timebase.getName();
                    if (timebase.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
                        timebasesNameList.add(timebase.getName());
                    }
                }
                String[] timebasesNameArray = timebasesNameList.toArray(new String[timebasesNameList.size()]);

                actionName = writeAttributeLog(CurrentScanDataModel.TIMEBASES, Arrays.toString(timebasesNameArray));
                setAttribute(CurrentScanDataModel.TIMEBASES, timebasesNameArray, false);

                // Sensors
                List<ISensor> sensorsList = config.getSensorsList();
                List<String> sensorsNameList = new ArrayList<String>(sensorsList.size());
                for (ISensor sensor : sensorsList) {
                    deviceName = sensor.getName();
                    if (sensor.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
                        sensorsNameList.add(sensor.getName());
                    }
                }
                String[] sensorsNameArray = sensorsNameList.toArray(new String[sensorsNameList.size()]);
                actionName = writeAttributeLog(CurrentScanDataModel.SENSORS_LIST, Arrays.toString(sensorsNameArray));
                setAttribute(CurrentScanDataModel.SENSORS_LIST, sensorsNameArray, false);

                // Actuator delay.
                double actuatorsDelay = config.getActuatorsDelay();
                actionName = writeAttributeLog(CurrentScanDataModel.ACTUATOR_DELAY, String.valueOf(actuatorsDelay));
                setAttribute(CurrentScanDataModel.ACTUATOR_DELAY, actuatorsDelay, false);

                // Zig zag.
                boolean zigzag = config.isZigzag();
                actionName = writeAttributeLog(CurrentScanDataModel.ZIGZAG, String.valueOf(zigzag));
                setAttribute(CurrentScanDataModel.ZIGZAG, zigzag, false);

                // Enable actuator speed.
                boolean enableScanSpeed = config.isEnableScanSpeed();
                actionName = writeAttributeLog(CurrentScanDataModel.ENABLESCANSPEED, String.valueOf(enableScanSpeed));
                setAttribute(CurrentScanDataModel.ENABLESCANSPEED, enableScanSpeed, false);

                // Post scan behaviour.
                IPostScanBehaviour postScanBehaviour = config.getScanAddOn().getPostScanBehaviour();
                Behaviour behaviour = postScanBehaviour.getBehaviour();
                if (behaviour == null) {
                    behaviour = Behaviour.NOOP;
                }
                int behaviourType = behaviour.getType();
                actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_TYPE, String.valueOf(behaviourType));
                setAttribute(CurrentScanDataModel.AFTER_ACTION_TYPE, behaviourType, false);

                if (behaviour.getArgumentCount() >= 1) {
                    int behaviourSensorIndex = postScanBehaviour.getSensor();
                    actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_SENSOR,
                            String.valueOf(behaviourSensorIndex));
                    setAttribute(CurrentScanDataModel.AFTER_ACTION_SENSOR, behaviourSensorIndex, false);
                } else if (behaviour.getArgumentCount() >= 2) {
                    int behaviourActuatorIndex = postScanBehaviour.getActuator();
                    actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_ACTUATOR,
                            String.valueOf(behaviourActuatorIndex));
                    setAttribute(CurrentScanDataModel.AFTER_ACTION_ACTUATOR, behaviourActuatorIndex, false);
                }

                // 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.
                        String catAttribute = cat + "TimeOut";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyTimeOut));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyTimeOut));
                        // Retry count.
                        catAttribute = cat + "RetryCount";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryCount));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryCount));
                        // Retry time out.
                        catAttribute = cat + "RetryTimeOut";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryTimeOut));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryTimeOut));
                        // Error strategy.
                        catAttribute = cat + "ErrorStrategy";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyType));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyType));
                    }
                    // Context validation error strategy.
                    int erreurStrategyValue = errorStrat.getContextValidationStrategy().ordinal();
                    actionName = writeAttributeLog(CurrentScanDataModel.CONTEXT_VALIDATION_STRATEGY,
                            String.valueOf(erreurStrategyValue));
View Full Code Here

        String indexStr = String.valueOf(dimensionIndex);
        if (dimensionIndex == 1) {
            indexStr = "";
        }

        DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
        if ((scanServerProxy != null) && (dimension != null)) {
            try {
                List<String> actuatorsNamesList;
                String[] actuatorsNamesArray;
                List<IActuator> actuatorsList = dimension.getActuatorsList();
                actuatorsNamesList = new ArrayList<String>(actuatorsList.size());
                String deviceName = null;
                for (IActuator actuator : actuatorsList) {
                    deviceName = actuator.getName();
                    if (actuator.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
                        actuatorsNamesList.add(deviceName);
                    }
                }
                actuatorsNamesArray = actuatorsNamesList.toArray(new String[actuatorsNamesList.size()]);

                String actuatorName = "actuators" + indexStr;
                actionName = writeAttributeLog(actuatorName, Arrays.toString(actuatorsNamesArray));
                setAttribute(actuatorName, actuatorsNamesArray, false);

                // Dimensions
                // Tango exchanges trajectories as double arrays that contains
                // the positions, in
                // order,
                // actuator after actuator, range after range, of the
                // trajectories of all the
                // actuators.
                // There is one such array per dimension.
                double[] allActuatorsPositionsArray;
                double initialValue;
                double[] integrationsTimesArray;
                // Contains the positions in order, range after range, of the
                // trajectories of an
                // actuator.
                List<Double> actuatorPositionsList;
                // Contains the positions in order, actuator after actuator,
                // range after range,
                // of
                // the trajectories of all the actuators.
                List<Double> allActuatorsPositionsList;
                // The list of integrations times.
                List<Double> integrationsTimesList;
                int integrationTimeIndex;
                // The list of speeds.
                List<Double> speedList = new ArrayList<Double>();
                // The number of points, which is the total steps numbers + 1
                // per range.
                int totalStepsNumber;
                // The positions, sorted as Tango expect them.
                allActuatorsPositionsList = new ArrayList<Double>();

                // The number of enabled actuators.
                int enabledActuatorsNumber = 0;

                if (dimension instanceof IDimensionK) {
                    enabledActuatorsNumber = 1;
                    ITrajectoryK trajectoryK = ((IDimensionK) dimension).getRangeX().getTrajectory();
                    allActuatorsPositionsArray = TrajectoryCalculator.calculateKTrajectoriesPosition(trajectoryK);
                    integrationsTimesArray = TrajectoryCalculator.calculateIntegrationTimesK(trajectoryK);
                    totalStepsNumber = allActuatorsPositionsArray.length;
                    speedList.add(trajectoryK.getSpeed());
                } else {
                    // The positions must be sorted by actuator, so we loop over
                    // the actuators.
                    for (int index = 0; index < actuatorsList.size(); index++) {
                        IActuator actuator = actuatorsList.get(index);
                        deviceName = actuator.getName();
                        if (actuator.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
                            actuatorPositionsList = new ArrayList<Double>();
                            // For each actuators, the positions must be sorted
                            // by range.
                            List<ITrajectory> completetrajectoryList = findActuatorTrajectories(dimension, index);
                            List<ITrajectory> trajectoryList = new ArrayList<ITrajectory>();
                            if (onTheFly) {
                                trajectoryList.add(completetrajectoryList.get(0));
                            } else {
                                trajectoryList.addAll(completetrajectoryList);
                            }

                            initialValue = DeviceConnector.getData(actuator);

                            for (ITrajectory trajectory : trajectoryList) {
                                actuatorPositionsList
                                .addAll(TrajectoryCalculator.calculateLinearTrajectoriesPosition(trajectory,
                                        initialValue, (onTheFly || (trajectory instanceof ITrajectoryHCS))));
                                // The speeds must be sorted in the same order,
                                // so we read them
                                // here.
                                speedList.add(trajectory.getSpeed());
                            }
                            allActuatorsPositionsList.addAll(actuatorPositionsList);
                            ++enabledActuatorsNumber;
                        }
                    }

                    // Integration Time and steps number.
                    List<? extends IRange> getRangeList = dimension.getRangeList();
                    List<IRange> rangeList = new ArrayList<IRange>();

                    if (onTheFly) {
                        rangeList.add(getRangeList.get(0));
                    } else {
                        rangeList.addAll(getRangeList);
                    }

                    integrationsTimesList = new ArrayList<Double>(rangeList.size());
                    int stepsNumber;
                    totalStepsNumber = 0;
                    for (IRange range : rangeList) {
                        if ((range instanceof IRangeHCS) || onTheFly) {
                            stepsNumber = 1;
                        } else {
                            stepsNumber = range.getStepsNumber();
                        }

                        if (range instanceof IRangeIntegrated) {
                            for (integrationTimeIndex = 0; integrationTimeIndex < stepsNumber + 1; ++integrationTimeIndex) {
                                integrationsTimesList.add(((IRangeIntegrated) range).getIntegrationTime());
                            }
                        }
                        totalStepsNumber += stepsNumber + 1;
                    }

                    // Builds the array from the list.
                    allActuatorsPositionsArray = toDoubleArray(allActuatorsPositionsList);

                    // Integration Time
                    integrationsTimesArray = toDoubleArray(integrationsTimesList);

                }

                String pointNumberName = "pointNumber" + indexStr;
                actionName = writeAttributeLog(pointNumberName, String.valueOf(totalStepsNumber));
                setAttribute(pointNumberName, totalStepsNumber, false);

                // Trajectories.
                // Sends the array to Tango.
                String trajectoriesName = "trajectories" + indexStr;
                DeviceAttribute trajectoriesAttribute = new DeviceAttribute(trajectoriesName);
                if (enabledActuatorsNumber != 0) {
                    trajectoriesAttribute.insert(allActuatorsPositionsArray, totalStepsNumber, enabledActuatorsNumber);
                } else {
                    trajectoriesAttribute.insert(new double[] {}, 0, 1);
                }

                // Attribute only manage in X dimension
                if (dimensionIndex == 1) {
                    actionName = writeAttributeLog("integrationTimes", Arrays.toString(integrationsTimesArray));
                    setAttribute("integrationTimes", integrationsTimesArray, false);

                    // Speed.
                    double[] speedArray = toDoubleArray(speedList);
                    actionName = writeAttributeLog("scanSpeed", Arrays.toString(speedArray));
                    setAttribute("scanSpeed", speedArray, false);
                }

                actionName = writeAttributeLog(trajectoriesName, Arrays.toString(allActuatorsPositionsArray));
                scanServerProxy.write_attribute(trajectoriesAttribute);

            } catch (DevFailed e) {
                if (actionName == null) {
                    actionName = "";
                }
View Full Code Here

        return actuatorTrajectoriesList;
    }

    public IScanResult retrieveCommonScanResult(boolean withTrajectories) throws SalsaDeviceException {
        IScanResult scanResult = null;
        DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
        if (scanServerProxy != null) {
            if (isScanResultReady()) {
                try {
                    // Type
                    actionName = "read_attribute(\"" + CurrentScanDataModel.SCAN_TYPE + "\")";
                    DeviceAttribute scanTypeAttribute = scanServerProxy.read_attribute(CurrentScanDataModel.SCAN_TYPE);
                    int scanType = scanTypeAttribute.extractLong();
                    LOGGER.trace("{}.{}={}", scanServerName, actionName, String.valueOf(scanType));
                    // 0 -> time scan
                    // 1 -> scan 1d
                    // 2 -> scan 2d
View Full Code Here

            }
        }
    }

    protected void initScanCommon(IConfig<?> config, String scanServerName) throws SalsaDeviceException {
        DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
        if (scanServerProxy != null) {
            try {

                // Time out
                actionName = "set_timeout_millis(10000)";
                scanServerProxy.set_timeout_millis(10000);

                // First Init Clean
                actionName = "command_inout(\"Init\")";
                // command("Clean");//The Clean command do not clean anything
                // bug 0023724
                command("Init");

                // Partial mode for recording,clean set mode to false
                boolean isPartialMode = isDataRecorderPartialMode();
                actionName = writeAttributeLog(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE,
                        String.valueOf(isPartialMode));
                setAttribute(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE, isPartialMode, false);

                // Run name.
                String runName = config.getName();
                IDirectory directory = config.getDirectory();
                while (directory != null) {
                    runName = directory.getName() + "." + runName;
                    directory = directory.getDirectory();
                }

                actionName = writeAttributeLog(CurrentScanDataModel.RUN_NAME, runName);
                setAttribute(CurrentScanDataModel.RUN_NAME, runName, false);

                // Scan number.
                int scanNumber = config.getScanNumber();
                actionName = writeAttributeLog(CurrentScanDataModel.SCAN_NUMBER, String.valueOf(scanNumber));
                setAttribute(CurrentScanDataModel.SCAN_NUMBER, scanNumber, false);

                // 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()]);

                actionName = writeAttributeLog(CurrentScanDataModel.TIMEBASES, Arrays.toString(timebasesNameArray));
                setAttribute(CurrentScanDataModel.TIMEBASES, timebasesNameArray, false);

                // 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()]);
                actionName = writeAttributeLog(CurrentScanDataModel.SENSORS_LIST, Arrays.toString(sensorsNameArray));
                setAttribute(CurrentScanDataModel.SENSORS_LIST, sensorsNameArray, false);

                // Actuator delay.
                double actuatorsDelay = config.getActuatorsDelay();
                actionName = writeAttributeLog(CurrentScanDataModel.ACTUATOR_DELAY, String.valueOf(actuatorsDelay));
                setAttribute(CurrentScanDataModel.ACTUATOR_DELAY, actuatorsDelay, false);

                // Zig zag.
                boolean zigzag = config.isZigzag();
                actionName = writeAttributeLog(CurrentScanDataModel.ZIGZAG, String.valueOf(zigzag));
                setAttribute(CurrentScanDataModel.ZIGZAG, zigzag, false);

                // Enable actuator speed.
                boolean enableScanSpeed = config.isEnableScanSpeed();
                actionName = writeAttributeLog(CurrentScanDataModel.ENABLESCANSPEED, String.valueOf(enableScanSpeed));
                setAttribute(CurrentScanDataModel.ENABLESCANSPEED, enableScanSpeed, false);

                // Post scan behaviour.
                IPostScanBehaviour postScanBehaviour = config.getScanAddOn().getPostScanBehaviour();
                Behaviour behaviour = postScanBehaviour.getBehaviour();
                if (behaviour == null) {
                    behaviour = Behaviour.NOOP;
                }
                int behaviourType = behaviour.getType();
                actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_TYPE, String.valueOf(behaviourType));
                setAttribute(CurrentScanDataModel.AFTER_ACTION_TYPE, behaviourType, false);

                if (behaviour.getArgumentCount() >= 1) {
                    int behaviourSensorIndex = postScanBehaviour.getSensor();
                    actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_SENSOR,
                            String.valueOf(behaviourSensorIndex));
                    setAttribute(CurrentScanDataModel.AFTER_ACTION_SENSOR, behaviourSensorIndex, false);
                } else if (behaviour.getArgumentCount() >= 2) {
                    int behaviourActuatorIndex = postScanBehaviour.getActuator();
                    actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_ACTUATOR,
                            String.valueOf(behaviourActuatorIndex));
                    setAttribute(CurrentScanDataModel.AFTER_ACTION_ACTUATOR, behaviourActuatorIndex, false);
                }

                // 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.
                        String catAttribute = cat + "TimeOut";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyTimeOut));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyTimeOut));
                        // Retry count.
                        catAttribute = cat + "RetryCount";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryCount));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryCount));
                        // Retry time out.
                        catAttribute = cat + "RetryTimeOut";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryTimeOut));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryTimeOut));
                        // Error strategy.
                        catAttribute = cat + "ErrorStrategy";
                        actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyType));
                        scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyType));
                    }
                    // Context validation error strategy.
                    int erreurStrategyValue = errorStrat.getContextValidationStrategy().ordinal();
                    actionName = writeAttributeLog(CurrentScanDataModel.CONTEXT_VALIDATION_STRATEGY,
                            String.valueOf(erreurStrategyValue));
View Full Code Here

TOP

Related Classes of fr.esrf.TangoApi.DeviceProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.