labscript-suite / labscript-devices

A modular and extensible plugin architecture to control experiment hardware using the 𝘭𝘒𝘣𝘴𝘀𝘳π˜ͺ𝘱𝘡 𝘴𝘢π˜ͺ𝘡𝘦.
http://labscriptsuite.org
Other
5 stars 58 forks source link

Implement mock flag for more devices #55

Open rpanderson opened 4 years ago

rpanderson commented 4 years ago

In developing works-out-of-the-box (and without any connected hardware) functionality and examples (#52, #53, #54), I've largely re-implemented subsets of existing labscript device code. As an alternative (or to supplement this), we could instead have a mock flag for (more) existing devices, which allows the functionality to be tested without that device being physically present. A good example of this is labscript_devices.IMAQdxCamera, which can be instantiated with:

# We then initiate an IMAQdxCamera using this RemoteBLACS instance
# using mock=True to bypass any attempts to commmunicate with an
# actual camera
IMAQdxCamera(
    name='camera',
    parent_device=camera_trigger,
    connection='trigger',
    serial_number=0xDEADBEEF,
    worker=test_remote,
    mock=True,
)

With this virtual device, one can even call labscript methods and simulated data will be generated in the shot file during transition_to_manual, e.g.

camera.expose(t, name='comparison', frametype='before', trigger_duration=0.2)

This has the benefit of being able to simulate control and automation workflows, which is obviously super useful for demonstration, training, etc.

On the other hand, extracting the minimal subset from actual labscript device code into dedicated dummy devices assists developers in writing new labscript device code for unsupported devices.

rpanderson commented 4 years ago

A good example of this is labscript_devices.IMAQdxCamera

See, for example, labscript-suite/labscript-utils#55.