[quote=“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[/quote]
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.