4 Replies Latest reply on Aug 9, 2016 11:39 AM by Kanagal Raj Ramaswamy

    EMDKWrapper overrides default Datawedge profile (Profile0)

    Jacek Rys

      Hello, I want to scan Hermes barcodes within my app in which I use EMDKWrapper to allow using on non-Zebra devices.

       

      I noticed that the scanner cannot scan Hermes barcode when I initialize emdkWrapper (like this):

       

      public boolean initializeScanner() throws ScannerException {

       

         if (scanner == null) {

         // Get the Barcode Manager object
         barcodeManager = (BarcodeManager) this.emdkManager
         .getInstance(EMDKManager.FEATURE_TYPE.BARCODE);

         // Get default scanner defined on the device
         scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);

         // Add data and status listeners
         scanner.addDataListener(this);

         scanner.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.
         scanner.triggerType = Scanner.TriggerType.HARD;

         // Enable the scanner
         scanner.enable();

         // 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.
         scanner.read();

         return true;

        } else {

         return false;

        }

      }

       

      Before I initialize emdkWrapper it *beeps* when pointing to Hermes barcode so that's why I assume that EMDKWrapper causes default Datawedge profile overriding.

       

      Example of Hermes barcode:

       

       

      I'm aware that to enable scanning it I have to change Profile settings.
      I did so by following this instructions for settings to allow Datawedge to scan Hermes Barcodes*
      •    Launch Datawedge

      •    Tap Profile 0

      •    Tap Decoders

      •    Enable “Interleaved 2 of 5

      •    Tap Back

      •    Tap Decoder Params

      •    Tap Interleaved 2 of 5

      •    Set Length 1 = 16

      •    Set Length 2 = 16

       

      The problem is that something related to my EMDK implementation overrides the default Profile settings.

      I tried to force change Datawedge profile according to this link: Data Capture Intent API Reference - Zebra Technologies Techdocs

      but with no success.

      Could you please help me so that my emdkWrapper will use default profile for scanning?

        • Re: EMDKWrapper overrides default Datawedge profile (Profile0)
          Bill Hecox

          Hello Jacek,

               It seems you are trying to mix usage of the EMDK Barcode API's, EMDK Profile Data Capture Features, and Datawedge.  Each of these development options are meant to be used individually.  When using the Barcode API's, you will need to set the scanner options via the scanners's ScannerConfig object. Please see the Barcode API sample app for details.

           

          Barcode APIs - Zebra Technologies Techdocs

          • Re: EMDKWrapper overrides default Datawedge profile (Profile0)
            Jacek Rys

            Hello Bill,

             

            I checked barcode sample and it works in this sample project.

             

            However I got this error when attempting to set scanner config.

             

            07-26 13:06:31.591 11557-11557/? D/com.symbol.emdk.EMDKServiceConnection: The EMDK Service is now connected!

            07-26 13:06:31.591 11557-11557/? V/EMDKWrapper: onOpened:

            07-26 13:06:31.591 11557-11557/? V/EMDKWrapper: initializeScanner: scanner: null

            07-26 13:06:31.591 3973-3984/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfig: start - getCurrentParameters

            07-26 13:06:31.591 3973-3984/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfig: end - getCurrentParameters

            07-26 13:06:31.612 3973-5785/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - getScanStatus

            07-26 13:06:31.612 3973-5785/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - getScanStatus

            07-26 13:06:31.612 3973-5785/? D/EmdkService: Caught exception : Already scanning. Wait for current scanning to complete.

            07-26 13:06:31.612 11557-11557/? D/EMDKWrapper: Scanner init error message: Already scanning. Wait for current scanning to complete.

            07-26 13:06:31.612 11557-11557/? D/EMDKWrapper: Scanner init error localized message: Already scanning. Wait for current scanning to complete.

            07-26 13:06:31.612 11557-11557/? D/EMDKWrapper: Scanner init error: com.symbol.emdk.barcode.ScannerException: Already scanning. Wait for current scanning to complete.

            07-26 13:06:31.612 11557-11557/? W/System.err: com.symbol.emdk.barcode.ScannerException: Already scanning. Wait for current scanning to complete.

            07-26 13:06:31.612 11557-11557/? W/System.err:     at com.symbol.emdk.barcode.Scanner.setConfig(Scanner.java:302)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at com.doddle.concession.EMDK.EMDKWrapper.initializeScanner(EMDKWrapper.java:122)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at com.doddle.concession.EMDK.EMDKWrapper.onOpened(EMDKWrapper.java:146)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at com.symbol.emdk.EMDKServiceConnection.notifyonConnected(EMDKServiceConnection.java:112)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at com.symbol.emdk.EMDKServiceConnection.onServiceConnected(EMDKServiceConnection.java:92)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)

            07-26 13:06:31.612 11557-11557/? W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at android.os.Looper.loop(Looper.java:136)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5002)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

            07-26 13:06:31.622 11557-11557/? W/System.err:     at dalvik.system.NativeStart.main(Native Method)

             

            It doesn't crash the app but doesn't allow to set config properly.

             

            Any idea why?

              • Re: EMDKWrapper overrides default Datawedge profile (Profile0)
                Jacek Rys

                Hello Bill,

                 

                I transposed Sample Barcod Project to my project and I'm getting such warning-error when I want to do scanner.enable():

                 

                07-27 23:24:41.002 29164-11660/? W/System.err: com.symbol.scanning.Scanner$ScannerExceptions

                07-27 23:24:41.002 29164-11660/? W/System.err:     at com.symbol.scanning.imager.ImagerScanner.enable(ImagerScanner.java:283)

                07-27 23:24:41.002 29164-11660/? W/System.err:     at com.symbol.emdk.emdkservice.barcode.SvcScanner$2.run(SvcScanner.java:349)

                07-27 23:24:41.002 29164-11660/? W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)

                07-27 23:24:41.002 29164-11660/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)

                07-27 23:24:41.002 29164-11660/? W/System.err:     at android.os.Looper.loop(Looper.java:136)

                07-27 23:24:41.002 29164-11660/? W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)

                 

                Later, when I want to perform scanner.read() I'm getting this warning-error:

                 

                740-11740/? W/System.err:     at com.symbol.emdk.barcode.Scanner.read(Scanner.java:531)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at com.doddle.concession.EMDK.EMDKWrapper.startScan(EMDKWrapper.java:317)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at com.doddle.concession.EMDK.EMDKWrapper.onResumeWrapped(EMDKWrapper.java:300)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at com.doddle.concession.EMDK.EMDKWrapper.onOpened(EMDKWrapper.java:127)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at com.symbol.emdk.EMDKServiceConnection.notifyonConnected(EMDKServiceConnection.java:112)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at com.symbol.emdk.EMDKServiceConnection.onServiceConnected(EMDKServiceConnection.java:92)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)

                07-27 23:24:41.012 11740-11740/? W/System.err:     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)

                 

                Do you have any idea why I'm getting info that "The scanner device is not enabled"?

                 

                This is my EMDKWrapper class, please take a look on it:

                 

                 

                 

                import android.app.Activity;

                import android.content.Context;

                import android.os.AsyncTask;

                import android.support.design.widget.Snackbar;

                import android.util.Log;

                import android.widget.Toast;

                 

                 

                import com.doddle.concession.BuildConfig;

                import com.doddle.concession.reporting.logs.LogManager;

                import com.symbol.emdk.EMDKManager;

                import com.symbol.emdk.EMDKManager.EMDKListener;

                import com.symbol.emdk.EMDKResults;

                import com.symbol.emdk.barcode.BarcodeManager;

                import com.symbol.emdk.barcode.ScanDataCollection;

                import com.symbol.emdk.barcode.Scanner;

                import com.symbol.emdk.barcode.Scanner.DataListener;

                import com.symbol.emdk.barcode.Scanner.StatusListener;

                import com.symbol.emdk.barcode.ScannerConfig;

                import com.symbol.emdk.barcode.ScannerException;

                import com.symbol.emdk.barcode.ScannerInfo;

                import com.symbol.emdk.barcode.ScannerResults;

                import com.symbol.emdk.barcode.StatusData;

                 

                 

                import java.util.ArrayList;

                 

                 

                /**

                * Created by jrys on 5/23/2016.

                */

                public class EMDKWrapper implements EMDKListener, StatusListener, DataListener, BarcodeManager.ScannerConnectionListener {

                 

                 

                    private static final String TAG = EMDKWrapper.class.getSimpleName() ;

                    // 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 scanner = null;

                 

                 

                    private Context context;

                 

                 

                    private Activity activity;

                 

                 

                    private RealScanLifecycleListener mScanningCallback;

                 

                 

                    private int CURRENT_PROCESS = RealScanCurrentProcess.UNDEFINED_PROCESS;

                 

                 

                    private boolean bContinuousMode = false;

                 

                 

                 

                 

                    public EMDKWrapper(Context context, Activity activity) {

                        if (BuildConfig.DEBUG) {

                            Log.v(TAG, "EMDKWrapper: create();");

                        }

                 

                 

                        this.context = context;

                        this.activity = activity;

                    }

                 

                 

                    //RealScanning

                    public void setCurrentProcess(int currentProcess) {

                        this.CURRENT_PROCESS = currentProcess;

                    }

                 

                 

                    public void addRealScanCompletedListener(RealScanLifecycleListener callback) {

                        if (mScanningCallback == null) {

                            this.mScanningCallback = callback;

                        }

                    }

                 

                 

                    public void removeRealScanCompletedListener() {

                        if (mScanningCallback != null) {

                            this.mScanningCallback = null;

                        }

                    }

                 

                 

                    //Listeners

                    @Override

                    public void onOpened(EMDKManager emdkManager) {

                 

                        this.emdkManager = emdkManager;

                 

                        onResumeWrapped();

                 

                    }

                 

                 

                    @Override

                    public void onClosed() {

                 

                        if (this.emdkManager != null) {

                 

                            if (barcodeManager != null){

                                barcodeManager.removeConnectionListener(this);

                                barcodeManager = null;

                            }

                 

                            this.emdkManager.release();

                            this.emdkManager = null;

                        }

                    }

                 

                 

                    @Override

                    public void onStatus(StatusData statusData) {

                     

                        String statusStr = "";

                        StatusData.ScannerStates state = statusData.getState();

                  

                        switch (state) {

                 

                            case IDLE:

                                LogManager.logMessage(TAG + "Scanner is Idle");

                 

                                if (bContinuousMode) {

                                    try {

                                        // An attempt to use the scanner continuously and rapidly (with a delay < 100 ms between scans)

                                        // may cause the scanner to pause momentarily before resuming the scanning.

                                        // Hence add some delay (>= 100ms) before submitting the next read.

                                        try {

                                            Thread.sleep(100);

                                        } catch (InterruptedException e) {

                                            e.printStackTrace();

                                        }

                 

                 

                                        scanner.read();

                                    } catch (ScannerException e) {

                                        Log.d(TAG, "Status: " + e.getMessage());

                                        e.printStackTrace();

                                    }

                                }

                 

                 

                                break;

                  

                            case SCANNING:

                       

                                if (mScanningCallback != null) {

                                    mScanningCallback.onRealScanStarted();

                                }

                                break;

                 

                            case WAITING:

                             if (mScanningCallback != null) {

                                    mScanningCallback.hideGreenBoarderNow();

                                }

                                break;

                 

                            default:

                                break;

                        }

                    }

                 

                 

                    @Override

                    public void onData(ScanDataCollection scanDataCollection) {

                           new AsyncDataUpdated().execute(scanDataCollection);

                    }

                 

                 

                    public void onCreateWrapped(){

                    

                        EMDKResults results = EMDKManager.getEMDKManager(context, this);

                        if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) {

                            Snackbar.make((activity).getWindow().getDecorView().findViewById(android.R.id.content), "Status: " + "EMDKManager object request failed!", Snackbar.LENGTH_SHORT).show();

                        }

                    }

                 

                 

                    public void onResumeWrapped(){

                   

                        if (emdkManager != null) {

                            barcodeManager = (BarcodeManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.BARCODE);

                       

                            if (barcodeManager != null) {

                                barcodeManager.addConnectionListener(this);

                            }

                 

                            initScanner();

                            setTrigger();

                            setDecoders();

                            startScan();

                        }

                    }

                 

                 

                    private void startScan() {

                        if(scanner == null) {

                            initScanner();

                        }

                      

                        if (scanner != null) {

                            try {

                              

                                scanner.read();

                 

                                bContinuousMode = true;

                             

                            } catch (ScannerException e) {

                                Log.d(TAG, "Status: " + e.getMessage());

                                e.printStackTrace();

                            }

                        }

                 

                    }

                 

                 

                    private void stopScan() {

                           if (scanner != null) {

                            try {

                           

                                bContinuousMode = false;

                            

                                scanner.cancelRead();

                         

                            } catch (ScannerException e) {

                                Log.d(TAG,"Status: " + e.getMessage());

                                e.printStackTrace();

                            }

                        }

                    }

                 

                 

                 

                 

                    private void setDecoders() {

                    

                        if (scanner == null) {

                            initScanner();

                        }

                 

                        if (scanner != null) {

                            try {

                 

                                ScannerConfig config = scanner.getConfig();

                                config.decoderParams.i2of5.enabled=true;

                                config.decoderParams.i2of5.length1 = 1;

                                config.decoderParams.i2of5.length2 = 40;

                 

                 

                                config.decoderParams.ean8.enabled = true;

                                config.decoderParams.ean13.enabled = true;

                                config.decoderParams.code39.enabled = true;

                                config.decoderParams.code128.enabled = true;

                 

                 

                config.decoderParams.code39.enabled = true;

                config.decoderParams.code39.length1 = 1;

                config.decoderParams.code39.length2 = 40;

                 

                 

                                scanner.setConfig(config);

                 

                            } catch (ScannerException e) {

                                Log.d(TAG, "Status: " + e.getMessage());

                                e.printStackTrace();

                            }

                        }

                    }

                 

                 

                    private void setTrigger() {

                 

                        if (scanner == null) {

                            initScanner();

                        }

                 

                        if (scanner != null) {

                            scanner.triggerType = Scanner.TriggerType.HARD;

                        }

                    }

                 

                 

                    private void initScanner() {

                        if (scanner == null) {

                            scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);

                 

                            if (scanner != null) {

                 

                                scanner.addDataListener(this);

                                scanner.addStatusListener(this);

                 

                 

                                try {

                                    scanner.enable();

                     

                                } catch (ScannerException e) {

                                    Log.d(TAG, "Status: " + e.getMessage());

                                    e.printStackTrace();

                                }

                            }else{

                                Log.d(TAG, "Status: " + "Failed to initialize the scanner device.");

                            }

                        }

                    }

                 

                 

                    public void onDestroyWrapped() {

                 

                        deInitializeScanner();

                 

                        if (barcodeManager != null) {

                            barcodeManager.removeConnectionListener(this);

                            barcodeManager = null;

                 

                        }

                 

                        if (emdkManager != null) {

                            emdkManager.release();

                            emdkManager = null;

                        }

                 

                    }

                 

                 

                 

                    public void onPauseWrapped() {

                 

                        stopScan();

                        deInitializeScanner();

                        if(barcodeManager != null){

                            barcodeManager.removeConnectionListener(this);

                            barcodeManager = null;

                        }

                 

                 

                        if (emdkManager != null) {

                            emdkManager.release(EMDKManager.FEATURE_TYPE.BARCODE);

                        }

                 

                 

                    }

                 

                 

                    public void deInitializeScanner() {

                 

                        if (scanner != null) {

                            try {

                                scanner.cancelRead();

                      

                                scanner.disable();

                             

                            } catch (ScannerException e) {

                                Log.d(TAG, "Status: " + e.getMessage());

                                e.printStackTrace();

                            }

                            scanner.removeDataListener(this);

                            scanner.removeStatusListener(this);

                 

                 

                            try{

                                scanner.release();

                 

                            } catch (ScannerException e) {

                 

                                Log.d(TAG, "Status: " + e.getMessage());

                                e.printStackTrace();

                            }

                 

                            scanner = null;

                            Log.d(TAG, "deInitializeScanner() scanner=null set");

                        }

                    }

                 

                 

                    @Override

                    public void onConnectionChange(ScannerInfo scannerInfo, BarcodeManager.ConnectionState connectionState) {

                  

                        switch(connectionState) {

                            case CONNECTED:

                 

                 

                                initScanner();

                                setTrigger();

                                setDecoders();

                                startScan();

                                break;

                            case DISCONNECTED:

                                deInitializeScanner();

                                break;

                        }

                    }

                 

                 

                    public interface IWrapperKeeper {

                        EMDKWrapper getEMDKWrapper();

                 

                        void setEMDKWrapper(EMDKWrapper wrapper);

                 

                        void addRealScanCompletedListener(RealScanLifecycleListener callback);

                 

                        void removeRealScanCompletedListener();

                    }

                 

                 

                    private class AsyncDataUpdated extends AsyncTask<ScanDataCollection, Void, String> {

                 

                 

                        @Override

                        protected String doInBackground(ScanDataCollection... params) {

                      

                            String dataString = "";

                            ScanDataCollection datas = params[0];

                            if ((datas != null) && (datas.getResult() == ScannerResults.SUCCESS)) {

                                ArrayList<ScanDataCollection.ScanData> scanData = datas.getScanData();

                                for (ScanDataCollection.ScanData data : scanData) {

                                    dataString = data.getData();

                                }

                            }

                 

                 

                            return dataString;

                        }

                 

                 

                        @Override

                        protected void onPostExecute(String result) {

                 

                 

                            if (result.trim().isEmpty() || result.trim() == null) {

                                Toast.makeText(context, "No data. Please scan again", Toast.LENGTH_SHORT).show();

                            } else {

                                switch (CURRENT_PROCESS) {

                 

                 

                                    case RealScanCurrentProcess.CHECKIN_PROCESS:

                                        onRealScanCompleted(result);

                                        break;

                                    case RealScanCurrentProcess.STORAGE_PROCESS:

                                        onRealScanCompleted(result);

                                        break;

                                    case RealScanCurrentProcess.COLLECTION_PROCESS:

                                        onRealScanCompleted(result);

                                        break;

                                    case RealScanCurrentProcess.RETURNS_PROCESS:

                                        onRealScanCompleted(result);

                                        break;

                                    case RealScanCurrentProcess.UNDEFINED_PROCESS:

                                        Snackbar.make((activity).getWindow().getDecorView().findViewById(android.R.id.content), "SCAN UNEXPECTED", Snackbar.LENGTH_SHORT).show();

                                        break;

                                }

                 

                 

                 

                 

                            }

                        }

                 

                 

                    }

                 

                 

                    private void onRealScanCompleted(String result) {

                        if(mScanningCallback != null){

                            mScanningCallback.onRealScanCompleted(result);

                        }else{

                            Log.d(TAG, "Scan callback is missing");

                            LogManager.logMessage(TAG + "Scan callback is missing");

                        }

                    }

                 

                 

                    public boolean isScannerInitialized() {

                        return scanner != null;

                    }

                 

                 

                }

                  • Re: EMDKWrapper overrides default Datawedge profile (Profile0)
                    Kanagal Raj Ramaswamy

                    Please can you answer the below:

                    1. Which device you are using? What is the Build Number (Settings > About > Build Number)

                    2. What version of EMDK installed on the device? (Settings > Apps > All > EMDKService)

                    3. Which scanner device is used for scanning? is it internal imager or  internal camera or bluetooth scanners ?

                    3. Do you see enable problem with the BarcodeSample1 distributed without any change?

                             Barcode APIs - Zebra Technologies Online Documentation

                    4. If the BarcodeSample1 works, then try your barcode setting the corresponding config in the sample code.

                     

                    Also before calling the read, below is recommended:

                    1. Wait IDLE state first and this ensure that the scanner is enabled.

                    2. Also before calling the scanner.read, check for scanner is enabled and no read is pending as shown below.

                            if (scanner.isEnabled() && !scanner.isReadPending()) {  

                                    scanner.read();

                              }