Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceProxy


            return;
        }

        // Device Proxy creation
        try {
            m_deviceProxy = new DeviceProxy(m_deviceName);
            m_deviceProxy2 = new DeviceProxy(m_deviceName2);
        }
        catch (final DevFailed e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Assert.assertTrue(false);
View Full Code Here


      return;
    }

    // Device Proxy creation
    try {
      this.m_deviceProxy = new DeviceProxy(m_deviceName);
      this.m_deviceProxy2 = new DeviceProxy(m_deviceName2);
    } catch (final DevFailed e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

        writeData();
        return result;
    }

    private void writeData() {
        DeviceProxy proxy = TangoDeviceHelper.getDeviceProxy(DEVICE);

        if (proxy != null) {
            try {
                DeviceAttribute deviceAttribute = proxy.read_attribute("double_spectrum");
                double[] value1 = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                deviceAttribute.insert(value1);
                proxy.write_attribute(deviceAttribute);

                deviceAttribute = proxy.read_attribute("float_spectrum");
                float[] value2 = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                deviceAttribute.insert(value2);
                proxy.write_attribute(deviceAttribute);

                deviceAttribute = proxy.read_attribute("long_spectrum");
                int[] value3 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                deviceAttribute.insert(value3);
                proxy.write_attribute(deviceAttribute);

                deviceAttribute = proxy.read_attribute("double_image");
                double[] value4 = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
                deviceAttribute.insert(value4, 10, 2);
                proxy.write_attribute(deviceAttribute);

            } catch (DevFailed e) {
                e.printStackTrace();
            }
        }
View Full Code Here

     * @param scanServerName the name of the scan server to use.
     * @throws SalsaDeviceException
     */
    public void startScan(IConfig1D config, String scanServerName) throws SalsaDeviceException {
        int timeOut;
        DeviceProxy scanServerProxy = ScanServerManager.getScanServerProxy(scanServerName);
        if (scanServerProxy != null) {
            try {
                // Reads the initial value of the time out.
                timeOut = scanServerProxy.get_timeout_millis();
                try {
                    // Time out
                    scanServerProxy.set_timeout_millis(5000);

                    // Clean
                    command("Clean");

                    // ? Scan sequencing.
                    // scanServerProxy.write_attribute(new DeviceAttribute("scanSequencing", (short)
                    // 1));

                    // Partial mode for recording.
                    setAttribute("dataRecorderPartialMode", false);

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

                    // Scan number.
                    setAttribute("scanNumber", config.getScanNumber());

                    // 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()]);
                    setAttribute("timebases", timebasesNameArray);

                    // 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()]);
                    setAttribute("sensors", sensorsNameArray);

                    // Actuators
                    List<IActuator> actuatorsList;
                    List<String> actuatorsNamesList;
                    String[] actuatorsNamesArray;
                    IDimension1D dimension = config.getDimensionX();
                    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()]);
                    setAttribute("actuators", actuatorsNamesArray);

                    // 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;
                    // 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;
                    double[] integrationsTimesArray;
                    int integrationTimeIndex;
                    // The list of speeds.
                    List<Double> speedList = new ArrayList<Double>();
                    double[] speedArray;
                    // The number of points, which is the total steps numbers + 1 per range.
                    int totalStepsNumber;
                    // The actuators used for this dimension
                    List<IActuator> dimensionActuatorsList;
                    // Dimension.
                    // Initial computations.
                    dimensionActuatorsList = dimension.getActuatorsList();
                    // The positions, sorted as Tango expect them.
                    allActuatorsPositionsList = new ArrayList<Double>();
                    // The number of enabled actuators.
                    int enabledActuatorsNumber = 0;
                    // The positions must be sorted by actuator, so we loop over the actuators.
                    for (IActuator actuator : dimensionActuatorsList) {
                        if (actuator.isEnabled()) {
                            initialValue = ActuatorConnector.getData(actuator);
                            actuatorPositionsList = new ArrayList<Double>();
                            // For each actuators, the positions must be sorted by range.
                            for (ITrajectory trajectory : findActuatorTrajectories(dimension,
                                    actuator)) {
                                actuatorPositionsList.addAll(TrajectoryCalculator
                                        .calculateLinearTrajectoriesPosition(
                                                (ITrajectory1D) trajectory, initialValue));
                                // 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.
                    integrationsTimesList = new ArrayList<Double>(dimension.getRangesXList().size());
                    int stepsNumber;
                    totalStepsNumber = 0;
                    for (IRange1D range : dimension.getRangesXList()) {
                        stepsNumber = range.getStepsNumber();
                        for (integrationTimeIndex = 0; integrationTimeIndex < stepsNumber + 1; ++integrationTimeIndex) {
                            integrationsTimesList.add(range.getIntegrationTime());
                        }
                        totalStepsNumber += stepsNumber + 1;
                    }
                    integrationsTimesArray = toDoubleArray(integrationsTimesList);
                    setAttribute("integrationTimes", integrationsTimesArray);
                    setAttribute("pointNumber", totalStepsNumber);

                    // Trajectories.
                    // Builds the array from the list.
                    allActuatorsPositionsArray = toDoubleArray(allActuatorsPositionsList);
                    // Sends the array to Tango.
                    DeviceAttribute trajectoriesAttribute = new DeviceAttribute("trajectories");
                    if (enabledActuatorsNumber != 0) {
                        trajectoriesAttribute.insert(allActuatorsPositionsArray, totalStepsNumber,
                                enabledActuatorsNumber);
                    }
                    else {
                        trajectoriesAttribute.insert(new double[] {}, 0, 1);
                    }
                    scanServerProxy.write_attribute(trajectoriesAttribute);

                    // Speed.
                    speedArray = toDoubleArray(speedList);
                    setAttribute("scanSpeed", speedArray);

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

                    // Hardware continuous scan : no.
                    setAttribute("hwContinuous", false);

                    // On the fly mode (software continuous mode).
                    boolean onTheFly = config.isOnTheFly();
                    setAttribute("onTheFly", onTheFly);

                    // Fin configuration du scan.

                    // D�marrage du scan.
                    command("Start");
                }
                finally {
                    // Sets the time out back to the initial value.
                    scanServerProxy.set_timeout_millis(timeOut);
                }
            }
            catch (DevFailed e) {
                e.printStackTrace();
                String message = e.getMessage();
View Full Code Here

        if (value != null && !value.isEmpty() && config != null && !(config instanceof IConfig2D)) {
            String deviceName = value.trim();

            // 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 (!isDeviceBelongToList(actuatorName, actuatorList)) {
                                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;
View Full Code Here

     * @throws SalsaDeviceException
     */
    public static String getState(IDevice device) throws SalsaDeviceException {
        String state;
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceProxy proxy = getDeviceProxy(device);
            if (proxy != null) {
                try {
                    state = StateUtilities.getNameForState(proxy.state());
                }
                catch (DevFailed e) {
                    SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                            "Error while trying to read the state of the device "
                                    + device.getName() + ".", e);
View Full Code Here

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

            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

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.