com.sap.ip.me.api.pios.scanner
Interface ScannerListener


public interface ScannerListener

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();
 		} 
 				 		
 	}
 }
 
 

Since:
MI 2.5
Author:
Abaco
See Also:
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

onDataReceived

public void onDataReceived(ScannerData data)
Invoked whenever a barcode is scanned by the user. This method must be implemented in order to process data scanned by the user.

Parameters:
data - the ScannerData object that include barcode related information
See Also:
ScannerData

onError

public void onError(ScannerException ex)
Invoked whenever the reader encountered an error while performing a read operation. When this error is raised the user must close the scanner connection and open a new connection before further scanning is performed. This method must be implemented in order to process error notifications.

Parameters:
ex - the ScannerException exception object
See Also:
ScannerException


Copyright © 2005 SAP AG. All Rights Reserved.