The application starts by setting up the variables, functions and routines required for the correct acquisition of data and the dispatch of events (see Fig. C.13). The variables are initialized in InitData() and the menu bar and the graphical interface are set in InitNib(). Afterwards, the event handlers are initialized in InitEvents() which calls two different handlers. The first one is AppEventHandler() and it is responsible to catch the user events and send them to ControlEvent() where they are dispatched. The second one is IdleTime() which is triggered every 1/60 Hz and performs periodic tasks such as writing data files (ltFileIO()) and moving the piezos according to the different protocols (AutoMovePiezos()). The InitControl() routine creates the default windows (trap and motor windows, oscilloscope, PSDs, etc.) and starts the thread that opens the USB port to communicate with the electronic controller (InstrumentTask()). Once all the initialization has been completed, the algorithm enters the RunApplicationEventLoop() which keeps running the application until the user quits.

The ControlEvent() is one of the central routines and it performs two types of tasks: 1) give orders to the instrument (e.g., center traps, motor gotos) by calling CommandInstrument() (the orders will be send in the next call of InstrumentTask()) and 2) create and setup windows by calling MakeWindow(). The windows can be either of two types: dialog windows and OpenGL windows. The first ones allow to modify the parameters of the protocols and the routine UtilityWindow() sets up the event handlers of them. The second ones are graphical windows that display the data measured by the instrument. The routine GraphWindow() creates and installs two different types of event handlers on these windows: 1) a timer event (timerContextCB()) that refreshes the graphics at a frequency of 60 Hz by using the DrawGL() routine and 2) a keyboard event (graphKeyEventHandler()) that allows to control the properties of the graph (zoom, shift, rotation, etc.).

To sum up, the application continuously runs a central loop that catches and dispatches all the possible events, which are managed by several event handlers that report to that loop. The events include user actions (keyboard, mouse) and periodic tasks (graphical rendering, pulling protocols). Besides, a parallel thread communicates with the instrument by using the USB port.

Figure C.13: Host algorithm (see text). The boxes represent the most important routines of the lt application. Each box indicates the name of the routine, a brief description of it and the file where it is defined. Horizontal and vertical arrows indicate the natural flow of the algorithm. Tilted arrows indicate the routines that report events to the main loop.

JM Huguet 2014-02-12