Quick Tutorial - Using the Barcode Scanner

Description

This tutorial will demonstrate the fundamentals of using the barcode scanner in BrightBuilder, and how to incorporate this feature into your application.

Resources

The Scanner Object

Scanning through BrightBuilder and BrightForms is handled by the Scanner object, which can be found in the data source tree under Objects > Scanner.

To use the scanner’s scanning methods, the scanner must first be opened. This is performed by the Scanner.OpenScanner() method, which returns an int of 0 if the scanner is opened successfully, or an error code of a failure. Once all scanning operations are completed, it may be closed with the Scanner.CloseScanner() method.

Any scanner methods which change scanner properties, such as Scanner.EnableBeeper() or Scanner.SetScannerName() must be called before the OpenScanner() method. Also, as the scanner tends to use much of a devices power, it is recommended limit the time a scanner is enabled. For example, on a single form, and the scanner object is opened and closed in a pre and post open expression, respectively.

Conducting a Scan

Once the scanner is open, a scan may be triggered, and this can be done programmatically via the Scanner.Scan() method in an expression. However, it should be noted that a device would typically have a button which will also trigger a scan.

Processing a Scan

Expressions used to process completed scans can be linked to a form via its ‘Action – Scan Complete’ property. This property will call the defined expression when the Scanner.Scan() method is completed, either if it is called by an expression or if done via the device’s interface.

A scan’s success or failure can be determined by the GetScanResult() method, returning 0 on a successful scan, else an error code.

If a scan is successful, the methods Scanner.GetBarcode() and Scanner.GetBarcodeType() can be used to return the captured data from the scanner. These methods’ return values (string and int respectively) may be assigned to variables or controls, and/or saved to the database with appropriate typing.

An example expression may be observed below:

local.result = Scanner.GetScanResult();

IF(local.result == 0)

{

    bcode_field = Scanner.GetBarcode();

    type_field = Scanner.GetBarcodeType();

    Form.MessageBox("Success", "Scan Complete", MB_OK);

}

Exercise

Complete the open_btn_Click and close_btn_Click expressions. These expressions will attempt to open and close the scanner – if successful; it will notify the user that the scanner has opened/closed, if not; it will display an error message with the appropriate error code.

Complete the scan_btn_Click expression, which induces a scan from the device through the scan_btn control in the form.

Create a new expression called onScanComplete which processes a scan. Have it check the scan result and if successful, load the scanned barcode and barcode types into the bcode_field and type_fields. Have this expression execute whenever a scan is triggered, and have it return status updates to the user on scan success/failure.

A possible solution is contained in ScannerFinished.bsp.