Next: , Previous: Usage, Up: Top


4 Code

This section of the manual is only for those interested into learning how kacq works at the code level. That might be good to read that if you want to play a bit with the code.

kacq can run up to 3 threads. The main thread, which always runs, responds to the user input, draw the oscilloscope, and manages 2 other processing threads. Given that the interactions between the 3 processing threads are limited to copying a buffer with the raw data, many operations can occurs in parallel in the different threads without problem. Another advantage is that heavy processing of the data in the displaying thread is unlikely to block the acquisition thread and cause buffer overflow. Ideally, poor performance in the displaying thread should only impairs the display and not interfere with acquisition and recording of the data.

The user can start either the oscilloscope or the recording process. Either of these actions will start the acquisition thread. The recording and displaying processes are independent of each other. You can use the oscilloscope without recording or recording without the oscilloscope. Playing with the oscilloscope should not affect the recording.

4.1 Acquisition thread

This thread is responsible for fetching the data from the AD devices and to making the new data available to the rest of the program. It is therefore running whenever the recording or oscilloscope is running. There are two main structures used in the acquisition thread. One represents each individual device that are installed on the computer. The other is a comedi_interface which controls and syncrhonyzes the individual devices. The acquired data are available in the data_buffer of the comedi_interface structure. To avoid inconsistencies due to operations by multiple threads upon the same memory area performed at the same time or to prevent race conditions, this is the only memory chunck that is shared between the three processing threads. Moreover, when one thread read or write in that data_buffer, the other threads are prevented from reading or writing in it and must wait.

4.2 Recording thread

The recording thread gets the acquired data from the comedi_interface and copies the data needed into a recording_buffer. When enough data has accumulated into the recording_buffer, a call to the API write() is performed to save the data on a hard drive. Only the channels selected in the preference dialog box will be saved.

4.3 Displaying thread (main thread)

This thread gets the raw data from the acquisition buffer and reformat it so that is can be displayed on the screen. The data are drawn on a gtk drawing area using cairo. The oscilloscope also saves newly acquired data in a buffer so that the user can go back and have a look at recently acquired data.