- Custom Development
The most noticeable new features are:
As the new interface allows you to connect to multiple devices at a time, the interface needs some way for you to specify which device you intend to interact with at any given time. This handle is the device id. You can get a full list of available device ids by calling fxGetDeviceIds(). Thus for the most part, function calls will change in the following format:
foo(args…) → foo(devId, args…)
This is true of the following functions:
There are however several changes to the interface that should simplify your code:
The utility function loadAndGetDevice() should simplify your initialization to one line. It can be used in two ways
loadAndGetDevice( filename, numDevices)
loadAndGetDevice( comPortList )
The function opens all specified COM ports and waits until fxGetDeviceIds provides a list of ids that is at least numDevices long. On success, the function returns this list. Otherwise the function calls sys.exit().
If you'd like to write the initialization yourself, note the following changes in API functions:
There are however, several exceptions which should mostly simplify your code:
Since the interface now abstracts communication protocols from the user this process is greatly simplified. To start streaming data from the device (and simultaneously stream control commands to the device) use the following
setSuccess = fxSetStreamVariables(devId, varsToStream) #varsToStream is a list of field ids taken from pyFlexsea_def.py streamSuccess = fxStartStreaming(devId, frequencyInHz, shouldLogToFile, shouldUseAutoStreaming) #frequencyInHz must match a frequency in FX_VALID_FREQUENCIES from pyFlexsea_def.py
Note: The same function is used for different devices (rigid vs. pocket). You are expected to provide field ids that are valid for the device specified by devId.
The interface starts streaming data from the device, and populating an internal buffer with received data. The process for reading data is as follows:
dataValues = fxReadDevice(devId, fieldIds) #fieldIds is a list of field ids whose values are retrieved
dataValues is then populated with the values of the requested field ids, in the order requested. If an error occurred while fetching a field (fieldId invalid, or field not accessible because it's not being streamed) the value will be None.
Previous utility functions printRigid() and printPocket_s are replaced by printData(labels, values), where you should provide labels, a list of string which matches the length of values.
All controller commands simply take the device id handle, and are mentioned in the above section.