C Language Development Kit/Application development/Writing an application

From OptiWiki

Jump to: navigation, search

Applications for an Opticon terminal should be written in the programming language C. The source of an application can be created with every text editor, for example with Notepad that is supplied with Windows™.

Important issues

When writing an application for an Opticon terminal you must take the following in account:

  • Always include the header file 'lib.h' in your application to get access to all public Operating System functions.
  • When using the functions malloc() and free() always include the header file 'stdlib.h' in your application. For the OPL972x, NO warning is given when this header file is not included, but the functions malloc() and free() won't work properly without it.
  • Always add an endless loop to the main() function of your application, because when the main() function exits, the application will stop running and the message 'Application halted' is shown. The application can then only be restarted by using the restart option of the system menu or by temporarily removing the battery.
  • When waiting in a loop (i.e. for user input) always use the idle() function, because this greatly reduces the power consumption of the terminal.
  • More information about the use of all the Operating System functions can be found in the Functions section of this manual. Every described function in this section also contains the sources of an example program, which demonstrates how the function can be used. The description of the standard ANSI C functions is beyond the scope of this document, but a detailed description can be found on the Internet, for instance here.
  • If a database is needed in your application, then you won't have to write it yourself, because a complete database implementation can be found in the Snippets section of this manual.
  • On handheld terminals user input is realized by keyboard input or by reading bar codes. In the Snippets section of this manual several functions can be found that can be used to process this keyboard and scanner input.

Below you'll find a very simple example of an application that you can run on every handheld terminal. You can copy the source code to a text editor and save the file with the extension '.C' (i.e. DEMO.C)

#include "lib.h"
#include <stdio.h>
void main( void )
    printf("\fHello world");     // clear screen and print 'Hello world'
    while( 1 )        // Enter loop, because applications may not exit main()
        idle();       // use idle() to reduce power consumption

When your application is ready to be build, you should invoke the compiler and linker to build your application. How this is done in described in the following section of this manual:

Building an application

Personal tools