Package fr.esrf.TangoApi

Examples of fr.esrf.TangoApi.DeviceAttribute


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


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

    public void doScanFunction(String scanServerName, Behaviour behaviour, ISensor sensor,
            IActuator actuator) throws SalsaDeviceException {
        try {
            DeviceProxy scanServerProxy = ScanServerManager.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

     * @throws SalsaDeviceException
     */
    public static Double getData(IDevice device) throws SalsaDeviceException {
        Double data;
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceAttribute attribute = getDeviceAttribute(device);
            if (attribute != null) {
                try {
                    data = AttributeHelper.extractToDouble(attribute);

                }
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public static void setData(IDevice device, Double data) throws SalsaDeviceException {
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceAttribute attribute = getDeviceAttribute(device);
            if (attribute != null) {
                try {
                    AttributeHelper.insertFromDouble(data, attribute);
                    writeAttribute(device, attribute);
                }
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public static void setData(IDevice device, Double[] dataArray) throws SalsaDeviceException {
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceAttribute attribute = getDeviceAttribute(device);
            if (attribute != null) {
                int length = dataArray.length;
                double[] doubleArray = new double[length];
                for (int index = 0; index < length; ++index) {
                    doubleArray[index] = dataArray[index].doubleValue();
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    public static void setData(IDevice device, Double[][] dataMatrix) throws SalsaDeviceException {
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceAttribute attribute = getDeviceAttribute(device);
            if (attribute != null) {
                int dimY = dataMatrix.length;
                if (dimY != 0) {
                    int dimX = dataMatrix[0].length;
                    int length = dimY * dimX;
 
View Full Code Here

     * @throws SalsaDeviceException
     */
    public static String getQuality(IDevice device) throws SalsaDeviceException {
        String quality;
        if (device != null && device.getName() != null && !"".equals(device.getName().trim())) {
            DeviceAttribute attribute = getDeviceAttribute(device);
            if (attribute != null) {
                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);
View Full Code Here

     * @return
     * @throws SalsaDeviceException
     */
    private static DeviceAttribute getDeviceAttribute(DeviceProxy proxy, String attributeName)
            throws SalsaDeviceException {
        DeviceAttribute attribute;
        try {
            attribute = proxy.read_attribute(attributeName);
        }
        catch (DevFailed e) {
            e.printStackTrace();
View Full Code Here

        }
        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);
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.