diff --git a/artiq/devices/lda/driver.py b/artiq/devices/lda/driver.py index 4e6742e2e..3f5aaa2e2 100644 --- a/artiq/devices/lda/driver.py +++ b/artiq/devices/lda/driver.py @@ -26,6 +26,10 @@ class Ldasim: def get_att_step_size(self): return self._att_step_size + def close(self): + """Close the device.""" + pass + def get_attenuation(self): """Reads last attenuation value set to the simulated device. diff --git a/artiq/devices/thorlabs_tcube/driver.py b/artiq/devices/thorlabs_tcube/driver.py index f7bac7221..8643c388e 100644 --- a/artiq/devices/thorlabs_tcube/driver.py +++ b/artiq/devices/thorlabs_tcube/driver.py @@ -211,6 +211,10 @@ class Tcube: self.port.flush() logger.debug("baud rate set to 115200") + def close(self): + """Close the device.""" + self.port.close() + def send(self, msg): msg.send(self.port) diff --git a/artiq/frontend/lda_controller.py b/artiq/frontend/lda_controller.py index 225700cca..27714870f 100755 --- a/artiq/frontend/lda_controller.py +++ b/artiq/frontend/lda_controller.py @@ -27,8 +27,11 @@ def main(): lda = Ldasim() else: lda = Lda(args.serial, args.product) - simple_server_loop({"lda": lda}, - args.bind, args.port) + try: + simple_server_loop({"lda": lda}, + args.bind, args.port) + finally: + lda.close() if __name__ == "__main__": main() diff --git a/artiq/frontend/thorlabs_tcube_controller.py b/artiq/frontend/thorlabs_tcube_controller.py index bc5c32e23..90dbb12c3 100755 --- a/artiq/frontend/thorlabs_tcube_controller.py +++ b/artiq/frontend/thorlabs_tcube_controller.py @@ -37,7 +37,10 @@ def main(): elif args.product == "TPZ001": dev = Tpz(args.device) - simple_server_loop({args.product.lower(): dev}, args.bind, args.port) + try: + simple_server_loop({args.product.lower(): dev}, args.bind, args.port) + finally: + dev.close() if __name__ == "__main__": main()