- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
要求:在 Windows 计算机上支持多个扫描仪。
工具:
问题:第一个扫描仪已成功认领。但是,声称第二个扫描仪会导致以下异常“设备已被另一个控制设备占用”。
代码分析:
SymScannerSvc112 作为用于手持式扫描仪的服务类。
SymScannerSvc112 扩展了 SymScannerSvc。 SymScannerSvc 保存静态变量“_fClaimed”。
当第一个扫描仪被认领时,静态变量“_fClaimed”被设置为 true。现在,当您尝试认领第二个扫描仪时,以下代码会阻止它,因为“_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 扫描仪似乎都使用相同的服务对象,因此请准备其他供应商的扫描仪。
“考虑设置设备,使每个扫描仪在不同的服务对象上运行”是指,例如,当将多个扫描仪同时连接到单个 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',就会出现问题现象。
关于java - 斑马 jPOS : How to have support for multiple scanners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51488115/
我是一名优秀的程序员,十分优秀!