Hi im developing a wrapper for the MC40 devices we have.
The MX Version is as follows:
OSX Version : TI.51.5.2.10
MXMF Version : 5.3.2.0
Android Version : 5.1.1
EMDK Service Version (On Device) : 5.0.3.0
The error that i keep getting
03-20 21:59:46.758 7888-7888/com.test.omscp W/System.err: java.lang.ArrayIndexOutOfBoundsException: length=10; index=31690992003-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at com.symbol.emdk.EMDKManager.getInstance(EMDKManager.java:221)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at com.test.omscp.emdk.EMDKScannerClass.initializeScanner(EMDKScannerClass.java:74)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at com.test.omscp.emdk.EMDKScannerClass.onOpened(EMDKScannerClass.java:44)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at com.symbol.emdk.EMDKServiceConnection.notifyonConnected(EMDKServiceConnection.java:124)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at com.symbol.emdk.EMDKServiceConnection.onServiceConnected(EMDKServiceConnection.java:104)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1208)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1225)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.os.Handler.handleCallback(Handler.java:739)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.os.Looper.loop(Looper.java:135)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5254)03-20 21:59:46.759 7888-7888/com.test.omscp W/System.err: at java.lang.reflect.Method.invoke(Native Method)03-20 21:59:46.760 7888-7888/com.test.omscp W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)03-20 21:59:46.760 7888-7888/com.test.omscp W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)03-20 21:59:46.760 7888-7888/com.test.omscp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
My Code is as follows:
public class EMDKScannerClass implements EMDKListener, StatusListener, DataListener { // Declare a variable to store EMDKManager object private EMDKManager emdkManager = null; // Declare a variable to store Barcode Manager object private BarcodeManager barcodeManager = null;// Declare a variable to hold scanner device to scan private Scanner scannerEMDK = null; public EMDKScannerClass() { EMDKResults results = EMDKManager.getEMDKManager(OMSCPApplication.getGlobalContext(), this); if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) { Logger.d("Status: ", "EMDKManager object request failed!"); } } @Override public void onOpened(EMDKManager emdkManager) { this.emdkManager = emdkManager; try { // Call this method to enable Scanner and its listeners initializeScanner(); } catch (ScannerException e) { e.printStackTrace(); } } @Override public void onClosed() {} @Override public void onData(ScanDataCollection scanDataCollection) { } @Override public void onStatus(StatusData statusData) {} /** * Method to initialize and enable Scanner and its listeners */private void initializeScanner() throws ScannerException { if (scannerEMDK == null) { // Get the Barcode Manager object barcodeManager = (BarcodeManager) this.emdkManager .getInstance(EMDKManager.FEATURE_TYPE.BARCODE); if (barcodeManager != null) { // Get default scanner defined on the device scannerEMDK = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT); // Add data and status listeners scannerEMDK.addDataListener(this); scannerEMDK.addStatusListener(this); // Hard trigger. When this mode is set, the user has to manually // press the trigger on the device after issuing the read call. scannerEMDK.triggerType = Scanner.TriggerType.HARD; // Enable the scanner try { scannerEMDK.enable(); Logger.d("Status", "Scanner started."); } catch (ScannerException e) { Logger.d("Status", "Scanner initialization failed."); e.printStackTrace(); } // IMP : setConfig will apply ONLY after scanner is enabled ScannerConfig config = scannerEMDK.getConfig(); config.decoderParams.upce0.convertToUpca = true; scannerEMDK.setConfig(config); // Starts an asynchronous Scan. The method will not turn ON the // scanner. It will, however, put the scanner in a state in which // the scanner can be turned ON either by pressing a hardware // trigger or can be turned ON automatically. scannerEMDK.read(); } else { Logger.d("EMDK BarcodeManager Null."); } } }}
public class ScanEvents { private static ScanEvents scanBarcodeEvent; private ScanListener scanBarcodeListener; public static ScanEvents getInstance() { if (scanBarcodeEvent == null) { scanBarcodeEvent = new ScanEvents(); } return scanBarcodeEvent; } public ScanEvents() { scanBarcodeEvent = this; } /** * Set scanner listener. */ public void setScanner(ScanListener barcodeListener) { scanBarcodeListener = barcodeListener; } /** * Method to receive barcode. */ public void onScanned(String data) { if (scanBarcodeListener != null) { scanBarcodeListener.onScannedValue(data); } } /** * Interface to implemented for listening for scan events. */ public interface ScanListener { void onScannedValue(String scanVal); }}
In my onCreate i initialize the scanner as follows
ScanEvents.getInstance().setScanner(MainActivity.this);new EMDKScannerClass();
0 Replies