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:
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.
You probably need to start a thread on the Java side to handle the scanning, then trigger an event in AS3 using the dispatchStatusEventAsync method. Make sure your AS3 class descends from EventDispatcher, otherwise you won't be able to relay any events.
See "Dispatching status events" in http://www.adobe.com/devnet/air/articles/developing-native-extensions-air.html.
Thank you! That worked great. I don't know how I missed it in that article.