By setting, starting and stopping the barcode reader in the following procedure, you can read a barcode with the AM_ExecMenu function and receive AMENU_BARCODE_READ event.
  1. Define a AM_BarcodeBuffer structure and specify the buffer to store the barcode data.
    Sample
        char barcodebuff[13+1];
        AM_BarcodeBuffer buffer;
    
        buffer.dataBuf = barcodebuff;
        buffer.dataBufLength = sizeof(barcodebuff);
    

  2. Call AM_ConfigBarcodeReader function to register the above AM_BarcodeBuffer structure and initialization commands for the barcode reader in the menu resource.
    Sample
        hMenu = AM_CreateMenu(Task1MenuTable, (const pAM_Option)&TaskOption);
    
        // Set option commands
        //  B0:  Disable all symbology
        //  R1:  Enable UPC
        //  R4:  Enable EAN/JAN
        AM_ConfigBarcodeReader(hMenu, &buffer, "B0R1R4");
    

  3. Call AM_EnableBarcodeReader function to allow barcode reading.
    Sample
        AM_ShowMenu(hMenu, AM_SELECT_NO_ID);
        AM_EnableBarcodeReader(hMenu);
    

  4. If the barcode reading is allowed, a barcode will be scanned when the [SCAN] key is pressed while waiting for input in the AM_ExecMenu function.

  5. If a barcode is successfully read, the AM_ExecMenu function returns AMENU_BARCODE_READ event.

  6. After receiving this event, stop the barcode reader with AMenu_AM_DisableBarcodeReader function.

  7. If processing of the read barcode data is completed and you want to continue reading the barcode, call the AM_EnableBarcodeReader function again to allow the next barcode reading.
    Sample
        while(1){
            event = AM_ExecMenu(hMenu);
            // Waiting scan
            if (event == AMENU_BARCODE_READ){
                AM_DisableBarcodeReader(hMenu);
                // Got result
                AM_SetText(hMenu, TASK1_ID_RESULT, barcodebuff);
                AM_EnableBarcodeReader(hMenu);
                continue;
            }else if (event == CLR_KEY){
                //Exit
                break;
            }
        }
    

  8. If you want to stop reading the barcode, call the AMenu_AM_DisableBarcodeReader function.

Sample

    ...

void task1(void)
{
    MENU_HANDLE hMenu;
    int event;
    char barcodebuff[13+1];
    AM_BarcodeBuffer buffer;

    buffer.dataBuf = barcodebuff;
    buffer.dataBufLength = sizeof(barcodebuff);

    hMenu = AM_CreateMenu(Task1MenuTable, (const pAM_Option)&TaskOption);

    // Set option commands
    //  B0:  Disable all symbology
    //  R1:  Enable UPC
    //  R4:  Enable EAN/JAN
    AM_ConfigBarcodeReader(hMenu, &buffer, "B0R1R4");

    AM_ShowMenu(hMenu, AM_SELECT_NO_ID);
    AM_EnableBarcodeReader(hMenu);

    while(1){
        event = AM_ExecMenu(hMenu);
        // Waiting scan
        if (event == AMENU_BARCODE_READ){
            AM_DisableBarcodeReader(hMenu);
            // Got result
            AM_SetText(hMenu, TASK1_ID_RESULT, barcodebuff);
            AM_EnableBarcodeReader(hMenu);
            continue;
        }else if (event == CLR_KEY){
            //Exit
            break;
        }
    }
    AM_DisableBarcodeReader(hMenu);

    AM_ReleaseMenu(hMenu);
    return;
}

See also

Last updated: 2020/10/09