Zebra jPOS:如何支持多个扫描仪
Zebra jPOS: How to have support for multiple scanners
要求:要在 windows 机器上支持多个扫描仪。
工具:
- Zebra SDK 扫描器
- Zebra 手持式扫描器,即 DS2208
- JPOS
- Spring 启动应用程序
问题:第一个扫描仪被成功认领。但是,声称第二个扫描仪导致以下异常
"Device is already claimed by another control device".
代码分析:
SymScannerSvc112 作为服务 class 用于手持式扫描仪。
SymScannerSvc112 扩展了 SymScannerSvc。 SymScannerSvc 持有一个静态变量“_fClaimed”。
当第一个扫描仪被认领时,静态变量“_fClaimed”被设置为真。现在,当您尝试声明第二台扫描仪时,以下代码会阻止它,因为“_fClaimed”设置为 true。
代码:SymScannerSvc.java:
this._alreadyClaimed = false;
if(_fClaimed) {
this._alreadyClaimed = true;
this.release();
}
注意:
1. 扫描仪连接到 USB 端口。
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>
我认为它可能已经清楚了。
评论里写的追加说明要求是不需要的
这是因为服务对象的原始设计不正确。
未创建服务对象,因此一个应用程序可以同时使用同一供应商的多个扫描仪。
可能由于Java语言的特性,厂商构建了问题,试图轻松实现难以实现的排除控制。
如果您想同时使用多个扫描仪,请考虑设备配置,以便每个扫描仪使用不同的服务对象。
就jpos.xml而言,所有 Zebra 扫描仪似乎都使用相同的服务对象,因此请准备其他供应商的扫描仪。
另外:
"consider setting the device so that each scanner operates on a different service object"表示,例如,当多个扫描仪同时连接到一个POS机时,Zebra DS2208作为第一台设备,Honeywell Genesis 7580g作为第二台设备,Denso-Wave QK30作为第三个设备,请勿连接一个供应商的多个扫描仪。
原因是jpos.xml中每个设备条目的后面部分指定了要操作的服务对象,但即使是另一个扫描器(例如"ZebraScannerSerial"和"ZebraScannerUSB") ,这个内容如果相同,则认为是同一个服务对象工作。
<creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
并且如果认为同一个Zebra服务对象共享变量'_fClaimed',就会出现问题现象。
JPOS 逻辑名称“ZebraAllScanners”允许不同 USB 端口上的扫描仪将条码传输到 spring 启动应用程序的单个实例。
<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>
要求:要在 windows 机器上支持多个扫描仪。
工具:
- Zebra SDK 扫描器
- Zebra 手持式扫描器,即 DS2208
- JPOS
- Spring 启动应用程序
问题:第一个扫描仪被成功认领。但是,声称第二个扫描仪导致以下异常 "Device is already claimed by another control device".
代码分析:
SymScannerSvc112 作为服务 class 用于手持式扫描仪。
SymScannerSvc112 扩展了 SymScannerSvc。 SymScannerSvc 持有一个静态变量“_fClaimed”。
当第一个扫描仪被认领时,静态变量“_fClaimed”被设置为真。现在,当您尝试声明第二台扫描仪时,以下代码会阻止它,因为“_fClaimed”设置为 true。
代码:SymScannerSvc.java:
this._alreadyClaimed = false;
if(_fClaimed) {
this._alreadyClaimed = true;
this.release();
}
注意: 1. 扫描仪连接到 USB 端口。
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>
我认为它可能已经清楚了。 评论里写的追加说明要求是不需要的
这是因为服务对象的原始设计不正确。 未创建服务对象,因此一个应用程序可以同时使用同一供应商的多个扫描仪。
可能由于Java语言的特性,厂商构建了问题,试图轻松实现难以实现的排除控制。
如果您想同时使用多个扫描仪,请考虑设备配置,以便每个扫描仪使用不同的服务对象。
就jpos.xml而言,所有 Zebra 扫描仪似乎都使用相同的服务对象,因此请准备其他供应商的扫描仪。
另外:
"consider setting the device so that each scanner operates on a different service object"表示,例如,当多个扫描仪同时连接到一个POS机时,Zebra DS2208作为第一台设备,Honeywell Genesis 7580g作为第二台设备,Denso-Wave QK30作为第三个设备,请勿连接一个供应商的多个扫描仪。
原因是jpos.xml中每个设备条目的后面部分指定了要操作的服务对象,但即使是另一个扫描器(例如"ZebraScannerSerial"和"ZebraScannerUSB") ,这个内容如果相同,则认为是同一个服务对象工作。
<creation factoryClass="com.motorola.jpos.service.scanner.SymScannerSvc112Factory" serviceClass="com.motorola.jpos.service.scanner.SymScannerSvc112"/>
并且如果认为同一个Zebra服务对象共享变量'_fClaimed',就会出现问题现象。
JPOS 逻辑名称“ZebraAllScanners”允许不同 USB 端口上的扫描仪将条码传输到 spring 启动应用程序的单个实例。
<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>