Search code examples
javabarcode-scannerjavapos

Zebra jPOS: How to have support for multiple scanners


Requirement: To support multiple scanners on the windows machine.

Tools:

  • Zebra SDK scanner
  • Zebra handheld scanner i.e DS2208
  • JPOS
  • Spring Boot application

Issue: The First scanner is claimed successfully. However, claim the second scanner leads to following exception "Device is already claimed by another control device".

Code Analysis:

  • SymScannerSvc112 as the service class being used for Handheld scanner.

  • SymScannerSvc112 extends SymScannerSvc. SymScannerSvc holds a static variable "_fClaimed".

  • When the first scanner is claimed, the static variable '_fClaimed' is set to true. Now, when you try to claim the second scanner, following code obstructs it as the '_fClaimed' is set as true.

Code: SymScannerSvc.java:

this._alreadyClaimed = false;
            if(_fClaimed) {
                this._alreadyClaimed = true;
                this.release();
            }

Note: 1. Scanners are attached to USB ports.

jpos.xml

<?xml version="1.0" encoding="UTF-8"?>
<JposEntries>

<JposEntry logicalName="ZebraScannerSerial">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra Serial" name="Zebra Serial Scanner on COM1" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Scanner configuration-->
    <!--Comm port device name-->
    <prop name="port" value="COM1"/>
    <!--Baud rate, default=9600, valid values are: 9600, 19200, 38400, 57600, 115200-->
    <prop name="baud" value="9600"/>
    <!--Data bits, default=7, valid values are: 5, 6, 7, 8-->
    <prop name="databits" value="8"/>
    <!--Stop bits, default=1, valid values are: 1=1 stop bit, 2=2 stop bits, 3=1.5 stop bits-->
    <prop name="stopbits" value="1"/>
    <!--Parity, default='O' (Odd), valid values are: 'N'one, 'O'dd, 'E'ven, 'M'ark, 'S'pace-->
    <prop name="parity" value="O"/>
    <!--Port mode, default='B', valid values are: 'B'=Nixdorf-B-->
    <prop name="mode" value="B"/>
    <!--UPC-A Length, default=13, indicates the number of digits generated by the scanner-->
    <!--for UPC-A labels based on the scanner's preamble and check digit settings.-->
    <!--The scanner service uses this value to determine when supplementals are present.-->
    <!--The default value of 13 assumes preamble is set to system character-->
    <!--and country code and that transmit check digit is enabled-->
    <prop name="UPCALength" value="13"/>
    <!--UPC-E Length, default=7, indicates the number of digits generated by the scanner-->
    <!--for UPC-E labels based on the scanner's preamble and check digit settings.-->
    <!--The scanner service uses this value to determine when supplementals are present.-->
    <!--The default value of 7 assumes preamble is set to system character-->
    <!--only and that transmit check digit is disabled-->
    <prop name="UPCELength" value="7"/>

    <!--Scanner type, default=0, valid values are: 7 - NixdofrUSB-->
    <prop name="ScannerType" value="7"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>

<JposEntry logicalName="ZebraScannerUSB">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra USB" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="USB"/>
    <!--Scanner type, default=0, valid values are: 6 - IBM HID-->
    <prop name="ScannerType" value="6"/>
    <prop name="ExclusiveClaimLevel" value="1" />
</JposEntry>

<JposEntry logicalName="IBM HANDHELD">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra USB" name="Zebra Scanner" url="https://www.zebra.com" />

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="USB"/>
    <!--Scanner type, default=0, valid values are: 6 - IBM HID-->
    <prop name="ScannerType" value="6"/>
    <prop name="ExclusiveClaimLevel" value="1" />
</JposEntry>

<JposEntry logicalName="ZebraUSBTableTop">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="USBIBMTT"/>
    <!--Scanner type, default=0, valid values are: 18944=TableTop(0x4A00)-->
    <!--prop name="ScannerType" value="18944"-->
    <prop name="ScannerType" value="9"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>

<JposEntry logicalName="ZebraUSBHandHeld">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="USBIBMHID"/>
    <!--Scanner type, default=0, valid values are: 19200=HandHeld(0x4B00)-->
    <prop name="ScannerType" value="19200"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>

<JposEntry logicalName="ZebraUSBOPOS">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="USBOPOS"/>
    <!--Scanner type, default=0, valid values are: 13 -->
    <prop name="ScannerType" value="13"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>

<JposEntry logicalName="ZebraScannerSNAPI">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra SNAPI Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Other non JavaPOS required properties-->
    <!--Comm port device name, must be 'USB' for USB scanner-->
    <prop name="port" value="SNAPI"/>
    <!--Scanner type, default=0, valid values are: 2 - SNAPI-->
    <prop name="ScannerType" value="2"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>


<JposEntry logicalName="ZebraAllScanners">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra Serial/USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Scanner type, default=0, valid values are: 1- ALL Scanners-->
    <prop name="ScannerType" value="1"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>

<JposEntry logicalName="IBM HANDHELD">
    <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos category="Scanner" version="1.12"/>
    <product description="Zebra Serial/USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>

    <!--Scanner type, default=0, valid values are: 1- ALL Scanners-->
    <prop name="ScannerType" value="1"/>
    <prop name="ExclusiveClaimLevel" value="0" />
</JposEntry>


<JposEntry logicalName="ZebraScale">
    <creation factoryClass="com.motorola.jpos.service.SvcServiceInstanceFactoryImpl" serviceClass="com.motorola.jpos.service.scale.ScaleService113Impl"/>
    <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
    <jpos   category="Scale" version="1.13"/>
    <product description="Zebra Scale" name="Zebra Scale" url="https://www.zebra.com"/>     
    <prop name="ErrorOnSameWeight" value="1"/>
</JposEntry>


Solution

  • The JPOS logical name ‘ZebraAllScanners’ allows scanners on different USB ports to transmit barcodes to a single instance of the spring boot app.

                <JposEntry logicalName="ZebraAllScanners">
                                <creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
                                <vendor name="Zebra Technologies" url="https://www.zebra.com"/>
                                <jpos category="Scanner" version="1.12"/>
                                <product description="Zebra Serial/USB Scanner" name="Zebra Scanner" url="https://www.zebra.com"/>
    
                                <!--Scanner type, default=0, valid values are: 1- ALL Scanners-->
                                <prop name="ScannerType" value="1"/>
                                <prop name="ExclusiveClaimLevel" value="0" />
                </JposEntry>