This post will take you from the initial setup of your local Mac OS X development environment to getting your ID scanner (IDWedgeKB) working in serial port mode with a web form, and everything in between. Ultimately, it will provide all the instructions required to demonstrate the IDWedgeKB in serial port mode sending data to the browser, using Node.js and Express to host a server written in JavaScript.
NOTE: If you are looking for the Windows OS version of this post, please see this post.
Please watch this video to see the related Windows demo to get a solid idea of what the entire process entails, but read on to learn the key differences with Mac OS X:
(Not sure how to copy video over - david) ^^^
NOTE: If you need help in connecting and configuring your IDWedgeKB, for general serial port mode usage, please first see the guide found here as this current document serves to explain how to work with your device in conjunction with Node.js and, additionally, a web form and therefore assumes that you have already configured your device properly.
You will need:
Download the Resources:
This documents all the steps in the video above:
IDWedgeKB-Serial-Port-and-NodeJS.pdf
The inf files to install the IDWedgeKB, unzip this to a folder on your PC, you will need this during h/w installation.
The SerialServer test app, unzip this to a folder on your PC to a folder you will navigate to with the command prompt.
If you have a PC with a Windows OS available to you then please follow the above linked-to PDF guide, in conjunction with the requisite inf files folder above to first configure your IDWedgeKB — before proceeding to the Node.js portion of this guide — the video above will also walk you through the IDWedgeKB configuration.
If you would like to configure the IDWedgeKB via Mac OS X that you are currently working on and ultimately looking to work on (hence your reading this guide) then you will need to install a Windows Virtual Machine as the necessary files are only accessible via flash-drive mode. Our guide on how to accomplish this can be found here.
Confirm your IDWedgeKB config file is similar to this image before continuing.
IDwedgeKB config file
NOTE: Please only proceed AFTER having completed the above steps because although you will be able to complete a number of the below steps — once you actually start trying to test and work with your device via the provided web form/server — your device will almost undoubtedly not be configured properly to do so and issues will therefore arise.
Ensure that you close the Windows Virtual Machine once your IDWedgeKB is configured. Once closed, reconnect your IDWedgeKB. Failure to do so will cause issues later on this setup with your IDWedgeKB not being recognized.
The IDWedgeKB is a barcode scanner that reads and parses the information encoded on the 2D barcode found on U.S. Driver’s Licenses. IDWedgeKB has two modes of operation; Keyboard and Serial Port. This document describes how to use IDWedgeKB in Serial Port mode, run the provided Node.js SerialServer.js application, and send barcode data to the browser running the SerialPage.html page and corresponding web form.
Node.js is a cross-platform open source JavaScript run-time environment built on Google’s Chrome’s V8 JavaScript engine. Node.js lets you code server-side applications in JavaScript and run that on a server.
There are two main (and recommended) ways of downloading/installing Node.js
brew install node
NOTE: Only use ONE of these methods to install Node.js. Having multiple downloads of Node.js may cause issues.
Further Reading:
After installing both Node.js and NPM via one of the above means, it is now time to install the following packages to actually communicate with the IDWedgeKB and run the serial server —
NOTE: If you had Node.js and NPM installed prior to using this guide then it is recommended to run the npm list “package-name” for the specific packages named above. Otherwise it will likely be difficult to discern and verify proper installation due to the potential that you have a number of packages installed and the way they will be displayed is in a hierarchical, nested fashion.
The first module to install is the serial port, and we recommend you install this, and its corresponding packages, globally (-g) so you can use them as command line tools. There are some handy serial port commands you might be interested in as a developer, like: serialport-list.
To install the above packages run the following command for each of the above (5) listed packages:
Successful serialport package install
Successful serialport package install
NOTE: If you encounter an issue with permissions/access while installing these packages you will have to enter the following commands:
These commands will give you the access required to continue your setup.
npm install express -g
npm install http -g
npm install socket.io -g
NOTE: If permission/access issues continue to exist, execute the previous commands beginning with “sudo”.
Example Commands:
sudo npm install express -g
sudo npm install http -g
sudo npm install socket.io -g
Finally, you are ready to test out your device via the aforementioned and downloadable (hopefully already downloaded, but if not — download the SerialServer.zip folder here or above).
For this step you will be in the directory where the folder SerialServer is located.
— Make note of the destination folder once you have downloaded the SerialServer.zip file and extracted the contents; it is recommended that you move the folder to wherever is easiest to minimize navigating via Terminal.
Once again run the serialport-list command to see something similar to the following:
Note the naming convention for the USB/serial port devices, namely the IDWedgeKB (highlighted in blue)
Make note of which device you are trying to communicate with and then it is time to run the application — in this case we are using: /dev/tty/usbmodemKINETIS1
To run the app, you must navigate to the directory where you have it saved, via the cd command and then use the pwd command to confirm, like so:
Note how the prompt next to your user name has changed and you are in the Serial Server directory — you are now ready to run the app
The SerialPage.html file is served to the browser from the sub-folder called public when the browser attempts to load a page at this address: http://localhost:8080/
Run the following command as shown below to start the server and serve the web page —
This is to illustrate the following: If you do not provide a device to read data from and interface with then you will receive a “path is not defined” error as shown
However, if you do provide a device — when you press Enter — If it is not properly connected the app will exit.
Barring the above — If you run the command correctly as with this example — node serialserver.js /dev/tty.usbmodemKINETIS1 — this is what you should see:
NOTE: Please see the text highlighted in blue — this is showing that the device and app are working properly when a driver’s license is scanned — despite the warnings. See the established localhost:8080 connection
The Unhandled Promise Rejection Warning in the above screenshot will be addressed in a future update to this guide as the current approach in the code will be deprecated.
Again (as stated in the above caption) — the code and app work as constituted — a FUTURE UPDATE is forthcoming to address the above exception/warning.
Open a web browser to local host at port 8080: http://localhost:8080 and this is the basic form you will be presented with —
Blank form before card is scanned, but showing established serial port device connection
You should see, at the top-left of the page, that a port has been opened and a successful connection made with the device you specified.
Try scanning a card (no need to insert the cursor into the text area that says “scan a card to fill a form”) the result of which should appear as below —
Card is scanned — shows the raw CSV data captured in the text area, and also populates the data in the proper fields below (as it relates to the driver’s license fields/values)
You can observe the CSV string printed in the text box above, the JavaScript in the browser parses the CSV string and assigns the table below the text box with field information.
The Terminal also displays the CSV data sent by the IDWedgeKB (as seen in the below screenshot) —
The raw driver’s license data is captured as comma separated values (CSV) in tandem with the web form scan and capture
To end the demo, simply enter Ctrl+c in the command prompt.