Running a Custom IDL Driver
As previously mentioned in IDL Driver File Locations, the example driver can be run as a service using example.conf, however since the example driver outputs feedback to the console as it executes, you will generally find it more useful to instead just run the example driver explicitly to monitor the execution flow and see the callback activity. To run the example driver directly:
- Using a console application like PuTTY to connect to the SmartServer IoT.
- Navigate to the /var/apollo/data/example/ directory.
- Type ‘
sudo ./example
’ to start up the IDL example driver you previously compiled.
You should see the above output to the console indicating that the IdiStart() function was called, that it returned successfully, and that the example thread was launched. The console also reports the internal version number of the IDL driver library itself. The IDL example driver can be exited at any time within the console by typing ^C (Control-C). To view the console feedback while the example driver runs, leave the driver application running and the console application open while working with the SmartServer IoT’s CMS.
Before loading the device type definition file (exampledevice.dtd) into the SmartServer IoT’s Device Types Widget, make sure the device interface file (example.xif) is already copied to the /var/apollo/data/example/res/ directory per the instructions in IDL Driver File Locations. As mentioned in that section, the CMS does not currently copy custom driver interface files into a custom driver resource directory automatically when they are imported into the Device Types Widget in the CMS (LUM-7757). Therefore, any device interface files need to be manually copied into the driver’s resource directory before first importing in any .dtd files. With the IDL example driver running, import (drag-n-drop) the exampledevice.dtd file into the Device Types Widget.
Following the import, exampledevice should show up in the Device Types Widget as shown below.
Create a new device called ExampleDevice that uses this custom driver protocol type using the parameters shown below.
The action of creating a device that uses this example driver triggers IDL to call the dev_create_cb() callback function in example.cpp that was registered by the example driver code with the IDL library in main.cpp:Â Â IdlDevCreateCallbackSet(idl, dev_create_cb);
This also generates output in the console from the running IDL driver application:
As you provision devices, de-provision devices, delete devices, read / write data points (and so on) that use this custom driver, the sample driver will output information to the console as these selected callback functions are triggered by the IDL library:
When running the IDL example driver explicitly in the console, we recommend that you de-provision and delete any created devices that use this protocol before terminating the IDL driver application in the console.