Label Reader Tutorial
This section covers a basic Java Application tutorial. The tutorial will demonstrate how to create a basic label reader application using Java and the Datalogic JavaPOS API.
Introduction
For this tutorial, we will be creating a simple console application in Java that opens, claims and enables a scanner device and provides a mechanism to see what labels were scanned with that device. This tutorial only covers a very basic aspect of development in JavaPOS, but should suffice as a starting point for any application that looks to read labels from a Datalogic scanning device.
Prerequisites
In order to develop an application for Datalogic Scanning devices, you will need to first have the supporting JAR libraries and configuration files needed for Datalogic JavaPOS present.
Support Libraries
The easiest way to integrate JavaPOS into your application is to copy the entire SupportJars folder from the installed JavaPOS location to your project. This will add a SupportJars folder to your project and will contain all of the support libraries needed for JavaPOS. You will also need to copy the JavaPOS.jar file to your project. This file can be copied to the SupportJars folder if you wish, or can be copied to your application's directory.
Configuration Files
In order for JavaPOS to operate correctly, you will need the configuration files that are installed with JavaPOS copied into your application's directory.
Application Development
The Tutorial Class
In order to respond to JPOS events, your class will need to implement the jpos.events.DataListener interface in your class. This interface is part of the OMG JPOS 1.14 library (jpos114.jar). In order to implement the listener, you will also need to import the jpos.events.DataEvent class. Add the following imports to your class:
import jpos.events.DataEvent;
import jpos.events.DataListener;
Now create your Tutorial class which implements the DataListener interface as follows:
public class Tutorial implements DataListener {
public void dataOccurred(DataEvent de) {
}
}
Note that each time data is received from the Scanner device, the dataOccurred method will be called. This method is where we will put our label processing.
The Scanner implementation
In order to program for a UPOS Scanner device, we will need to import the jpos.Scanner class. This class is the UPOS Scanner device implementation.
Add the following import to the Tutorial class:
import jpos.Scanner;
Next, we will add a member variable to the Tutorial class to hold the Scanner instance.
public class Tutorial implements DataListener {
private Scanner scanner;
Next, add a constructor for the Tutorial class that instantiates the Scanner instance as follows:
public class Tutorial implements DataListener {
private Scanner scanner;
public Tutorial() {
this.scanner = new Scanner();
}
Now the Tutorial class has a member variable named scanner that holds a generic UPOS Scanner instance.
Open -> Claim -> Enable
In order for an application to read labels using a UPOS Scanning device, the application must first open the UPOS device. The application must then claim the device. Finally, the application sends an enable command to the claimed device allowing the device to begin reading labels. Each step of this process is represented by a method within the UPOS Scanner class. Each of these methods potentially throws a JposException when they are called, so it is a good time to import jpos.JposException by adding the following to your Tutorial class imports:
import jpos.JposException;
jpos.xml Profile
The JPOS Scanner.open method takes a single argument denoting the name of the jpos.xml Profile to use. This profile must match the logicalName attribute of a JposEntry element in the jpos.xml file. For this example, I will be using the default jpos.xml that is shipped with Datalogic JavaPOS, and I will be using the DL-Gryphon-GD4430-USB-OEM profile from jpos.xml. You can find the beginning of this profile by looking in the jpos.xml file, but it is included here as well.
<JposEntry logicalName="DL-Gryphon-GD4430-USB-OEM">
<creation factoryClass="com.dls.jpos.service.DLSScannerInstanceFactory" serviceClass="com.dls.jpos.service.DLSScannerService"/>
<vendor name="DLA" url="http://www.adc.datalogic.com"/>
<jpos category="Scanner" version="1.13"/>
<product description="ScannerService" name="ScannerService" url="http://www.adc.datalogic.com"/>