Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceAttribute


    public ScanState getScanState(String scanServerName) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        ScanState state;
        scanServerProxy = getScanServerProxy(scanServerName);
        try {
            DeviceAttribute stateAttribute = scanServerProxy.read_attribute("State");
            String stateString = AttributeHelper.extractToString(stateAttribute);
            if ("ON".equals(stateString)) {
                state = ScanState.STOPPED;
            }
            else if ("MOVING".equals(stateString)) {
View Full Code Here


     * @param scanServerName
     * @return
     */
    public List<HistoricRecord> getHistoric(String scanServerName) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        DeviceAttribute historicAttribute;
        String historicStringArray[];
        try {
            scanServerProxy = getScanServerProxy(scanServerName);
            historicAttribute = scanServerProxy.read_attribute("historic");
            historicStringArray = AttributeHelper.extractToStringArray(historicAttribute);
View Full Code Here

    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 + ".");
View Full Code Here

                    // Add Actuator list
                    if (TangoAttributeHelper.isAttributeRunning(deviceName, ACTUATORS_ATTRIBUTE)) {
                        DeviceProxy proxy = TangoDeviceHelper.getDeviceProxy(deviceName);
                        try {
                            DeviceAttribute deviceAttribute = proxy.read_attribute(ACTUATORS_ATTRIBUTE);
                            String[] attributeList = deviceAttribute.extractStringArray();
                            IDimension dimension = config.getDimensionX();
                            if (dimension != null) {
                                List<IActuator> actuatorList = dimension.getActuatorsList();
                                // Check if the actuators are not already defined
                                // Then add
                                for (String actuatorName : attributeList) {
                                    if (config.getDevice(deviceName, actuatorList) == null) {
                                        config.addActuator(actuatorName, false);
                                    }
                                }
                            }
                        } catch (Exception e) {
                        }
                    }

                    // Add Sensor list
                    if (TangoAttributeHelper.isAttributeRunning(deviceName, SENSORS_ATTRIBUTE)) {
                        DeviceProxy proxy = TangoDeviceHelper.getDeviceProxy(deviceName);
                        try {
                            DeviceAttribute deviceAttribute = proxy.read_attribute(SENSORS_ATTRIBUTE);
                            String[] attributeList = deviceAttribute.extractStringArray();
                            List<ISensor> sensorList = config.getSensorsList();
                            String completeSensorName = null;
                            for (String sensorName : attributeList) {
                                completeSensorName = deviceName + "/" + sensorName;
                                if (config.getDevice(completeSensorName, sensorList) == null) {
View Full Code Here

        // If a scan result is ready, there is a data_01 attribute.
        DeviceProxy scanServerProxy;
        boolean ready;
        scanServerProxy = getScanServerProxy(scanServerName);
        try {
            DeviceAttribute data01Attribute = scanServerProxy.read_attribute("data_01");
            // If there is no data_01 attribute, the next line will throw a DevFailed exception.
            double[] data01Array = AttributeHelper.extractToDoubleArray(data01Attribute);
            ready = data01Array != null && data01Array.length != 0;
        }
        catch (DevFailed e) {
View Full Code Here

    public ScanState getScanState(String scanServerName) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        ScanState state;
        scanServerProxy = getScanServerProxy(scanServerName);
        try {
            DeviceAttribute stateAttribute = scanServerProxy.read_attribute("State");
            String stateString = AttributeHelper.extractToString(stateAttribute);
            if ("ON".equals(stateString)) {
                state = ScanState.STOPPED;
            }
            else if ("MOVING".equals(stateString)) {
View Full Code Here

     * @param scanServerName
     * @return
     */
    public List<HistoricRecord> getHistoric(String scanServerName) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        DeviceAttribute historicAttribute;
        String historicStringArray[];
        try {
            scanServerProxy = getScanServerProxy(scanServerName);
            historicAttribute = scanServerProxy.read_attribute("historic");
            historicStringArray = AttributeHelper.extractToStringArray(historicAttribute);
View Full Code Here

    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 + ".");
View Full Code Here

                // Trajectories
                // Builds the array from the list.
                allActuatorsPositionsXArray = toDoubleArray(allActuatorsPositionsXList);
                // Sends the array to Tango.
                DeviceAttribute trajectoriesXAttribute = new DeviceAttribute("trajectories");
                if (enabledActuatorsXNumber != 0) {
                    trajectoriesXAttribute.insert(allActuatorsPositionsXArray, totalStepsNumberX,
                            enabledActuatorsXNumber);
                }
                else {
                    trajectoriesXAttribute.insert(new double[] {}, 0, 1);
                }
                scanServerProxy.write_attribute(trajectoriesXAttribute);

                // Speed.
                speedXArray = toDoubleArray(speedXList);
                setAttribute("scanSpeed", speedXArray);

                // Dimensions Y
                // 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[] allActuatorsPositionsYArray;
                double initialValueY;

                // Contains the positions in order, range after range, of the trajectories of an
                // actuator.
                List<Double> actuatorPositionsYList;
                // Contains the positions in order, actuator after actuator, range after range, of
                // the trajectories of all the actuators.
                List<Double> allActuatorsPositionsYList;
                // The number of points, which is the total steps numbers + 1 per range.
                int totalStepsNumberY;
                // The actuators used for this dimension
                List<IActuator> dimensionActuatorsYList;
                // Dimension
                dimensionActuatorsYList = dimensionY.getActuatorsList();
                // The positions, sorted as Tango expect them.
                allActuatorsPositionsYList = new ArrayList<Double>();
                // The number of enabled actuators.
                int enabledActuatorsYNumber = 0;
                // The positions must be sorted by actuator, so we loop over the actuators.
                for (IActuator actuator : dimensionActuatorsYList) {
                    if (actuator.isEnabled()) {
                        initialValueY = ActuatorConnector.getData(actuator);
                        actuatorPositionsYList = new ArrayList<Double>();
                        // For each actuators, the positions must be sorted by range.
                        for (ITrajectory2DY trajectory : findActuatorTrajectories(dimensionY,
                                actuator)) {
                            actuatorPositionsYList
                                    .addAll(TrajectoryCalculator
                                            .calculateLinearTrajectoriesPosition(trajectory,
                                                    initialValueY));
                        }
                        allActuatorsPositionsYList.addAll(actuatorPositionsYList);
                        ++enabledActuatorsYNumber;
                    }
                }

                // The number of points
                totalStepsNumberY = 0;
                for (IRange2DY range : dimensionY.getRangesList()) {
                    totalStepsNumberY += range.getStepsNumber() + 1;
                }
                setAttribute("pointNumber2", totalStepsNumberY);

                // Builds the array from the list.
                allActuatorsPositionsYArray = toDoubleArray(allActuatorsPositionsYList);
                DeviceAttribute trajectoriesYAttribute = new DeviceAttribute("trajectories2");
                if (enabledActuatorsYNumber > 0) {
                    // Sends the array to Tango.
                    trajectoriesYAttribute.insert(allActuatorsPositionsYArray, totalStepsNumberY,
                            enabledActuatorsYNumber);
                }
                else {
                    trajectoriesYAttribute.insert(new double[] {}, 0, 1);
                }
                scanServerProxy.write_attribute(trajectoriesYAttribute);

                // 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);
View Full Code Here

                    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(" ");
                                    if (index > -1) {
                                        logHour = runStartDate.substring(index + 1);
View Full Code Here

TOP

Related Classes of fr.esrf.TangoApi.DeviceAttribute

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.