Unable to load C++ Class with multiclass Python HL


The low-level API allows adding a C++ class via the add_class() method, and the high-level API requires using run() which does not support this feature.
Could you please confirm for me that it is indeed impossible to have a multi-class python server that loads both HL python class and C++ class (shared lib)?
And in case of impossibility, could you tell me if it is planned that this functionality be added?

Thanks for your help,
Hi Arnaud

I think it might be possible to mix C++ classes with high-level API devices. You will have to use the tango.Util class directly. This is a singleton, so if we use add_class before calling tango.server.run, then it should see all the classes. The tango.server.run function is adding the Python classes internally.

Based on the example here:

(note: the example above has a typo on line 5 - it should be "util =", not "py =".)

import sys

import tango
from tango.server import run

from IRMirror import IRMirror
from PLC import PLC
if __name__ == '__main__':
util = tango.Util(sys.argv)
util.add_class('SerialLine', 'SerialLine', language="c++")

# run device server with SerialLine, PLC and IRMirror:
run([PLC, IRMirror])

There is also a dict form that can be passed to run for more complicated settings, but this still doesn't allow a C++ class to be specified. It may be useful to extend the dict-form to suit your use case.

Please let me know if the suggested code works or fails.

Thank you very much Anton, it works fine with this syntax.
I did a basic test in a Conda environment with pytango 9.3.3.

import sys
import tango
from tango.server import run, Device

class MyPowerSupply(Device):

class OtherPowerSupply(Device):

class MyServer(tango.Device_4Impl):

class MyServerClass(tango.DeviceClass):

if __name__ == '__main__':
util = tango.Util(sys.argv)
util.add_class('Modbus', 'Modbus', language="c++")

run([MyPowerSupply, OtherPowerSupply, [MyServerClass, MyServer]])

except tango.DevFailed as e:
print('——-> Received a DevFailed exception: {}'.format(e))

except Exception as e:
print('——-> An unforeseen exception occured…. {}'.format(e))

This allows great flexibility in the use of Python multiclasses smile

Thanks, Arnaud. That's good news.

It would be great if you could propose a documentation update for PyTango, so others can find this in future.
Fixing, and extending this section: https://gitlab.com/tango-controls/pytango/-/blob/v9.3.5/doc/howto.rst#L790-815

Register or login to create to post a reply.