tango-simlib: Changing command behaviour

Hello,

I am trying to simulate part of the Modbus Tango class that we use at the ESRF. This class does not have attributes but many commands.
I have overwritten one command of the Modbus class and successfully added a command to the simulator control device.
In the command that I have added to the simulator control device, I would
like to change the behaviour of the overwritten Modbus command of the simulated device (for instance, asking it to throw exception instead
of returning data)
How am I able to do this?

The two methods that I wrote are in different classes
(OverrideModbus for one and OverrideModbusSimControl for the other one)
and unfortunately, the device I receive as argument (tango_dev) in the simulator control command method is not the simulated device but the
simulator control device.

Thank's for your help

Emamnuel
Hi Emamnuel,

If I understand you correctly, you are trying to create a command on the sim control device that will be called on the sim device. At the moment our library does not support that. The commands on the sim control device only act on the device itself by manipulating the sim model or the default device attributes.

The only way you can be able to make the command on the simulated device to throw an exception is to specify that in the action-handler of the OverrideModbus class.

I hope that helps.

Kind regards,
K. Madisa
Manu
Hello,

I am trying to simulate part of the Modbus Tango class that we use at the ESRF. This class does not have attributes but many commands.
I have overwritten one command of the Modbus class and successfully added a command to the simulator control device.
In the command that I have added to the simulator control device, I would
like to change the behaviour of the overwritten Modbus command of the simulated device (for instance, asking it to throw exception instead
of returning data)
How am I able to do this?

The two methods that I wrote are in different classes
(OverrideModbus for one and OverrideModbusSimControl for the other one)
and unfortunately, the device I receive as argument (tango_dev) in the simulator control command method is not the simulated device but the
simulator control device.

Thank's for your help

Emamnuel

Emanuel: If I understand you correctly, you want to 1) issue a command on the simulator control device, 2) After 1), any calls to a specific command on the main device should raise an exception. I'll answer how that can be done below, but if you want a different behaviour please do shout out :)

You could enable that behaviour by having the sim control device command override setting your own python attribute on the model instance, and then having the override on the main simulator device checking that flag on the model. If the flag is present and true, it should raise an exception.

E.g.

class OverrideModbus(object):
    def action_the_command(self, model, tango_dev, data_input):
        if getattr(model, 'the_command_broken', False):
            "Raise exception here"
        # … rest of handler


class OverrideModbusSimControl(object):
    def action_break_the_command(self, model, tango_dev, data_input):
        model.the_command_broken = True

The getattr() call is neccesary since the current implementation of tango-simlib does not call the override class at initialisation time, but perhaps we can add a mechanism such that the user code also gets a chance to initialise the model instance during device initialisation. If this kind of "make a command break" feature is commonly required we can also look into making this a generic functionality such that any tango-simlib simulator allows commands on the simulator to be "broken" via the simcontrol interface.

I guess one could also change the API to pass in the main device to the handler functions, but the current design tries to keep a clean "model-view-control" architecture. I.e. the sim control interactions should always be via the model and not directly onto the device server instance.


Hello Nellen,

Thank's for the advice. I did something similar but instead of creating a new python attribute in the model, I created
it in the main device. I was able to retrieve the main device name in the simulation control device from its name (stored in the model) with the help of the Tango Util object.
Anyway your proposal is better because it requires less code. I have implemented it and it works fine.

Once again, thank's for the tip

Emmanuel

 
Register or login to create to post a reply.