Documents > BPS V2 C++ API
BpsKeyboardScanner Class Reference

Handles input of scanners that are looped into the keyboard input stream. More...

#include <bpskeyboardscanner.h>

List of all members.

Public Member Functions

 BpsKeyboardScanner (QObject *aParent=0)
void setTimeout (int aTimeout)
 Change time out seconds.
int timeout () const

Detailed Description

Handles input of scanners that are looped into the keyboard input stream.

Scanner configuration

The scanner must be programmed to send a record as follows:

  1. A prefix character STX (Ctrl-B)
  2. A code identifier character (see BpsScannerEvent for allowed types)
  3. The scanned data (one or more characters)
  4. A suffix character ETX (Ctrl-C)

The default time out is 5 seconds after receiving a STX. It is recommended to make timeout configurable from the value set in Central System Settings/Scanning/Keyboard in the key Timeout (see example below).

How it works

This handler will process all keystrokes sent to any widget of the application and wait for a STX. Until then, all keystrokes are just forwarded to be processed as normal user input.

As soon as a STX key press is detected, all subsequent key press and release events are collected as scanner input, until either an ETX key press happens, or the time out happens. During this phase the collected characters are filtered (not delivered to the focus widget).

Finally when ETX is received the collected characters between STX and ETX are analyzed. When more than one character was received, the first character is taken as Code Identifier and the rest as data. A event of type BpsScannedEvent is created and sent to the focus widget.

Usage

An object of this type is usually installed as event filter of GUI applications:

 int main(int argc, char *argv[])
 {
    BpsApplication a(argc, argv);
    a.setOrganizationName(bStr(BPS_ORGANIZATION_NAME));
    a.setOrganizationDomain(bStr(BPS_ORGANIZATION_DOMAIN));
    a.setApplicationName(bStr(BPS_APPLICATION_NAME));
    BpsKeyboardScanner scanner;
    a.installEventFilter(&scanner);
    // .....
    // After login:
    BpsSettings settings(aDatastore, BpsSettings::CentralSystemScope);
    settings.open(bStr("Settings/Scanning/Keyboard"));
    scanner.setTimeout(settings.value(bStr("Timeout")).toInt());
    // .....

This handler will then do the keyboard stream processing for any number of widgets that shall be able to process scanner input.

On every widget that shall process scanner inputs, a BpsScannerFilter object must be created and installed as event filter for dialog elements that can receive keyboard input:

 MyWidget::MyWidget(QWidget* aParent) : QWidget(aParent)
 {
     // .....
     BpsScannerFilter* sf = new BpsScannerFilter(this);
     foreach (QWidget* w, findChildren<QWidget*>()) w->installEventFilter(sf);
     connect(sf, SIGNAL(scanned(char,QString)), 
             this, SLOT(myScannerInput(char,QString)));
     // .....
 } // constructor

Constructor & Destructor Documentation

BpsKeyboardScanner::BpsKeyboardScanner ( QObject *  aParent = 0)
Parameters:
[in]aParentThe parent object.

Member Function Documentation

void BpsKeyboardScanner::setTimeout ( int  aTimeout)

Change time out seconds.

Parameters:
[in]aTimeoutThe new time out in seconds, must be greater than 0.
int BpsKeyboardScanner::timeout ( ) const
Returns:
The current timeout in seconds (default = 5).

The documentation for this class was generated from the following file: