Device with 'externally' updated attributes
|
|
---|---|
Hi, Let's say you have a hardware device that sends you updates at more or less random intervals and that a client wants to receive events every time this happens. I tried to write a PyTango Device that simulates this using a thread that pushes new attribute values. Actually, I also want to have a simulator, so having the simulator work is useful too :) I'm completely new to Tango, so I'm not sure what is the right way to go about it. Some questions: 1) What Device() methods are thread safe? I'm pretty sure I'm doing something wrong since if I uncomment the time.sleep() between set_value() and fire_change_event() I get segfaults. What is the correct way to do this? Is there a lock somewhere I must grab, or is there some thread-safe way to push the attribute value? 2) It seems set_value() stores the new value somewhere in the Attribute instance, but how to get hold of it? I would like the attribute read function to return that same value rather than having to cache it in a private variable. 3) Is it possible to control the attribute date when using the attribute read method? If a client does reading = dev.read_attribute('randomnumber') (where dev is a DeviceProxy) I would like reading.time to refer to the time when the value was received from the device (i.e. the same time as used for self.randomnumber.set_date()), not the time that the attribute read method was called. Below is my device server Thanks Neilen
|
|
|
---|---|
Hi Neilen, I experienced segfaults in PyTango when the threads are too intensive, started before init_device() or are not properly joined at exit. You may try to use a threading.Event with a short wait to control it:
Regarding your question about read_attribute(): may be the new API works different that the old one, but in the classical PyTango API (using a read_AttrName(self,attr) method) you just pass the date to the client using the attr.set_value_date_quality(…) method. Sergi |
|
|
---|---|
It turns out the threading stuff works OK if you use the device's push_change_event(). Regarding the attribute timestamps, it seems the "new python" way to return a tuple of (new_value, timestamp, AttrQuality.ATTR…) in the read method, nicely described here: http://www.esrf.eu/computing/cs/tango/tango_doc/kernel_doc/pytango/latest/tep/tep-0001.html I personally find stackoverflow a great forum for answers to specific questions, so I asked and answered my own question with an example here: http://stackoverflow.com/questions/35460896/pytango-device-with-externally-updated-attributes/ I tried to add a 'tango-controls' tag (there is already a "tango" tag referring to another project), but I don't have enough reputations on SO. If anyone has > 1500 reputation please make a tango-controls tag and add it to my question :) Thanks Neilen |