Accessing own DeviceProxy class

Dear all,
I'm writing some small general utilities for our device servers and I need to access in parametric way to the device structures. One easy way is to use a DeviceProxy class pointing to the current device.

There is a globally available pointer to the DeviceProxy of the current class? Or, as an alternative, there is a global variable/class holding the database device name?

Thank you for your answer
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Hi Carlo,

I am not sure to fully understand your question…
What do you mean with global variable/class holding the database device name?

Do you mean a variable containing the FQDN current device name (Fully Qualified Domain Name)? Like tango://myhost:10000/my/device/name ?

Kind regards,
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Dear Reynald

Yes I intended the FQDN. To have the current device name is equivalent to have the DeviceProxy pointer: it is just a function call.
Bye
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
From your device, you can get your device name from the device_name variable (which is already used in some DEBUG_STREAM messages generated by POGO).
Then if you create a device proxy using device_name as parameter, you will for sure get a device_proxy on your current device.
I don't know whether this would fit your needs because I think device_name does not contain the FQDN device name, you don't have the TANGO_HOST in device_name value.

It depends on what do you mean when you write you want to access to the device structures?
What do you mean with device structures? It is still not clear to me what you would like to access.

Kind regards
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Dear Reynald,

I have verified and on my device the contents of global device_name variable contains a string with /domain/family/member.
Even if this is not a FQDN, as you stated, I can access the local structures using a call to DeviceProxy, as the facility (or TangoDb) is the same for the caller and the target (as is obvious, the two are the same device!).

My aim is to write an initialization routine which will be called by few different device driver. So I need to access attributes (and attributes properties) in a 'parametric' way, and I think my shortest path is to access them by means of a DeviceProxy call.

Thank you for your answer
Bye
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Hi Carlo,

Emmanuel Taurel found the attached presentation with a slide about setting/getting attribute properties from a server.
Tomasz Rogucki and Emmanuel presented this during the 25th Tango collaboration meeting in 2012.
If you have a look at slide 9, you will see how you could access and modify the standard Tango attribute properties for your current device from a Tango server.
This works only for standard Tango attribute properties (described on slide 6). If you defined new custom attributes properties, you won't be able to get and set them using the code described there.
Please beware that if you use the DeviceProxy way, you won't be able to use it from your init_device() method because during the device server initialization, the device is not yet exported, so the DeviceProxy calls will fail.

Hoping this helps

Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Dear Reynald

I think your observation can be precious. I will test the presentation approach and I will give some feedback.
Thank you again
Bye
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Dear Reynald (and Emmanuel)

Thank you again for your suggestion. I tested it and, while I was able to change the attribute properties (as in the example), I did not succeeded in setting correctly the attributes values. My code fragments are as follow:
  // we iterate on local writable attributes 
  Tango::MultiAttribute *attributes = this->get_device_attr();
  vector<Tango::Attribute *> w_attr_idx = attributes->get_attribute_list();
  vector<Tango::DevULong> v_ulo;
  for (int izz = 0 ; izz <  (int) w_attr_idx.size(); izz++) {
    Tango::Attribute *local_attr = w_attr_idx[izz];
    if (Tango::DEV_ULONG == local_attr->get_data_type()) {
      v_ulo.push_back((unsigned long) value);
      local_attr->set_value(&(v_ulo[0]),1,0,false);
    }
    …// all Tango data types
   }  

Examining the log output I see the problem could reside in the associate method write_VariableName not being called induring the local_attr->set_value() execution, but I can be wrong.
Thank you in advance for your comments.
Carlo

—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Hi Carlo,

Good to know you managed to solve the issue with the attribute properties.
About setting the attribute value, I think there is a misunderstanding here.
From your last message, it looks like what you would like to do is to write a tango RW attribute.
local_attr->set_value(&(v_ulo[0]),1,0,false);
will just update the read value of your attribute and will not execute the code from the write_variableName() method nor the one from read_variableName() method.

The right way to do it in this case is clearly to use a device proxy on yourself.
You could simulate what the Tango library is doing but this is not advised since you might miss something and if we add new features in the library in the future, you might miss them.

When you are using DeviceProxy on devices exported by your device server, the call will not go to the network and Tango will call the needed methods (is_variableName_allowed(), always_executed_hook(), write_variableName() and write_attr_hardware()) directly without going through the network.
Please be aware that the timeout feature from the DeviceProxy class when invoked on a device exported by your current device server (process) does not work in that case.

Hoping this helps,
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
 
Register or login to create to post a reply.