Using the JTango 9 (Java) API on a customer site, I get scalar attribute values embedded in an array.
Typically, I get Boolean or String scalar values in an array[1].
(I have double-checked with AtkPanel that the attribute type is really a scalar type).
Using the same JTango API (with the same java code), I don’t see this issue on my TangoBox.
Any explanation about this behavior? Is install/config issues could explain this?
Some more questions:
What is the code that returns this array?
Is the source device/attribute is the same in your customer configuration and your tango box?
In TANGO all attribute values are transferred in an array.
Scalar:
READ_ONLY array[1]
READ_WRITE array[2]
Spectum n values:
READ_ONLY array[n]
READ_WRITE array[2*n]
…
@Pascal,
ok, but since I’m using the JTango extractXXX calls, I should’nt get an array for scalar values.
Typically, for boolean values, the code is as follows:
Object value;
AttrDataFormat dataFormat = deviceAttribute.getDataFormat();
if (dataFormat == AttrDataFormat.SCALAR) {
value = deviceAttribute.extractBoolean();
} else {
value = deviceAttribute.extractBooleanArray();
}
@Gwenaëlle,
No, the device/attribute is not the same in the customer configuration.
But I’ve checker (from AtkPanel) the attribute is really a scalar one.
Seems there is a mismatch in DataFormat between Scalar an Array.
Is this could be caused by an issue in Tango configuration/install?
Or by the device server implementation?
We are using the same JTango library on the client side: JTango-9.1.2
On the server side, it may vary, depending on the device server we are connected to.
Is there any restriction about compatibility between JTango versions ?
DeviceAttribute has DataFormat == UNKNOWN by default, so in your case it might be the reason: you fall through if to else, hence Array. Debug would say exactly.
Why do not you use one of the high level APIs? There is JTangoClientLang (or so) embedded into JTango and ezTangORB: link source, link maven.
With this you can just do:
Object value = proxy.readAttribute("my-boolean-attribute")
or to be more specific:
boolean value = proxy.readAttribute("my-boolean-attribute")
Obviously that would not fix you problem, but at least less typing.
Finally as I can see you store value in Object, so I think it is even better to have arrays everywhere - the rest of the code becomes much more cleaner, this is how it is done in TINE BTW
About ezTangORB, I’d like to stick to Tango official repositories (Tango Controls Core Projects · GitHub).
About JTango Client Lang, I didn’t know there is a high level API, if it can simplify my code it would be nice!
If you could give me a small usage example it would be great.
import fr.soleil.tango.clientapi.TangoAttribute;
...
TangoAttribute ta = new TangoAttribute("my/device/test/scalarAttributeName");
// return the read value with the type of the attribute
Object value = ta.read();
// in case of a READ/WRITE attribute, get write part
if(ta.isWritable){
Object writeValue = ta.readWritten();
}
// read value and try to convert the attribute value to adouble
double doubleValue = ta.read(double.class);
// read value and try to convert the attribute value to a String
String stringValue = ta.read(String.class);
// convert value to the attribute type and write it
ta.write("50");
TangoAttribute taSpectrum = new TangoAttribute("my/device/test/spectrumAttributeName");
// return the value with the type of the attribute
Object value = taSpectrum.read();
// read value and try to convert the attribute value to adouble
double doubleValue = taSpectrum.read(double[].class);
// read value and try to convert the attribute value to a String
String stringValue = taSpectrum.read(String.class);
// convert value to the attribute type and write it
ta.write(new double[] { 1, 0, 1, 0, 1, 0 });
Thank you very much for the code example.
I’ll use it in my code, it will significantly simplify my code I guess!
About IDL version, yes we are using IDL5.
I attached what I got from Astor > Help > JTango version.
(We got the same versions for both our TangoBox VM and on our customer site)