Hi,
I have a camera set up as a network device support package (NDSP) in ARTIQ. Saving images with this camera is time intensive (approx 1s) compared to the length of an experimental shot (approx 2s). I would like to make the image saving happen asynchronously so that the experimental shot does not take any additional time.
I've set up a mock NDSP aqctl_ExampleDevice.py
import argparse
import logging
from sipyco.pc_rpc import simple_server_loop
from sipyco import common_args
from time import sleep
logger = logging.getLogger("controller_ExampleDevice")
class ExampleDevice():
def __init__(self, serial):
# Make connection to device
pass
def ping(self):
return True
def save_image(self):
# Simulate image saving by sleeping
sleep(1)
def get_argparser():
parser = argparse.ArgumentParser(description="Thorlabs Zelux camera controller")
common_args.simple_network_args(parser, 3249) # 3249 is the default TCP port
parser.add_argument("-d", "--device", default=None,
help="The serial number of the camera.")
common_args.verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
common_args.init_logger_from_args(args)
logger.debug(f"Connecting to {args.device}")
example = ExampleDevice(args.device)
try:
logger.debug("Starting server")
simple_server_loop({"example": example}, common_args.bind_address_from_args(args), args.port)
finally:
example.close()
if __name__ == "__main__":
main()
The device is registered in device_db.py
as
device_db["example_device"]={
"type": "controller",
"host": "::1",
"port": 40109,
"command": "python drivers/aqctl_ExampleDevice.py -p {port} -d 13315 -vv"
}
My EnvExperiment
class is as follows
from artiq.experiment import *
class Example(EnvExperiment):
def build(self):
self.setattr_device('core')
self.setattr_device('ttl0')
self.setattr_device('example_device')
def prepare(self):
pass
@kernel
def run(self):
self.core.reset()
for i in range(20):
self.ttl0.pulse(1*ms)
delay(1)
self.core.wait_until_mu(now_mu())
self.example_device.save_image()
The time between TTL pulses is 2 seconds. Is there a way I can call save_image
asynchronously to prevent this blocking behavior?