【发布时间】:2018-07-23 22:42:18
【问题描述】:
要求:在 windows 机器上支持多个扫描仪。
工具:
- Zebra SDK 扫描器
- Zebra 手持式扫描仪,即 DS2208
- JPOS
- Spring Boot 应用程序
问题:第一个扫描仪被成功认领。但是,声称第二个扫描仪会导致以下异常 “设备已被另一个控制设备占用”。
代码分析:
SymScannerSvc112 作为用于手持式扫描仪的服务类。
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>
【问题讨论】:
-
信息不足,无法提问。请列举所有正确使用的扫描仪(包括连接方式(COM/USB)),而不是举例。还要编写所有扫描仪的源代码,包括设备名称和对象变量名称,以及创建 ControlObject 和打开设备的部分。还请描述正在运行的进程和线程的单元。
标签: java barcode-scanner javapos