Determine Symbology
This example shows how to determine the symbology of a scanned barcode.

· This feature is available only if the scanner supports it. Some scanners makes and models may not provide this functionality.
· This example assumes that at least one driver has been installed. It also assumes this driver supports all the attributes that are being used.
...
1. Implements the constructor for the class. It opens a connection to the scanner in scan aware mode and sets an event listener.
2. Implements the onError method from ScannerListener.
3. Implements the onDataReceived method from ScannerListener.
4. Declares and implements a method called scanBarcode. This method starts the scanning engine, waits for the application to read a barcode, and stops the scanning engine.
5. Declares and implements the method called activateSymbologies. This method adds Code 39, Code 128, and Codabar symbologies to the scanner.
6. Declares and implements the getSymbologyName method. It returns the symbology name determined during the onDataReceived event.
7. Declares and implements the close method. It closes the connection to the scanner.
8. Creates a new instance of the class and activates symbologies for the scanner.
9. Scans a barcode and displays the symbology of the barcode.
10. Closes the connection to the scanner.
package scanner_api_examples;
import com.sap.ip.me.api.pios.PIOSException;
import com.sap.ip.me.api.pios.connection.*;
import com.sap.ip.me.api.pios.scanner.*;
import com.sap.ip.me.api.pios.symbology.*;
public class DetermineSymbology implements ScannerListener {
private ScannerConnection scannerConnection = null;
private boolean barcodeScanned = false;
private String symbologyName = null;
private Exception lastException = null;
//-----------------------(1)-----------------------
public DetermineSymbology() throws PIOSException {
Connector connector = Connector.getInstance();
DriverInfo[] scanners = connector.listDrivers(ConnectionType.SCANNER);
ScannerParameters parameters = new ScannerParameters(scanners[0]);
parameters.setMode(ScannerParameters.SCAN_AWARE);
scannerConnection = (ScannerConnection) connector.open(parameters);
scannerConnection.setEventListener(this);
}
//-----------------------(2)-----------------------
public void onError(ScannerException e) {
lastException = e;
barcodeScanned = true;
}
//-----------------------(3)-----------------------
public void onDataReceived(ScannerData scannerData) {
symbologyName = scannerData.getSymbology().getName();
barcodeScanned = true;
}
//-----------------------(4)-----------------------
public void scanBarcode() throws Exception {
scannerConnection.startRead();
while (!barcodeScanned) {
Thread.sleep(500);
}
if (lastException != null) {
throw lastException;
}
scannerConnection.endRead();
barcodeScanned = false;
}
//-----------------------(5)-----------------------
public void activateSymbologies() throws PIOSException {
scannerConnection.addSymbology(new Code39(Code39.FULLASCII));
scannerConnection.addSymbology(new Code128());
scannerConnection.addSymbology(
new Codabar(
Codabar.CHECK_DIGIT_MOD16
| Codabar.CHECK_DIGIT_TRANSMIT));
}
//-----------------------(6)-----------------------
public String getSymbologyName() {
return this.symbologyName;
}
//-----------------------(7)-----------------------
public void close() {
try {
scannerConnection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
DetermineSymbology determineSymbologyExample = null;
try {
//-----------------------(8)-----------------------
determineSymbologyExample = new DetermineSymbology();
determineSymbologyExample.activateSymbologies();
//-----------------------(9)-----------------------
determineSymbologyExample.scanBarcode();
System.out.println("Symbology = " + determineSymbologyExample.getSymbologyName());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//-----------------------(10)-----------------------
determineSymbologyExample.close();
}
}
}