PyTango dynamic attributes
|
|
---|---|
Hi, I am trying to create a device server that can create new attributes during run-time. I am following the guide which gives the following example:
Since I am not using the high-level Python API, I have created a command via POGO that creates a scalar attribute like so:
Following this, I need to create new methods that are used for reading and writing this attribute. I can create these new methods in my python code, but since they are not in a protected region, every time I re-run POGO to add some other commands etc. these read/write methods are removed. Where would be the best place to put my methods? Thanks.
Dr Andrea DeMarco, BSc (Hons) (Melita), MSc (Melita), DPhil (UEA)
Lecturer | Researcher Department of Physics Institute of Space Sciences and Astronomy Room 220, Maths and Physics Building University of Malta, Msida MSD2080, MALTA |
|
|
---|---|
Some additional information: Given a method like the following, which creates a scalar attribute for a particular name, I require two methods for reading and writing this attribute. The method pointers are self.read_GeneralScalar (reading) and self.write_GeneralScalar.
My problem is how to write those methods. In my scenario, when reading, I require the code to access an external API (which accesses the board given some parameters, and reads off a register value. So in my case I have written something like:
Am I right in assuming this function has to return the value? I ask because in this tutorial, there seems to be a "set_value" method for Attr, which is not in the PyTango API (v.8.1.1)
Furthermore, when writing values to the attribute, I need to pass some actual data to the write function. So I would like to have this kind of function, where I am calling another method "writeRegister" with particular arguments as a string.
But I'm not sure how the Tango device server would be able to pass the "data" argument. The tutorial mentioned above gives this example:
But I can't get how this writes to the attribute. Past API's seem to have had a set_value method, but this is not available anymore. Any help/suggestions are much appreciated.
Dr Andrea DeMarco, BSc (Hons) (Melita), MSc (Melita), DPhil (UEA)
Lecturer | Researcher Department of Physics Institute of Space Sciences and Astronomy Room 220, Maths and Physics Building University of Malta, Msida MSD2080, MALTA |
|
|
---|---|
|
Hi drea,drea I don't use pogo generator very often but unless I am mistaken, in the beginning of the device declaration there is an empty protected region (defined as global variables) you can use for that. Something like:
drea When you declare a new attribute you do it with object Attr. When read_[…](self, attr) or write_(self, attr) is called, attr is an instance of Attribute (not Attr). You can find the documentation here dreaI am not sure I understand what you mean. I will assume that data is actually the value the client is trying to write into a certain attribute. If that is the case, then you should do:
Hope it helps |
|
|
---|---|
Thanks a lot, that explains it perfectly! :)
Dr Andrea DeMarco, BSc (Hons) (Melita), MSc (Melita), DPhil (UEA)
Lecturer | Researcher Department of Physics Institute of Space Sciences and Astronomy Room 220, Maths and Physics Building University of Malta, Msida MSD2080, MALTA |
|
|
---|---|
Hi all, I have another question related to creation of dynamic attributes. For the dynamic attributes created with the add_attribute() API call, I would also like to add optional parameters, such as MIN/MAX alarm values. The attr_list dictionary does not appear to be modifiable in PyTango as far as I can tell. On the other hand, using the Jive tool, I can set these values dynamically. So assuming I have created an attribute in one of my commands with this code:
How can I also add min/max alarm values (or any other optional parameters) to the attribute (perhaps even update old values)? Thanks!
Dr Andrea DeMarco, BSc (Hons) (Melita), MSc (Melita), DPhil (UEA)
Lecturer | Researcher Department of Physics Institute of Space Sciences and Astronomy Room 220, Maths and Physics Building University of Malta, Msida MSD2080, MALTA |
|
|
---|---|
|
Hi, To setup attribute properties at attribute creation time do:
In the server, to update properties of an existing attribute do:
Hope it helps |
|
|
---|---|
That works wonderfully, thanks. I am still getting used to the API - I didn't know about MultiAttrProp() - problem solved now!
Dr Andrea DeMarco, BSc (Hons) (Melita), MSc (Melita), DPhil (UEA)
Lecturer | Researcher Department of Physics Institute of Space Sciences and Astronomy Room 220, Maths and Physics Building University of Malta, Msida MSD2080, MALTA |