Elevator Pitch
Every lab geek has to deal with great number of different hardware, from the typical power supply to the home made particle accelerator. Learn how to harmonize all that hardware and create an interface that is easy and fun to use.
Description
API definition
Learn to define classes that reflect your hardware in a natural way.
- Use properties for hardware states (current, radiance)
- Use methods for actions (image acquisition, calibrate)
- Don’t fail silently, raise Exceptions that reflect the problems (custom Exceptions if necessary)
- Use private “_” methods for hardware peculiarities (set register, connect)
Extract API
Parse your class definition to generate a representation of public methods and properties
- Add annotations to reflect input and output types (voltage <-> float, image -> numpy array )
- Automatically generate a Json with setters, getters and methods that describe your class
REST interface
Create a flask app that will call your hardware class
- Use your class descriptor (json) to automatically generate a rest interface
- Transform exceptions into http errors
- Share your class descriptor for client generation
REST client
Accessing your REST interface, create a client to communicate with your hardware remotely
- Use your class descriptor (json) to automagically generate a class with the same public methods and properties
- Access your hardware from everywhere as if it was local
- Work with different hardware that are dispersed in different locations as if it were locate in the same place
Enjoy your life outside of the lab!
Notes
In my day work I have to control different equipment in different labs and production environments. Cameras, power supply, radiometers, environmental chambers…
I have been perfecting this method for the past 5 years. This methodology allows me to greatly simplify development, and more importantly decouples the use of the hardware from it’s physical location, specially useful in long run procedures