ISISComputingGroup / lewis-ess

Let's write intricate simulators!
GNU General Public License v3.0
21 stars 19 forks source link

Add support for sending unsolicited messages from a device #283

Closed FreddieAkeroyd closed 4 years ago

FreddieAkeroyd commented 4 years ago

This is used, for example, in the simulated gamry device. It sends a "charge complete" unsolicited message some seconds after being sent a command to "start charging".

The PR adds a unsolicited_reply() method so code like the following in the device StreamInterface can accomplish this:

# function to send unsolicited message when charging complete
def charged(self):
    self.handler.unsolicited_reply("STOPPED")

# Device commanded to start charging
def start_charging(self):
    t = Timer(self.charging_time, self.charged)
    t.start()
    return "STARTED"
DominicOram commented 4 years ago

@mattclarke, would you like to take a look at this? Otherwise I'm happy to merge it.