Objects in Tango servers

Dear all,

I have a technical question that I hope you can answer.

Let us assume I have a python class (e.g. DriverHelper) that is interfacing with a C++ library (a sort of device driver) that is interfacing directly with a hardware device.

The python class sort of hooks into the functionality of the device. I now want to create a python Tango device that wraps around some of the functionality of this python class, with Tango-specific attributes and commands etc.

Is it possible, inside my Tango device, to instantiate an object of the DriverHelper class and pass on attribute values/commands to it, whilst making sure that the state of the DriverHelper persists with the Tango device? It seems that on different Tango command calls, the state of the object DriverHelper is not being kept.

Is there any way around this?

Thanks & Regards smile

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,

Normally, there is no problem for what you want to do. In fact, I think it's good to separate Tango class and hardware access class.

I have done it several times without issues.

Maybe your problem is in your DriverHelper class or the way you are using it in the tango class.
Hi Sebastien,

Thanks. It may be my problem is implementation then. There's a lot of code so I'll try to put in salient parts.

In my Tango device server, when I start the device, I can run a command like:

def init_device(self):
        self.debug_stream("In init_device()")
        self.get_device_properties(self.get_device_class())
        #—– PROTECTED REGION ID(TPM_DS.init_device) ENABLED START —–#
        self.info_stream("Starting device initialization…")
        self.set_state(PyTango.DevState.INIT)
        self.tpm_instance = TPM(ip="127.0.0.1", port=10000)
        self.info_stream("Device has been initialized.")
        #—– PROTECTED REGION END —–#	//	TPM_DS.init_device

TPM is a python helper class (not a Tango device server). I can see the device server passes this command successfully and the communication (tpm_instance) is established.

Later on, a Tango client calls a command in my device e.g.

import PyTango

tpm_instance = PyTango.DeviceProxy("test/tpm_board/1")

arguments = {}
arguments['device'] = 1
arguments['path'] = '/home/andrea/Documents/AAVS/xml/map.xml'
args = str(arguments)

tpm_instance.command_inout("loadfirmwareblocking", args)

My device server contains this command:

    def loadfirmwareblocking(self, argin):
        """ Blocking call to load firmware.
        
        :param argin: File path.
        :type: PyTango.DevString
        :return: 
        :rtype: PyTango.DevVoid """
        self.debug_stream("In loadfirmwareblocking()")
        #—– PROTECTED REGION ID(TPM_DS.loadfirmwareblocking) ENABLED START —–#
        arguments = eval(argin)
        device = arguments['device']
        filepath = arguments['path']
        self.tpm_instance.loadFirmwareBlocking(Device(device), filepath)
        #—– PROTECTED REGION END —–#	//	TPM_DS.loadfirmwareblocking

"Device" is an enumerated type, and Filepath is an XML file the helper class requires. The helper class method tpm_instance.loadFirmwareBlocking() is indeed called. However the attributes of tpm_instance (set internally when previously starting up the object during INIT) seem to be of another instance of tpm_instance i.e. the original tpm_instance object seems to have not persisted.

I hope the explanation is clear smile

Thanks a lot!

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
Edited 9 years ago
Your code seems ok from my side.

Maybe tou will need to add some debug traces to ensure that the object is still the same or not.

You can also try to use singleton or module in python to ensure there is only one object created.
 
Register or login to create to post a reply.