2 Replies Latest reply on Apr 16, 2012 1:18 PM by CEDixon

    How can my AIR native extension communicate with my AS Library?

    CEDixon Level 1

      Please point me in the right direction if this isn't the right place to post this.

       

      I have a Barcode scanner hooked up via Bluetooth.  I'm using a native extension that essentially uses the BluetoothChat service from Android to communicate with this barcode reader.

       

      There is a software trigger for making a scan that I am launching from my flex code.  This goes to the native extension, the scanner scans, and a barcode is returned.  My problem is my native extension functinon has already returned at this point and I have no way of getting the barcode once it's been scanned.

       

      Here's my workflow:

       

      User presses "Scan" button in my flex app.

      This calls Scan() in the ASLib

      This calls ScanFunction() in the native extension.

      A "write()" message is sent to the barcode scanner via the bluetooth chat service, that tells the scanner to scan.  The user then points it at something and scans, this can take any amount of time, usually around 4 or 5 seconds.

      A "read()" message is fired when the barcode is scanned.

       

      My problem is as soon as I call the ScanFunction(), it returns after if kicks off the write message.  So it's returning before it gets a barcode.  I've tried waiting for it, with an iterative loop until the bScanComplete variable is set in the read function, but I think this is hogging the thread or something because NOTHING happens while this loop is going on.  The scanner won't scan at all.  If I take this loop out, the scan occurs.

       

      I've also tried waiting in flex, something like:

       

      Scan();

      setTimeout(Read, 6000);

       

      And then the Read function checks to see if a string has been set back in the native extension... Again, this seems to hog the thread and nothing happens in the native extension code or otherwise during those 6 seconds.

       

      What I'd really like to do is hook up some events between the native extension and the actionscript code, so when a barcode is scanned an event fires back in the library.  I don't know if that's even possible and if that is, I can't find a solution for it.  Any help would be greatly appreciated, I'm stumped.