Summary of microspec submodules

The microspec module has four submodules:

Summaries of each are below.

microspec.commands

commands defines class Devkit:

import microspec
kit = microspec.Devkit()

Each command in the serial communication protocol is a Devkit method.

Example:

kit.getBridgeLED()

See the full list of commands in microspec.commands.

microspec.constants

constants names the constants in the serial communication protocol.

Example:

import microspec as usp
usp.OK    # <---------------------- equals int 0
usp.ERROR # <---------------------- equals int 1

See the full list of constants.

constants also provides dictionaries for converting a constant’s integer code into a string name

Example:

import microspec as usp
usp.status_dict.get(usp.OK) # <---- returns str 'OK'

Note

Applications usually do not use these dictionaries. Module replies uses these dictionaries to make command responses human-readable.

See the microspec.constants unit tests (source code) for examples using all constants and all dicts in constants.

Values of the constants match the values in the globals object in the JSON API config file.

Consistency between constants defined in microspec and microspeclib is pinned by the unit tests in TestConsistent_with_microspeclib.

Note

Names of the constants are similar to the keys in the globals object, but the names are capitalized. Where possible, names are shortened for readability.

constants defines additional constants MAX_CYCLES and MIN_CYCLES. These are hard-coded in the dev-kit firmware but are not (yet) listed in the JSON config file.

microspec.replies

replies defines a namedtuple for the response to each command. Class Devkit uses replies to re-package the response returned by the microspeclib API.

Note

Do not directly use the replies module in application code.

The commands module uses replies to format responses. Application code should never need to instantiate a response.

Note

The responses to each command are defined in the protocol.sensor object in the JSON API config file. The responses to Bridge-specific commands are in protocol.bridge. The API hides the bridge responses to commands directed at the sensor, which is most commands.

microspec.helpers

helpers provides helper functions for common application tasks. Use the helpers to reduce lines of code.

Example:

import microspec as usp
ms = usp.to_ms(usp.MAX_CYCLES)

The commands module incorporates helpers where possible. For example, setExposure() and getExposure() already incorporate the time conversion helpers.