Writing an application

Applications for OPN-2500 and OPN-6000 are written in the programming language C. All example applications in this SDK have a project files (.emProject) that can be opened using SEGGER Embedded Studio for ARM.

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.
  • Always add an endless loop to the main() function of your application, because when the main() function exits, the application will stop running.
  • 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. See also the AutoPowerDown() function to control sleep and power off.
  • More information about the use 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.
  • In case you want to add, remove, edit and export bar code data, then you won't have to write it yourself, because a complete bar code database implementation can be found in the Snippets section of this manual.

  • Below you'll find simple application to demonstrate reading of bar codes and menu-labels and basic power management features
    
    // This program reads menu labels from OptiConfigure and executes them.
    
    #include <stdio.h>
    #include "lib.h"
    
    void main( void )
    {
        char bcr_buf[42] = {0};
        struct barcode code  = {0};
        int result;
    
        code.min   = 1;
        code.max   = 41;
        code.text  = bcr_buf;
    
        //
        // The following function will try to restore system settings from flash memory and will cause
        // system settings to be stored in flash memory when 'SystemSetting("Z2")' is called.
        //
        if(SystemSettingsMemorizing(ON) < 0)
        {
            SystemSetting("U2");               // If no old settings were found -> Reset to default
        }
    
        SystemSetting("YC");                   // Make sure menu labels are always enabled after a restart
    
        // Disable to let the OS handle this. Else: Trigger mode, 5 seconds read time, scanner off after 1 barcode
        // ScannerPower(TRIGGER | SINGLE, 250);
    
        for(;;)
        {
            if(ReadBarcode(&code) == OK)
            {
                result = 0;
    
                if(code.id == MENU_CODE)
                {
                    ScannerPower(ON, -1);        // Scanner on indefinitely
    
                    while(result != EXITING_MENU_MODE && result != ERROR)
                    {
                        if(result == 0 || ReadBarcode(&code) == OK)
                        {
                           switch( (result=ExecuteMenuLabel(&code)) )
                           {
                               case ENTERING_MENU_MODE:
                                   Sound(TSTANDARD, VHIGH, SHIGH, SMEDIUM, SHIGH, 0);
                                   break;
    
                               case EXITING_MENU_MODE:
                                   ScannerPower(OFF, 0);
                                   Sound(TSTANDARD,VHIGH, SHIGH, SMEDIUM, SHIGH, 0);
                                   Delay(TSTANDARD * 4);        // Wait till buzzer sound ends before saving (saving flash settings temp. turns of sound timer)
                                   SystemSetting("YC");         // Make sure menu labels stay enabled
                                   SystemSetting("Z2");         // Save changed settings in flash memory
    
                                   while(TriggerPressed())      // Wait for release before resetting read mode
                                       Idle();
    
                                   ScannerPower(TRIGGER | SINGLE, 250);  // Reset read mode, because it's turned off after reading menu labels
                                   break;
    
                               case INVALID_OPTION_READ:
                                   Sound(TLONG, VHIGH, SLOW, 0);
                                   break;
    
                               case VALID_OPTION_READ:
                                   Sound(TSTANDARD, VHIGH, SHIGH, SMEDIUM, SHIGH,0);
                                   break;
    
                               case LABEL_IGNORED:
                                   break;
    
                               case ERROR:
                                   ScannerPower(OFF, 0);
    
                                   while(TriggerPressed())      // Wait for release before resetting read mode
                                       Idle();
    
                                   ScannerPower(TRIGGER | SINGLE, 250);  // Reset read mode, because it's turned off after reading menu labels
                                   break;
                            }
                        }
                    }
                }
                else
                {
                    GoodReadLed(GREEN, 10);
                    Sound( TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);
                    PutString(code.text);
                }
            }
    
            Idle();
        }
    }
    
    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