Home >
Barcode Scanner Support for Flex
I recently came across an interesting problem when we had to access barcode scanners from Flex applications. The scanners came in different models but all were connected to the computer via serial port or USB (Serial2USB). Now, how do you read data from serial ports from Flex? Well, you don’t. At least not directly. The main issue with accessing local hardware from Web applications is the same as for everything else. Access is generally prohibited unless specifically authorized by the user. Examples for this scenario are online virus scanners or even Windows updates.
Since Flex applications do not have the capability to access local hardware even with authorization (only Air can) we were trying to bypass Flex by creating a little Java applet that directly accesses the serial port after initial authorization and which passes the data on to JavaScript which is embedded in the index.html file in which the Flex application is embedded as well.
<body>
<script language="JavaScript" type="text/javascript">
<applet
code="com.comparatio.barcodeapi.WebClient_BarcodeApplet"
width="0"
height="0"
archive="RXTXcomm.jar,barcode.jar"
name="BarcodeAPI"
myscript="myscript">
</applet>';
//######################################################################################
// Public Functions : FLEX => JavaScript => Java Applet
// Returns the version of the BARCODE APPLET application.
function GetAPIVersion() {
return document.BarcodeAPI.getAPIVersion();
}
// Returns open COM port
function GetComPort() {
return document.BarcodeAPI.getComPort();
}
// Returns the speed of the current COM port
function GetSpeed() {
return document.BarcodeAPI.getSpeed();
}
//######################################################################################
// Public Functions : Java Applet => JavaScript => FLEX
// Sends barcodes to FLEX
function UploadBarcodes(barcodes) {
GetApplication("index").uploadBarcodeOnFlex(barcodes);
}
</script>
<noscript>
<object classid="clsid:...........">
<embed src="index.swf".......>
</embed>
</object>
</noscript>
</body>
- Embedded Java applet with 0 pixel width and height that handles the communication with the serial port
- JavaScript to access the Java applet from Flex
- JavaScript to access Flex from Java applet
- Embedded Flex application (here index.swf)
Voila, we have our interface! ActiveX controls would solve the same problem but it seemed easier in this case to use Java since there are less dependencies and the entire development process is much simpler and faster.
On a separate note it’s interesting to see how widely used serial ports still are. Most barcode scanners are now actual terminals running Windows Mobile or something similar. That opens a whole other can of worms since much more complex programming of the scanner itself and much more complex infrastructures are required. Serial ports seem to be disappearing but most point-and-shoot scanners are still based on it.
See www.comparatio.com for more info about our Flex framework in which we access barcode scanners.




Facebook Application Development
aren´t those barcode readers configurable to act as a keyboard?
There is a ton of different barcode readers out there. Some simple ones can act as keyboard replacement but in most settings, e.g. in industrial environments the scanner is not hooked up to the computer and you would scan batches to upload later. This gets also tricky if you scan multiple fields for each record, e.g. a part along with a quantity and other info.
Hello! why don't you use merapi?
thanks in advance for the answer
Daniele
I remember the day when we used to use Director for this kind of thing.
MerAPI won't work because that's for AIR. They key here was to actually access scanners from Flex apps that run in a browser.
In any industry, most especially the commodity based industries, barcode readers play an important role for their operation. You're lucky you've found out the solution using an easy way.
Francois Talens
So will you all be posting the applet for download or sale?
The applet itself is different for each scanner model because they all use different protocols. The Flex framework is free but the scanner applets are for sale depending on your scanners.
interesting! thanks for sharing this =)
for barcode needs such as software, maintenance and repair, i recommend http://www.adstiklabels.com.au