SnoopEvents

The driver has method:

async def snoopevent(self, event):

If this driver is ‘snooping’ on other drivers, this method should be written to handle events created as data is received.

Snooping is typically used when an instrument should only take actions if another remote instrument has already taken a required prior action. Snooping may also be useful as a method of logging traffic.

Your code should read the event contents, and then take any appropriate action.

Snooping

A driver can be set to snoop on another drivers device and vector traffic with the method:

snoop(devicename, vectorname, timeout=30)

This will cause the driver to transmit a ‘getProperties’ request, which will instruct servers to copy traffic originating from the specified device/vector to this driver, as if it was a connected client. Since intermediate servers may get switched off and on and lose the copy instruction, if no traffic is received after the timeout value, then another getProperties will be sent.

It is also possible for a driver to await a send_getProperties command directly using coroutine method:

send_getProperties(devicename=None, vectorname=None)

This has the same effect as the snoop command, however without the timeout facility, and this command could have devicename and vectorname set to None.

If vectorname is None, then all traffic from the specified device will be copied, if devicename is None as well, then traffic from all devices will be copied (apart from devices on this particular driver).

As this has no timeout function it is up to user code to provide a repeating send_getProperties call if it is deemed necessary.

Note: in this implementation, snooping will not occur between devices on the same driver. Your driver code is handling all its devices, so should be able to control all traffic needed between them. However snooping can occur between drivers connected to the same IPyServer, or across multiple IPyServers linked together by remote connections.

When the copied traffic is received by this driver, the snoopevent method will be awaited. The snoop event objects are described below, you never need to create these objects - they are automatically created by the received data, however you should overwrite the snoopevent method to test the event matches an object, and act accordingly.

The event type passed into the method reflects the command sent by the remote device.

Events

All snoop events have attributes devicename, root and timestamp. The root is an xml.etree.ElementTree object. The timestamp is a datetime object, or None if unable to parse the timestamp given in the protocol. In the attempt to parse, fractional minutes or seconds may be lost, and if no received timestamp is given, datetime.utcnow() is used. If the exact received timestamp is required it can be obtained from event.root.get(“timestamp”) which will return either the string from the received xml, or None if not present.

class Message(root)

This contains attribute ‘message’ with the message string sent by the remote driver. Attribute devicename could be None if the driver is sending a system wide message.

class delProperty(root)

The remote driver is instructing the client to delete either a device or a vector property. This contains attribute vectorname, if it is None, then the whole device is to be deleted. A ‘message’ attribute contains any message sent by the remote driver with this instruction.

def Vector events also all have attributes vectorname, label, group, state and message. They are also a mapping of membername:value, which should contain all the vector member names, so for example event[‘membername’] would give the value of that member.

class defSwitchVector(root)

The remote driver has sent this to define a switch vector property, it has further attributes perm, rule, timeout, and memberlabels which is a dictionary of membername:label.

class defTextVector(root)

The remote driver has sent this to define a text vector property, it has further attributes perm, timeout, and memberlabels which is a dictionary of membername:label.

class defNumberVector(root)

The remote driver has sent this to define a number vector property, it has further attributes perm, timeout, and memberlabels which is a dictionary of membername:(label, format, min, max, step).

getfloatvalue(membername)

Given a received membername in this event, returns the number as a float

class defLightVector(root)

The remote driver has sent this to define a light vector property, it has further attribute memberlabels which is a dictionary of membername:label.

class defBLOBVector(root)

The remote driver has sent this to define a BLOB vector property, it has further attributes perm, timeout, and memberlabels which is a dictionary of membername:label.

However this class does not have an object mapping of member name to value, since values are not given in defBLOBVectors

set Vector events all have attributes vectorname, message and state (which could be None if not given due to no change of state). These events are also a mapping of membername:value, so for example event[‘membername’] would give the value of that member. However this object may not include members if they have not changed.

class setSwitchVector(root)

The remote driver is setting a Switch vector property, this has further attribute timeout.

class setTextVector(root)

The remote driver is setting a Text vector property, this has further attribute timeout.

class setNumberVector(root)

The remote driver is setting a Number vector property, this has further attribute timeout. The number values of the membername:membervalue are string values.

getfloatvalue(membername)

Given a received membername in this event, returns the number as a float

class setLightVector(root)

The remote driver is setting a Light vector property.

class setBLOBVector(root)

The remote driver is setting a BLOB vector property, this has further attributes timeout and sizeformat which is a dictionary of membername:(size, format).