This tutorial guides through construction of CyberAtom API objects and retrieving system information (model and firmware version) from AHRS device connected to PC via USB cable.
The API library uses concept of a logical device object that represents connected device in user's code. This is what Device class is for. Once instantiated, plays central role in application-to-device communication.
In order to construct a logical device object, references to two existing interfaces needs to be provided:
To use connection to the device via USB cable, UsbConnection object can be created:
Receiving data from the device, is possible by creating class that derives from IResponse class and override specific methods for the data you are interested in.
E.g. to receive and print system information, you can define your response class like that:
and then in the main function you can instantiate it with:
Once this is done, you can create logical device object:
With this device object, you are now free to request for various information, e.g system details, like:
This method call sends request to the device. Now wee also need a way to obtain the information device is sending back. For that we need to use Device.checkForMessages() method, in a periodic loop until the message we expect arrives:
When the system information message arrives from the device, the IResponse.sysInfo() method will be called back by the device object, which eventually will print retrieved information to the console and help to terminate the loop
With adding some exception handling, the complete code can look like that:
This tutorial demonstrates how-to retrieve system information from the CyberAtom AHRS device. The technique is based on using central Device class and implementation of IResponse interface as a handler for incoming data. This is the pattern that works for almost any data retrieval scenario.
Other methods of Device class allows to send data to the device in one-directional way, which is event simpler and does not require implementing subclassing from IResponse.