|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This class represents the base class for all ScannerListener implementations. All ScannerListener implementation must inherit from this class. This interface must be implemented if scan aware mode is used in order to receive scanner event notifications.
Example: Set an event listener and start scanning Code39 barcodes.Description: Create scanner parameters, open a scanner connection. Set an event listener and start scanning Code39 barcodes.
public class ScannerExample implements ScannerListener{
private int barcodeCount = 0;
public void onError(ScannerException e) {
System.out.println("The following error ocurred. " + e.getMessage());
barcodeCount = 5; //Exit the loop since an error occurred.
}
public void onDataReceived(ScannerData scannerData) {
System.out.println("Symbology = " + scannerData.getSymbology().getName());
try {
System.out.println("Data = " + new String(scannerData.toByteArray(),"ASCII"));
++barcodeCount;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void scanFiveBarcodes() {
try {
//loop to wait for 5 barcodes to be scanned.
while(barcodeCount < 5) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
try {
Connector connector = Connector.getInstance();
DriverInfo[] scanners = connector.listDrivers(ConnectionType.SCANNER);
ScannerParameters parameters = new ScannerParameters(scanners[0]);
parameters.setMode(ScannerParameters.SCAN_AWARE);
ScannerConnection scanner = (ScannerConnection)connector.open(parameters);
ScannerExample example = new ScannerExample();
scanner.addSymbology(new Code39(Code39.FULLASCII));
scanner.setEventListener(example);
scanner.startRead();
example.scanFiveBarcodes();
scanner.endRead();
scanner.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
ScannerConnection
,
com.sap.ip.me.api.pios.symbology
,
ScannerData
,
ScannerException
Method Summary | |
void |
onDataReceived(ScannerData data)
Invoked whenever a barcode is scanned by the user. |
void |
onError(ScannerException ex)
Invoked whenever the reader encountered an error while performing a read operation. |
Method Detail |
public void onDataReceived(ScannerData data)
data
- the ScannerData object that include barcode related informationScannerData
public void onError(ScannerException ex)
ex
- the ScannerException exception objectScannerException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |