Examples of DeviceProxy


Examples of fr.esrf.TangoApi.DeviceProxy

                    false);
        }
        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);
            String format = null;
            try {
                AttributeProxy attributeProxy = tangoAttribute.getAttributeProxy();
                if (attributeProxy != null) {
                    AttributeInfo attributeInfo = attributeProxy.get_info();
                    if (attributeInfo != null) {
                        format = attributeInfo.format;
                    }
                }
            }
            catch (Exception e) {
                // Ignore exception: it is not a problem if format is not recovered
                format = null;
            }
            report.setFormat(format);

            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 " + name
                            + ".", 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 "
                            + name + ".", e);
            throw salsaDeviceException;
        }
        report.setQuality(quality);

        String state;
        try {
            state = StateUtilities.getNameForState(proxy.state());
        }
        catch (DevFailed e) {
            SalsaDeviceException salsaDeviceException = new SalsaDeviceException(
                    "Error while trying to read the state of the TangORB attribute value for the device "
                            + name + ".", e);
View Full Code Here

Examples of fr.esrf.TangoApi.DeviceProxy

        try {

            Vector<String> tmpAttributeList = new Vector<String>();
            String tmpAttributeName = null;

            DeviceProxy proxy = ProxyFactory.getInstance().createDeviceProxy(getDeviceName());
            String[] attList = proxy.get_attribute_list();

            for (int i = 0; i < attList.length; i++) {
                tmpAttributeName = getDeviceName() + "/" + attList[i];
                if (!isExcludedAttribute(attList[i])) {
                    tmpAttributeList.add(tmpAttributeName);
View Full Code Here

Examples of fr.esrf.TangoApi.DeviceProxy

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

            ScanStatusImpl result = new ScanStatusImpl();
            DeviceProxy scanServerProxy = ScanServerManager.getScanServerProxy(scanServerName);
            // System.out.println("scanServerProxy=" + scanServerProxy);
            if (scanServerProxy == null) {
                // scanServerManager.invalidateScanServerProxy(scanServerName);
                /*Exception e = new Exception("Error : cannot read scan status informations on "
                        + scanServerName);
View Full Code Here

Examples of fr.esrf.TangoApi.DeviceProxy

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

Examples of fr.esrf.TangoApi.DeviceProxy

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

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

Examples of fr.esrf.TangoApi.DeviceProxy

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

Examples of fr.esrf.TangoApi.DeviceProxy

     * @param scanServerName
     * @throws SalsaDeviceException
     */
    public void clearHistoric(String scanServerName) throws SalsaDeviceException {
        try {
            DeviceProxy scanServerProxy = ScanServerManager.getScanServerProxy(scanServerName);
            scanServerProxy.command_inout("ClearHistoric");
        }
        catch (DevFailed e) {
            scanServerManager.invalidateScanServerProxy(scanServerName);
            e.printStackTrace();
            throw new SalsaDeviceException("Error : cannot read the historic : " + e.getMessage(),
View Full Code Here

Examples of fr.esrf.TangoApi.DeviceProxy

     * @throws SalsaDeviceException
     */
    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 + ".");
                    }
                }
            }

            scanServerProxy.command_inout("ExecuteAction");

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

Examples of fr.esrf.TangoApi.DeviceProxy

     * @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

Examples of fr.esrf.TangoApi.DeviceProxy

     * @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
TOP
Copyright © 2018 www.massapi.com. 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.