Scalar attribute values in Array[1] using JTango

Hello,

Here is an example code for jtangoclient:

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

Hope this help,

Gwenaëlle.
Another hint,

What the IDL version of your server?

I think that

DeviceAttribute#getDataFormat();
is only working from IDL5 servers.
For older versions of servers, you have to do a separate request to the device to get the attribute format:

fr.esrf.TangoApi.AttributeProxy#get_info().data_format
Hi Gwenaelle,

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)

Thanks,
Jerome
 
Register or login to create to post a reply.