TC55 Barcode Scanner Initialization

J Jon-Luke West 2 years 11 months ago
27 2 0

I am writing an application with the TC55 as my test environment right now that integrates with the barcode scanner.  I have been using this tutorial for most of my reference material to make sure I am doing things correctly: Advanced Scanning Tutorial using Barcode API but I am still encountering an issue with the initialization of the scanner.
 
I do the following when I receive data:
 
    //region onData
    private class AsyncDataUpdate extends AsyncTask {
        @Override
        protected String doInBackground(ScanDataCollection... params) {
            try {
                if (!scanner.isReadPending()) {
                    scanner.read();
                }
                ScanDataCollection scanDataCollection = params[0];
                if (scanDataCollection != null
                        && scanDataCollection.getResult() == ScannerResults.SUCCESS) {
                    ArrayList scanDataList = scanDataCollection.getScanData();
                    ScanDataCollection.ScanData scanData = scanDataList.get(0);
                    mesUPC = scanData.getData();
                    }
            } catch (ScannerException e) {
                e.printStackTrace();
            }
            return mesUPC;
        }
 
        @Override
        protected void onPostExecute(String result) {
            if (mesUPC != null) {
                screenSlideAnimationSet.cancel();
                lookupItem();
            }
        }
    }
 
    @Override
    public void onData(ScanDataCollection scanDataCollection) {
        new AsyncDataUpdate().execute(scanDataCollection);
    }
    //endregion
 
Everything seems to work fine except for if you turn on the scanner, I am only using the hard trigger, but don't scan anything.  If you don't scan anything it seems like the scanner locks up and won't turn back on, and my debugger is telling me that the main thread is being hung up.  I have to destroy the application and open it back up for the scanner to work again.  Leaving the device for 60+ seconds in hopes that the lock up will resolve itself or time out yields nothing.  I was able to get around this, kind of, by implementing the following code:
 
//region Hard Trigger Trap
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BUTTON_L1) || (keyCode == KeyEvent.KEYCODE_BUTTON_R1)) {
            if (event.getRepeatCount() != 0) {
                return true;
            }
            try {
                if (scanner == null) {
                    initializeScanner();
                }
                if (scanner != null) {
                    scanner.read();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
 
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BUTTON_L1) || (keyCode == KeyEvent.KEYCODE_BUTTON_R1)) {
            if (event.getRepeatCount() != 0) {
                return true;
            }
            try {
                if (scanner != null) {
                    scanner.cancelRead();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
 
This is the exact code that is in the tutorial.  This provides me with a workaround, but it creates a weird interaction where the hard trigger has to be pressed twice to get the scanner to turn on.  It goes like this:
 

Application starts
Hard trigger pressed -> scanner turns on
No data scanned; hard trigger released
Hard trigger pressed -> scanner DOES NOT turn on
Hard trigger pressed -> scanner turns on
etc...

 
It's like the scanner is stalling if no data is scanned and the connection to it needs to be destroyed and reestablished.  Can someone point me in the right direction to figure out what is locking up the scanner?  Is there something obvious I am missing?
 
Thanks.

Please register or login to post a reply

2 Replies

f fen den

Ijust need this scanning tutorial using barcode API. Thank you,Jon.
It's very helpful to me.

V Vedsatx Saddvv

Jon-luke, At the end of the scanning tutorial is a link to download a working example of using the barcode scanning API. Could you download, install and test that example on your device to verify it functions as you would expect?   If it works properly, we can try to determine the differences between the example and your application.

CONTACT
Can’t find what you’re looking for?