Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceProxy


        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

     */
    public IScanStatus getScanStatus(String scanServerName) throws SalsaDeviceException {
        try {

            ScanStatusImpl result = new ScanStatusImpl();
            DeviceProxy scanServerProxy = getScanServerProxy(scanServerName);
            DevState state = scanServerProxy.read_attribute("State").extractState();
            result.setState("" + state.value());

            result.setStatus(scanServerProxy.read_attribute("Status").extractString());
            result.setRunStartDate(scanServerProxy.read_attribute("runStartDate").extractString());
            result
                    .setScanStartDate(scanServerProxy.read_attribute("scanStartDate")
                            .extractString());
            result.setScanEndDate(scanServerProxy.read_attribute("scanEndDate").extractString());
            result.setRunEndDate(scanServerProxy.read_attribute("runEndDate").extractString());
            result.setScanDuration(scanServerProxy.read_attribute("scanDuration").extractString());
            result.setRunDuration(scanServerProxy.read_attribute("runDuration").extractString());
            result.setScanRemainingTime(scanServerProxy.read_attribute("scanRemainingTime")
                    .extractString());
            result.setRunRemainingTime(scanServerProxy.read_attribute("runRemainingTime")
                    .extractString());
            result.setScanElapsed(scanServerProxy.read_attribute("scanElapsed").extractString());
            result.setRunElapsed(scanServerProxy.read_attribute("runElapsed").extractString());
            result
                    .setRunCompletion(scanServerProxy.read_attribute("runCompletion")
                            .extractDouble());
            result.setScanCompletion(scanServerProxy.read_attribute("scanCompletion")
                    .extractDouble());
            result.setDeadTime(scanServerProxy.read_attribute("deadTime").extractDouble());
            result.setDeadTimePercentage(scanServerProxy.read_attribute("deadTimePercent")
                    .extractDouble());
            result.setDeadTimePerPoint(scanServerProxy.read_attribute("deadTimePerPoint")
                    .extractDouble());
            return result;
        }
        catch (DevFailed e) {
            invalidateScanServerProxy(scanServerName);
View Full Code Here

                if (!newDeviceName.isEmpty()) {
                    String deviceName = newDeviceName.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 (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;
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public IConfig.ScanType getScanType(String scanServerName) throws SalsaDeviceException {
        try {
            DeviceProxy scanServerProxy = getScanServerProxy(scanServerName);
            short scanType = AttributeHelper.extractToShort(scanServerProxy
                    .read_attribute("scanType"));
            switch (scanType) {
                case 0:
                    return IConfig.ScanType.SCAN_1D;
                case 1:
View Full Code Here

     * @throws SalsaDeviceException
     */
    public IScanResult readScanResult(String scanServerName) throws SalsaDeviceException {
        IScanResult scanResult;
        if (isScanResultReady(scanServerName)) {
            DeviceProxy scanServerProxy = getScanServerProxy(scanServerName);
            // Type
            IConfig.ScanType scanType = getScanType(scanServerName);
            switch (scanType) {
                case SCAN_1D:
                    try {
View Full Code Here

     *
     * @param context context of the scan
     * @throws SalsaDeviceException
     */
    public void stopScan(IContext context) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        String scanServerName = context.getScanServerName();
        try {
            scanServerProxy = getScanServerProxy(scanServerName);
            scanServerProxy.command_inout("Abort");
        }
        catch (DevFailed e) {
            invalidateScanServerProxy(scanServerName);
            e.printStackTrace();
            throw new SalsaDeviceException("Error : cannot stop the scan : " + e.getMessage(), e);
View Full Code Here

     *
     * @param context context of the scan
     * @throws SalsaDeviceException
     */
    public void pauseScan(IContext context) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        String scanServerName = context.getScanServerName();

        try {
            scanServerProxy = getScanServerProxy(scanServerName);
            scanServerProxy.command_inout("Pause");
        }
        catch (DevFailed e) {
            invalidateScanServerProxy(scanServerName);
            e.printStackTrace();
            throw new SalsaDeviceException("Error : cannot pause the scan : " + e.getMessage(), e);
View Full Code Here

     *
     * @param context context of the scan
     * @throws SalsaDeviceException
     */
    public void resumeScan(IContext context) throws SalsaDeviceException {
        DeviceProxy scanServerProxy;
        String scanServerName = context.getScanServerName();
        try {
            scanServerProxy = getScanServerProxy(scanServerName);
            scanServerProxy.command_inout("Resume");
        }
        catch (DevFailed e) {
            invalidateScanServerProxy(scanServerName);
            e.printStackTrace();
            throw new SalsaDeviceException("Error : cannot resume the scan : " + e.getMessage(), e);
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public boolean isScanResultReady(String scanServerName) throws SalsaDeviceException {
        // 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

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.