Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceProxy


     */
    public void pauseScan(IContext context) throws SalsaDeviceException {
        String scanServerName = context.getScanServerName();
        if (TangoDeviceHelper.isDeviceRunning(scanServerName)) {
            try {
                DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
                if (scanServerProxy != null) {
                    scanServerProxy.command_inout("Pause");
                    // System.out.println(scanServerName + "Pause");
                }
            } catch (DevFailed e) {
                throw new SalsaDeviceException("Error : cannot pause the scan : " + DevFailedUtils.toString(e), e);
            }
View Full Code Here


     */
    public void resumeScan(IContext context) throws SalsaDeviceException {
        String scanServerName = context.getScanServerName();
        if (TangoDeviceHelper.isDeviceRunning(scanServerName)) {
            try {
                DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
                if (scanServerProxy != null) {
                    scanServerProxy.command_inout("Resume");
                }
            } catch (DevFailed e) {
                throw new SalsaDeviceException("Error : cannot resume the scan : " + DevFailedUtils.toString(e), e);
            }
        } else {
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public ScanState getScanState(String scanServerName) throws SalsaDeviceException {
        ScanState state = null;
        DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
        if (scanServerProxy != null) {
            try {
                // Time out
                scanServerProxy.set_timeout_millis(10000);
                DevState devState = scanServerProxy.state();
                if (devState != null) {
                    int stateInt = devState.value();
                    switch (stateInt) {
                        case DevState._ON:
                            state = ScanState.STOPPED;
View Full Code Here

     * @throws SalsaDeviceException
     */
    public void clearHistoric(String scanServerName) throws SalsaDeviceException {
        if (TangoDeviceHelper.isDeviceRunning(scanServerName)) {
            try {
                DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
                scanServerProxy.command_inout("ClearHistoric");
            } catch (DevFailed e) {
                throw new SalsaDeviceException("Cannot clear historic : " + DevFailedUtils.toString(e), e);
            }
        } else {
            throw new SalsaDeviceException("Cannot ClearHistoric because " + scanServerName + " device is down");
View Full Code Here

     */
    public void doScanFunction(String scanServerName, Behaviour behaviour, ISensor sensor, IActuator actuator)
    throws SalsaDeviceException {
        if (TangoDeviceHelper.isDeviceRunning(scanServerName)) {
            try {
                DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);

                TangoAttribute afterRunActionType = new TangoAttribute(scanServerName + "/afterRunActionType");
                afterRunActionType.write(behaviour.getType());
                // System.out.println("behaviour.getType()=" +
                // behaviour.getType());

                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) {
                            TangoAttribute afterRunActionSensor = new TangoAttribute(scanServerName
                                    + "/afterRunActionSensor");
                            afterRunActionSensor.write(sensorPosition);
                        } 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) {
                            TangoAttribute afterRunActionActuator = new TangoAttribute(scanServerName
                                    + "/afterRunActionActuator");
                            afterRunActionActuator.write(actuatorPosition);
                        } else {
                            throw new SalsaDeviceException("Error : actuator " + actuator.getName()
                                    + " is unknow on the scan server " + scanServerName + ".");
                        }
                    }
                }

                // TODO remove syso
                // System.out.println("ExecuteAction()=" + behaviour.getType());
                scanServerProxy.command_inout("ExecuteAction");

            } catch (DevFailed e) {
                e.printStackTrace();
                throw new SalsaDeviceException("Error : cannot perform scan function : " + DevFailedUtils.toString(e),
                        e);
View Full Code Here

        if (scanServerName == null) {
            throw new SalsaDeviceException("Cannot connect to the scan server : name is null.");
        }

        scanServerName = scanServerName.toLowerCase();
        DeviceProxy proxy = DeviceConnectionManager.getDevice(scanServerName);
        if (proxy == null) {
            DeviceConnectionManager.connect(scanServerName);
        }
        else {
            DeviceConnectionManager.addDevice(scanServerName);
View Full Code Here

                        logScanId = Integer.toString(config.getId());
                    }
                    String logScan = null;
                    String scanserver = context.getScanServerName();
                    if ((config == null) && TangoDeviceHelper.isDeviceRunning(scanserver)) {
                        DeviceProxy deviceProxy = TangoDeviceHelper.getDeviceProxy(scanserver);
                        if (deviceProxy != null) {
                            try {
                                DeviceAttribute attribute = deviceProxy
                                .read_attribute(CurrentScanDataModel.RUN_NAME);
                                logScan = attribute.extractString();
                            }
                            catch (DevFailed e) {
                            }
                        }
                    }
                    else if (config != null) {
                        logScan = config.getName();
                    }

                    // Get the real start date if it is a start action
                    if ((action != null) && action.equalsIgnoreCase(ILogService.START_ACTION)
                            && TangoDeviceHelper.isDeviceRunning(scanserver)) {

                        // For the moment runStartDate format = yyyy-MMM-dd HH:mm:ss
                        DeviceProxy deviceProxy = TangoDeviceHelper.getDeviceProxy(scanserver);
                        if (deviceProxy != null) {
                            try {
                                DeviceAttribute attribute = deviceProxy
                                .read_attribute(CurrentScanDataModel.RUN_START_DATE);
                                String runStartDate = attribute.extractString();
                                // System.out.println("runStartDate=" + runStartDate);
                                if ((runStartDate != null) && !runStartDate.isEmpty()) {
                                    int index = runStartDate.indexOf(" ");
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

        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());
                for (IActuator actuator : actuatorsList) {
                    if (actuator.isEnabled()) {
                        actuatorsNamesList.add(actuator.getName());
                    }
                }
                actuatorsNamesArray = actuatorsNamesList.toArray(new String[actuatorsNamesList.size()]);

                String actuatorName = "actuators" + indexStr;
                actionName = "write_attribute(\"" + 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);
                    // System.out.println("K Trajectory="
                    // + Arrays.toString(trajectoriesPositionsArray));
                    // System.out.println("K Trajectory size=" +
                    // trajectoriesPositionsArray.length);
                    integrationsTimesArray = TrajectoryCalculator.calculateIntegrationTimesK(trajectoryK);
                    // System.out.println("K integration size=" +
                    // integrationsTimesArray.length);
                    // System.out.println("K integration=" +
                    // Arrays.toString(integrationsTimesArray));
                    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);
                        if (actuator.isEnabled()) {
                            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());
                                // speedList.addAll(TrajectoryCalculator
                                // .calculateScanSpeedList(trajectory));
                            }
                            // System.out.println(actuator.getName() + "="
                            // +
                            // Arrays.toString(actuatorPositionsList.toArray()));
                            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) {
                        // System.out.println("onTheFly = " + onTheFly);
                        if ((range instanceof IRangeHCS) || onTheFly) {
                            stepsNumber = 1;
                        } else {
                            stepsNumber = range.getStepsNumber();
                        }

                        // System.out.println("stepsNumber = " + stepsNumber);
                        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 = "write_attribute(\"" + pointNumberName + "\"," + totalStepsNumber + ")";
                setAttribute(pointNumberName, totalStepsNumber, false);
                // System.out.println("pointNumber=" + totalStepsNumber);

                // 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 = "write_attribute(\"integrationTimes\"," + Arrays.toString(integrationsTimesArray)
                    + ")";
                    setAttribute("integrationTimes", integrationsTimesArray, false);

                    // Speed.
                    double[] speedArray = toDoubleArray(speedList);
                    // System.out.println("speedArray= " +
                    // Arrays.toString(speedArray));
                    actionName = "write_attribute(\"scanSpeed\"," + Arrays.toString(speedArray) + ")";
                    setAttribute("scanSpeed", speedArray, false);
                }

                actionName = "write_attribute(\"" + trajectoriesName + "\","
                + Arrays.toString(allActuatorsPositionsArray) + ")";
                scanServerProxy.write_attribute(trajectoriesAttribute);

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

    public IScanResult retrieveCommonScanResult(boolean withTrajectories) throws SalsaDeviceException {
        // System.out.println(this.getClass().getName() +
        // ".retrieveCommonScanResult");
        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();
                    // 0 -> time scan
                    // 1 -> scan 1d
                    // 2 -> scan 2d
                    switch (scanType) {
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.