Connect()

From SweepMe! Wiki
Jump to navigation Jump to search

The function connect can be added to any Device Class:

def connect(self):
   # do something

This function is called once at the beginning of each run, for all enabled modules of the sequencer from root to leaf, including modules of branches that are only reached later. It is intended to make everything ready for further communication with the device.

If your driver uses the Port manager (self.port_manager = True), SweepMe! has already opened the port before connect() is called, and the port is available as self.port. By default, the port is also cleared at this point (port property "clear"). In this case, you only need connect() for additional tasks, e.g. coordinating several channels of one instrument via self.device_communication. Otherwise, you can create your own object here to communicate with your device.

The counterpart is disconnect(). It is called at the end of the run even if connect() raised an error, and the same applies to deinitialize(). Make sure that both functions do not fail if an attribute that is created in connect() does not exist.