All the programs that interact with the EV3 hardware use the following three include files that are part of the EV3 source code (lms2012.h, bytecodes.h and lmstypes.h). The files can be copied and pasted from the links. They must be placed in the same work directory as the program that is being compiled.
Sensors are acceded using file operations that operate on special device files. In order to access the sensor data, the user must perform a few steps that involve opening the device, mapping the device data in user space, and if needed, configuring the device.
Opening and mapping the device is done in pretty much the same way for all types of sensors. The following examples cover some typical cases:
At startup, a sensor will be configured to work using default configuration parameters, however users may want to change the sampling frequency, pick a different mode of operation, increase the number of bytes in the data packet, or send direct commands to the sensor. This is done using input/output control functions (ioctl). The use of this function requires some understanding of the sensor capabilities. The following examples show the use of configuration functions: