Dynamic Attribute of type Enum

Hi,

I'm exploring the concept of Dynamic Attribute. I'm able to successfully create and use attributes dynamically of type Double, Float, String, etc. But if I try to dynamically create an attribute of type "DevEnum" I get following error:

ERROR 2015-09-09 20:10:27,699 [RequestProcessor-5 - td/1/1] org.tango.utils.DevFailedUtils.throwDevFailed:37 - org.tango.testdynamic.DynamicEnumAttrEnum cannot be an attribute
ERROR 2015-09-09 20:10:27,706 [RequestProcessor-5 - td/1/1] org.tango.utils.DevFailedUtils.throwDevFailed:38 - 
fr.esrf.Tango.DevFailed: IDL:Tango/DevFailed:1.0
	at org.tango.utils.DevFailedUtils.throwDevFailed(DevFailedUtils.java:36) ~[JTango-9.0.3.jar:na]
	at org.tango.server.attribute.AttributeValue.setValue(AttributeValue.java:118) [JTango-9.0.3.jar:na]
	at org.tango.server.attribute.AttributeValue.<init>(AttributeValue.java:61) [JTango-9.0.3.jar:na]
	at org.tango.testdynamic.DynamicEnumAttr.getValue(DynamicEnumAttr.java:128) [TestDynamic/:na]
	at org.tango.server.attribute.AttributeImpl.updateValue(AttributeImpl.java:187) [JTango-9.0.3.jar:na]
	at org.tango.server.servant.DeviceImpl.checkAlarms(DeviceImpl.java:2350) [JTango-9.0.3.jar:na]
	at org.tango.server.servant.DeviceImpl.getState(DeviceImpl.java:2332) [JTango-9.0.3.jar:na]
	at org.tango.server.servant.DeviceImpl.executeStateCmd(DeviceImpl.java:423) [JTango-9.0.3.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31]
	at org.tango.server.command.ReflectCommandBehavior.execute(ReflectCommandBehavior.java:66) [JTango-9.0.3.jar:na]
	at org.tango.server.command.CommandImpl.execute(CommandImpl.java:90) [JTango-9.0.3.jar:na]
	at org.tango.server.servant.DeviceImpl.commandHandler(DeviceImpl.java:1730) [JTango-9.0.3.jar:na]
	at org.tango.server.servant.DeviceImpl.command_inout_4(DeviceImpl.java:1609) [JTango-9.0.3.jar:na]
	at fr.esrf.Tango.Device_5POA._invoke(Device_5POA.java:229) [JTango-9.0.3.jar:na]
	at org.jacorb.poa.RequestProcessor.invokeOperation(RequestProcessor.java:350) [JTango-9.0.3.jar:na]
	at org.jacorb.poa.RequestProcessor.process(RequestProcessor.java:672) [JTango-9.0.3.jar:na]
	at org.jacorb.poa.RequestProcessor.run(RequestProcessor.java:830) [JTango-9.0.3.jar:na]

I know that the TANGO 9 is not yet officially released and the Enum datatype is a feature of TANGO 9. I just want to know if the error is because of the incorrect code or the feature of Dynamic Attribute with Enum Datatype is not yet implemented.

I have attached the device server code.

I'm using the JTango-9.0.3 jar file. I generate the code using the Pogo-9.1.2a which has the feature of using Enumeration as TANGO Deta types.
Hello,

The enum attribute is implemented in Java. You can either use it with:
- a Java enum. Example:


    public enum TestType {
        VALUE1, VALUE2
    }

    @Attribute
    private TestType enumAttribute = TestType.VALUE1;

    public TestType getEnumAttribute() {
        return enumAttribute;
    }

    public void setEnumAttribute(final TestType enumAttribute) {
        this.enumAttribute = enumAttribute;
    }

- or with a dynamic attribute. In this case, the value returned in getValue must be a short (and not an enum as in your code). It allows to have a configurable list of enum values with the attribute property "enum_labels". Example:


package org.tango.server.testserver;

import org.tango.server.StateMachineBehavior;
import org.tango.server.attribute.AttributeConfiguration;
import org.tango.server.attribute.AttributePropertiesImpl;
import org.tango.server.attribute.AttributeValue;
import org.tango.server.attribute.IAttributeBehavior;

import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevFailed;
import fr.esrf.TangoDs.TangoConst;

public class DynamicEnumAttribute implements IAttributeBehavior {

    private final AttributeConfiguration configAttr = new AttributeConfiguration();
    private short value = 0;

    public DynamicEnumAttribute() throws DevFailed {
        final AttributePropertiesImpl props = new AttributePropertiesImpl();
        props.setLabel("DevEnumDynamic");
        props.setEnumLabels(new String[] { "label1", "label2" });
        configAttr.setTangoType(TangoConst.Tango_DEV_ENUM, AttrDataFormat.SCALAR);
        configAttr.setName("DevEnumDynamic");
        configAttr.setWritable(AttrWriteType.READ_WRITE);
        configAttr.setAttributeProperties(props);
    }

    @Override
    public AttributeConfiguration getConfiguration() throws DevFailed {
        return configAttr;
    }

    @Override
    public AttributeValue getValue() throws DevFailed {
        return new AttributeValue(value);
    }

    @Override
    public void setValue(final AttributeValue value) throws DevFailed {
        this.value = (Short) value.getValue();
    }

    @Override
    public StateMachineBehavior getStateMachine() throws DevFailed {
        return null;
    }

}

Best Regards,

Gwenaëlle.
 
Register or login to create to post a reply.