Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently had to implement a scanner system to interact with java.</p> <p>I used <strong>Honeywell Voyager MS9540</strong> USB barcode scanner.</p> <p>As a default the scanner sent the data straight as keyboard input - no driver required.</p> <p><em>But</em> it was very easy to get this model to interact <strong>directly</strong> with java rather than using a keyboard hook (to use the barcodes as variables in java, as you mentioned). </p> <p>This model has a setting to emulate a serial port, you can then read the scanned data using the javax.comm package. For me, this was <em>much</em> better than a keyboard hook to get the barcode data because the program does not need the focus before being able to interpret a scan (I would not want to create a global keyboard hook).</p> <p>My java program reads all input from the specified serial port and writes the barcode to a database. I also setup the program to pass any unrecognized barcode scans to the keyboard (any barcode that my app did not create - I used a distinct signature on my barcodes) this was so it would work as a regular barcode scanner for any other apps that might read barcodes from the keyboard.</p> <p>You could probably read data directly from any USB scanner (without the serial port emulation that this model has) by doing some intensive JNDI coding but I wasn't prepared to take the time to work out the native code.</p> <p>To configure this particular model for serial port emulation all you do is scan a specific barcode in <a href="http://www.honeywellaidc.com/CatalogDocuments/00-02544%20Rev%20K%202-11.pdf"><strong>this</strong></a> document with the scanner you want to configure. It is the barcode titled "Serial Emulation Mode".</p> <p>This scanner <strong>does</strong> require a driver for serial port emulation. I found the implementation instructions and the needed drivers <a href="http://www.honeywellaidc.com/en-us/pages/Product.aspx?category=Laser&amp;cat=HSM&amp;pid=9520/40"><strong>here</strong></a> (under the "software" tab). Download the package titled: "Honeywell Scanning and Mobility (HSM) USB Serial Driver". The PDF titled "HSM USB Serial Driver Getting Started Guide" had the instructions.</p> <p>If you are not familiar with the javax.comm API. Please read the intro in <a href="http://edn.embarcadero.com/article/31915"><strong>this</strong></a> example by Rick Proctor - it tells you where to get the jar and where to put the files (javax.comm does not come standard with most java packages).</p> <p>I'm sure there are other scanner models around that have serial port emulation (I don't work for Honeywell).</p> <p>Here's a somewhat stripped down version of my barcode reader class:</p> <pre><code>package scanhandler; import java.awt.AWTException; import java.awt.Robot; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.util.Enumeration; import java.util.Properties; import java.util.TooManyListenersException; import javax.comm.CommPortIdentifier; import javax.comm.PortInUseException; import javax.comm.SerialPort; import javax.comm.SerialPortEvent; import javax.comm.SerialPortEventListener; import javax.comm.UnsupportedCommOperationException; public class ScanHandler implements Runnable, SerialPortEventListener { private static CommPortIdentifier myCommPortIdentifier; private static Enumeration portList; private static String TimeStamp; private static String driverClass; private static String connectionString; private static String comPort; private Connection myConnection; private InputStream myInputStream; private Robot myRobot; private SerialPort mySerialPort; private Thread myThread; public ScanHandler() { // open serial port try { TimeStamp = new java.util.Date().toString(); mySerialPort = (SerialPort) myCommPortIdentifier.open("ComControl", 2000); //System.out.println(TimeStamp + ": " + myCommPortIdentifier.getName() + " opened for scanner input"); } catch (PortInUseException e) { e.printStackTrace(); } // get serial input stream try { myInputStream = mySerialPort.getInputStream(); } catch (IOException e) { e.printStackTrace(); } // add an event listener on the port try { mySerialPort.addEventListener(this); } catch (TooManyListenersException e) { e.printStackTrace(); } mySerialPort.notifyOnDataAvailable(true); // set up the serial port properties try { mySerialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); mySerialPort.setDTR(false); mySerialPort.setRTS(false); } catch (UnsupportedCommOperationException e) { e.printStackTrace(); } // make a robot to pass keyboard data try { myRobot = new Robot(); } catch (AWTException e) { e.printStackTrace(); } // create the thread myThread = new Thread(this); myThread.start(); } public void run() { try { Thread.sleep(100); } catch (InterruptedException e) {} } // on scan public void serialEvent(SerialPortEvent event) { if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) { StringBuilder myStringBuilder = new StringBuilder(); int c; try { // append the scanned data onto a string builder while ((c = myInputStream.read()) != 10){ if (c != 13) myStringBuilder.append((char) c); } // send to keyboard buffer if it the barcode doesn't start with '5' if (myStringBuilder.charAt(0) != '5') { for (int i = 0; i &lt; myStringBuilder.length(); i++) { myRobot.keyPress((int) myStringBuilder.charAt(i)); myRobot.keyRelease((int) myStringBuilder.charAt(i)); } // here's the scanned barcode as a variable! } else { TimeStamp = new java.util.Date().toString(); System.out.println(TimeStamp + ": scanned input received:" + myStringBuilder.toString()); } // close the input stream myInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { // read ScanHandler properties Properties myProperties = new Properties(); try { myProperties.load(new FileInputStream("config.properties")); comPort = myProperties.getProperty("ScanHandler.comPort"); } catch (IOException e) { e.printStackTrace(); } try { // get our pre-defined COM port myCommPortIdentifier = CommPortIdentifier.getPortIdentifier(comPort); ScanHandler reader = new ScanHandler(); } catch (Exception e) { TimeStamp = new java.util.Date().toString(); System.out.println(TimeStamp + ": " + comPort + " " + myCommPortIdentifier); System.out.println(TimeStamp + ": msg1 - " + e); } }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload