3 Replies Latest reply on May 28, 2015 1:12 AM by fen den

    TC55 Barcode Scanner Initialization

    Jon-Luke West

      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<ScanDataCollection, Void, String> {

              @Override

              protected String doInBackground(ScanDataCollection... params) {

                  try {

                      if (!scanner.isReadPending()) {

                          scanner.read();

                      }

                      ScanDataCollection scanDataCollection = params[0];

                      if (scanDataCollection != null

                              && scanDataCollection.getResult() == ScannerResults.SUCCESS) {

                          ArrayList<ScanDataCollection.ScanData> 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:

       

      1. Application starts
      2. Hard trigger pressed -> scanner turns on
      3. No data scanned; hard trigger released
      4. Hard trigger pressed -> scanner DOES NOT turn on
      5. Hard trigger pressed -> scanner turns on
      6. 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.