HelloJavaPOSScale
Hello World program for a JavaPOS Scale
HelloJavaPOSScale reads the weight from a JavaPOS scale. The latest release of JavaPOS can be downloaded from the Datalogic website here.
The HelloJavaPOSScale repository contains the HelloJavaPOSScale.java source and shell scripts to run the HelloJavaPOSScale.jar you build. The repository also has a NetBeans IDE (Integrated Development Environment) project to perform the build. Other IDEs can be used.
Steps to build and run HelloJavaPOSScale.jar:
-
Install Datalogic JavaPOS. This install includes the JavaPOSTest program.
-
Make sure Datalogic JavaPOS runs with your scale. With your scale and JavaPOSTest do an Open, Claim, Enable and Read Weight. With nothing on the scale it should read 0.000. Put something on the scale. Press Read Weight again. It should read a positive number.
-
Clone or download the HelloJavaPOSScale repository.
-
Build HelloJavaPOSScale.jar. This was originally done with the following. Variations near these should work.
- Apache NetBeans 11.0
- Java jdk1.8.0_231
- The HelloJavaPOSScale project in NetBeans is a Java with Ant, Java Application project. The build uses a library of the JavaPOS's .jar files. These .jar files are in the JavaPOS install's root directory where it has its JavaPOS.jar and its SupportJars directory. Create this library via NetBeans -> Tools -> Libraries. Add the library to the HelloJavaPOSScale NetBeans project via its Properties -> Libraries -> Classpath + -> Add Library...
Another variation here builds HelloJavaPOSScale.jar without requiring the Apache NetBeans 11.0 Integrated Development Environment (IDE). It instead builds with the included script BuildHelloJavaPOSScale.cmd or BuildHelloJavaPOSScale.sh. These scripts explicitly use the Java JDK's javac and jar programs and require no intermediary IDE. Related "inside" scripts show what is inside HelloJavaPOSScale.jar and Datalogic's JavaPOS.
-
Update the jpos.xml of your installed JavaPOS to include a
<JposEntry logicalName="JavaPOSScaleDevice">
entry for your scale and interface. This entry is a copy of the entry you used with JavaPOSTest above. The only difference is the logicalName is changed to JavaPOSScaleDevice. -
With HelloJavaPOSScale.jar make your scale weigh. Use the appropriate HelloJavaPOSScale script: .cmd or .sh. With nothing on the scale it should read 0. With something on the scale it should read a positive integer.
-
The following images show successful runs at Command Prompts and Terminals.
- Windows
- Linux
-
The non-zero weight runs above do produce a logged error, "ERROR DLSUSBScale - onDataReceived: RESP_NO_WEIGHT" in jposTraceR.log files.
The reason for the error is because the HelloJavaPOSScale program is so simple that it does not first check for an empty scale with zero weight. This problem is corrected in LiveWeightExample.
To see the logged error look at the jposTraceR.log and jposTraceR-1.log, jposTraceR-2.log, ,etc. log files. Search for
ERROR
in the .log file.The path to the jposTraceR*.log files is found by looking in log4j2.xml in the installed SupportJars subdirectory. The SupportJars directory is expected to be at:
- Windows
- Linux
C:\Program Files\Datalogic\JavaPOS\SupportJars
/usr/local/Datalogic/JavaPOS/SupportJars
-
A Project Run F6 in NetBeans is also successful but it typically requires configuring the Working Directory in Project Properties -> Run.
Set the Working Directory to the JavaPOS install directory:
- Windows
- Linux
C:\Program Files\Datalogic\JavaPOS
/usr/local/Datalogic/JavaPOS
You need to configure the working directory and
java.library.path
to VM options at NetBeans -> Project Properties -> Run.