IPyDriver

class IPyDriver(devices, tasks=[], **driverdata)

A subclass of this should be created with methods written to control your device.

devices is a list of Device objects this driver handles.

tasks is a list of co-routines that you may have created to operate your instruments, the co-routines set in this list will all be started when the driver is run. The tasks argument was introduced in version 1.1.0.

driverdata will be an attribute dictionary of any hardware data that may be usefull.

async asyncrun()

Gathers tasks to be run simultaneously

async clientevent(event)

Override this. On receiving data, this is called, and should handle any necessary actions. event is an object describing the event, with attributes devicename, vectorname, vector, root where vector is the properties vector the event refers to, and root is an xml.etree.ElementTree object of the received xml

async hardware()

Override this to operate device hardware, and transmit updates

For example: call your own code to operate hardware then update the appropriate vectors, and send updated values to the client using await vector.send_setVector()

static indi_number_to_float(value)

The INDI spec allows a number of different number formats, given any number string, this returns a float. If an error occurs while parsing the number, a TypeError exception is raised.

listen(host='localhost', port=7624)

If called, listens on the given host and port. Only one connection is accepted, further connection attempts while a client is already connected will be refused. This method also checks for enableBLOB instructions, and implements them. In general, using IPyServer is preferred.

async send(xmldata)

Transmits xmldata, this is an internal method, not normally called by a user.

async send_getProperties(devicename=None, vectorname=None)

Sends a getProperties request - which is used to snoop data from other devices on the network, if devicename given, it must not be a device of this driver as the point of this is to snoop on remote devices.

async send_message(message='', timestamp=None)

Send system wide message - without device name

async snoopevent(event)

Override this if this driver is snooping on other devices. On receiving snoop data, this is called, and should handle any necessary actions. event is an object with attributes according to the data received.

There are three ways a driver can be run, assuming ‘driver’ is an instance of this class.

This outputs the xml data on stdout, and reads it on stdin:

asyncio.run(driver.asyncrun())

This listens on the given host and port, to which a client can connect. Multiple drivers can be served, and multiple client connections can be made:

server = IPyServer([driver], host="localhost", port=7624, maxconnections=5)
asyncio.run(server.asyncrun())

This also listens on a host and port, but with a single connection only, may be useful for testing as it avoids the code associated with IPyServer:

driver.listen(host="localhost", port=7624)
asyncio.run(driver.asyncrun())

The driver is also a mapping, of devicename:deviceobject, so your code in the hardware or clientevent methods could access a specific device using self[‘devicename’].

Similarly a Device object is a mapping to a vector, so to access a vector you could use self[‘devicename’][‘vectorname’].

The ‘snooping’ capabilities enable one driver to receive data transmitted by another, possibly remote driver. For a simple instrument this will probably not be used.