Class Scanner
- java.lang.Object
-
- totalcross.io.device.scanner.Scanner
-
public class Scanner extends java.lang.ObjectScanner accesses some popular barcode scanners.Scanner access is only available when running on a native TotalCross VM; it is not supported when running on Java. It is, though, emulated on Java: a popup dialog will ask you for a barcode symbol which will be returned every time the
getDatamethod is called.Since there is only one scanner per device, the scanner class is static. Activating the scanner causes the physical scanner to be powered, and enables the trigger. Deactivating the scanner removes the power from the scanner and prevents scans from taking place. The scanner should always be deactivated at the end of processing to prevent excessive battery drain.
When the scanner is activated, scan events will appear in the MainWindow's onEvent method. The scan events will contain a string describing either the item scanned or a battery error. Deactivating the scanner prevents scan events from being delivered.
Since barcodes can have many formats, this class includes a method to register the barcode types with the scanner. These types must each be individually set as parameters to the scanner. After all the parameter types have been set, the commitBarcodeParams method must be called to register the parameters with the scanner. Once this is done the scanner is able to decode the specified barcode types.
A typical processing sequence is given below:
if (!Scanner.activate() || !Scanner.setBarcodeParam(Intermec.AZTEC, true) || !Scanner.commitBarcodeParams()) return; ... if (!Scanner.deactivate()) return;Note: to generate an installation for the SYMBOL MC32, you must deploy using -WINCE (creates cab without compression), and not -WINMO (creates cab with compression).
-
-
Field Summary
Fields Modifier and Type Field Description static booleanisActivestatic ControllistenerSet this listener to send all Scanner events to its onEvent method.static java.lang.StringscanManagerVersionThe scanner version.
-
Constructor Summary
Constructors Constructor Description Scanner()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void_onEvent(int type)Dispatch the event to the current listener (associated through thelistenerpublic member.static booleanactivate()Activate the scanner.static booleancommitBarcodeParams()Commit the barcode parameters to the scanner.static booleandeactivate()Deactivate the scanner.static java.lang.StringgetData()Get the decoded string of what has been scanned.static java.lang.StringgetScanManagerVersion()Get the scan manager version as an hexadecimal String.static java.lang.StringgetScanPortDriverVersion()Get the Scanner Port Driver version as an hexadecimal string.static voidproprietaryScanLoad(java.lang.Runnable scanLoad)static java.lang.StringreadBarcode(java.lang.String mode)Reads a barcode using ZXing for Android.static booleansetBarcodeLength(int barcodeType, int lengthType, int min, int max)Set the length of a barcode.static booleansetBarcodeParam(int barcodeType, boolean enable)Set a scanner parameter defining whether a barcode format will be used in scanning.static booleansetParam(int type, int barcodeType, int value)Set a parameter for the barcode.static voidsetParam(java.lang.String what, java.lang.String value)Used in the Honeywell Android barcode scanners.
-
-
-
Field Detail
-
isActive
public static boolean isActive
-
scanManagerVersion
public static java.lang.String scanManagerVersion
The scanner version.
-
listener
public static Control listener
Set this listener to send all Scanner events to its onEvent method.
-
-
Method Detail
-
proprietaryScanLoad
public static void proprietaryScanLoad(java.lang.Runnable scanLoad)
-
activate
public static boolean activate()
Activate the scanner. Return true if the scanner could be activated, false otherwise. (A false condition may arise if batteries have run too low, or if the unit does not have the scan library installed.Note: On Android Intermec, you can't activate the scanner if it is off in the settings. Moreover, you should not set the scanner and virtual wedge settings off and then try to use the scanner. Even though your app won't crash or hang, the device might not behave properly. There is no way to check if the device settings are off in the settings or in the app.
-
setBarcodeParam
public static boolean setBarcodeParam(int barcodeType, boolean enable)Set a scanner parameter defining whether a barcode format will be used in scanning. Choose from one of the barcode types given above.- Parameters:
barcodeType- the type of barcode under considerationenable- a flag to enable or disable decoding barcodes of this type.Note: On Android Intermec, you CAN'T set enable a barcode type the scanner is not activate. In this case, this method will return false.
-
setParam
public static boolean setParam(int type, int barcodeType, int value)Set a parameter for the barcode. You can use the xxx_PARAM constants to know which parameter to set, and also the values below for their values. Be careful because some functions may require also the barcode type.With Datalogic scanners, the SECOND parameter is not used (always pass 0 to it); and don't forget to call the commitBarcodeParams method.
Values valid for SYMBOL scanners:
// triggering modes #define LEVEL 0x00 #define PULSE 0x02 #define HOST 0x08 // Linear code type security #define SECURITY_LEVEL0 0x00 #define SECURITY_LEVEL1 0x01 #define SECURITY_LEVEL2 0x02 #define SECURITY_LEVEL3 0x03 #define SECURITY_LEVEL4 0x04 // UPC/EAN Supplementals #define IGNORE_SUPPLEMENTALS 0x00 #define DECODE_SUPPLEMENTALS 0x01 #define AUTODISCRIMINATE_SUPPLEMENTALS 0x02 // Transmit Check Digit options #define DO_NOT_TRANSMIT_CHECK_DIGIT 0x00 #define TRANSMIT_CHECK_DIGIT 0x01 // Preamble options #define NO_PREAMBLE 0x00 #define SYSTEM_CHARACTER 0x01 #define SYSTEM_CHARACTER_COUNTRY_CODE 0x02 // CheckDigit verification options #define DISABLE_CHECK_DIGIT 0x00 #define USS_CHECK_DIGIT 0x01 #define OPCC_CHECK_DIGIT 0x02 // MSI Plessey checkdigit options #define ONE_CHECK_DIGIT 0x00 #define TWO_CHECK_DIGITS 0x01 // MSI Plessey check digit algorithms #define MOD10_MOD11 0x00 #define MOD10_MOD10 0x01 // Transmit Code ID Character options #define AIM_CODE_ID_CHARACTER 0x01 #define SYMBOL_CODE_ID_CHARACTER 0x02 // Scan data transmission formats #define DATA_AS_IS 0x00 #define DATA_SUFFIX1 0x01 #define DATA_SUFFIX2 0x02 #define DATA_SUFFIX1_SUFFIX2 0x03 #define PREFIX_DATA 0x04 #define PREFIX_DATA_SUFFIX1 0x05 #define PREFIX_DATA_SUFFIX2 0x06 #define PREFIX_DATA_SUFFIX1_SUFFIX2 0x07 // Scan angle options #define SCAN_ANGLE_WIDE 0xB6 #define SCAN_ANGLE_NARROW 0xB5This method is ignored for Intermec scanners.
-
commitBarcodeParams
public static boolean commitBarcodeParams()
Commit the barcode parameters to the scanner. Returns true if the operation is successful and false, otherwise.Not used on the Windows CE and Android platforms.
-
setBarcodeLength
public static boolean setBarcodeLength(int barcodeType, int lengthType, int min, int max)Set the length of a barcode.This method is ignored for Intermec scanners. The lengthType must be one of the following values:
- Parameters:
barcodeType- One of the BARxxxx constantslengthType- 0 (variables length, min, and max are ignored), 1 (length = min), 2 (length = min || length = max), 3 (min <= length <= max). Careful: in Motorola Scanners, min and max must be used in inverted order due to a bug in the MOTOROLA API.min- The minimum valuemax- The maximum value
-
getData
public static java.lang.String getData()
Get the decoded string of what has been scanned. If an error occurs a null String will be returned.Note: On Android Intermec, you should first set some parameters before fetching data or else it might crash after 10 or 15 reads.
-
getScanManagerVersion
public static java.lang.String getScanManagerVersion()
Get the scan manager version as an hexadecimal String. If an error occurs or if this method is called before the Scanner is initialized, a null String will be returned.
-
getScanPortDriverVersion
public static java.lang.String getScanPortDriverVersion()
Get the Scanner Port Driver version as an hexadecimal string. If an error occurs or if this method is called before the Scanner is initialized, a null string will be returned.
-
deactivate
public static boolean deactivate()
Deactivate the scanner. Returns true if the operation is successful and false, otherwise.
-
_onEvent
protected static void _onEvent(int type)
Dispatch the event to the current listener (associated through thelistenerpublic member. Called from the native library. If there are no assigned listeners, the event is sent to the top most window, and the window is validated.
-
readBarcode
public static java.lang.String readBarcode(java.lang.String mode)
Reads a barcode using ZXing for Android. The mode can be one of:- 1D - for one dimension barcodes
- 2D - for QR codes
- empty string - for both
-
setParam
public static void setParam(java.lang.String what, java.lang.String value)Used in the Honeywell Android barcode scanners. See the totalcross.io.device.scanner.Honeywell constants. For example:Scanner.setParam(Honeywell.START_BATCH,"true"); ... set other parameters Scanner.setParam(Honeywell.END_BATCH,"true");
Dont forget the start and end batch, otherwise it won't work! For boolean parameters, use "true" or "false". For integer parameters, use the integer passed as String.
-
-