How to read attributes:
// Read "Current" attribute
DeviceAttribute deviceAttribute = deviceProxy.read_attribute("Current");
if (deviceAttribute.hasFailed()) {
Except.print_exception(deviceAttribute.getErrStack());
else {
int type = attribute.getType();
if (type==TangoConst.Tango_DEV_DOUBLE) {
// If attribute read is double
double current = deviceAttribute.extractDouble();
System.out.println("Current : " + current);
}
else if (type==TangoConst.Tango_DEV_ENUM) {
// If attribute read is an enum
AttributeInfoEx info = deviceProxy.get_attribute_info_ex(attributeName);
short index = deviceAttribute.extractShort();
System.out.println(info.getEnumLabel(index));
}
}
How to write attributes:
// To write an enum value, use a short value
short index = 2;
deviceAttribute = new DeviceAttribute("EnumAttr");
deviceAttribute.insert(index);
deviceProxy.write_attribute(deviceAttribute);
// Or declare an enum like:
enum Numbers { ZERO(0), ONE(1), TWO(2), THREE(3);
public short value;
private Numbers(int value) {
this.value = (short)value;
}
}
- - - - -
// And insert enum value
deviceAttribute.insert(Numbers.TWO.value);