为什么霍尼韦尔POS4NET为两个不同的扫描仪发射相同的事件?

时间:2018-05-15 13:10:46

标签: c# point-of-sale

我想读取两台霍尼韦尔扫描仪的输入,即 Voyager 1202g Orbit 7190g 。对于某些业务要求,两台设备都需要在同一台机器上使用。 两个扫描仪都使用Honeywell POS4NET驱动程序。

我需要知道,哪个扫描程序正在提供数据。

Scanner对象创建如下

// This code is only for illustrating how my application works
// and may therefore be incomplete.

Microsoft.PointOfService.PosExplorer posExp = new PosExplorer(this);
DeviceCollection devices = posExp.GetDevices("Scanner", 
    DeviceCompatibilities.OposAndCompatibilityLevel1);
var listOfScanners =  { Voy1202g ,  Orbit7190g };     // symbolical code

foreach (string device in listOfScanners)
{
    var scanningDevice = posExp.CreateInstance(device) as Microsoft.PointOfService.Scanner;
    if (scanningDevice != null)
    {
        scanningDevice.Claim(1000);
        scanningDevice.DeviceEnabled = true;
        scanningDevice.DataEvent += ScanningDevice_DataEvent;
        scanningDevice.DecodeData = true;
        scanningDevice.DataEventEnabled = true;
        scanningDevice.ErrorEvent += ScanningDevice_ErrorEvent;
    }
}

问题:在事件处理程序ScanningDevice_DataEvent中读取数据时,我无法再区分它们,因为对于两个扫描程序,触发相同的事件 ,无论哪个扫描仪实际读取条形码。

void ScanningDevice_DataEvent(object sender, DataEventArgs e)
{
    Scanner scanner = (Scanner)sender; // <--- sender is always the last one
                                       //       in listOfScanners, i.e. 
                                       //       Orbit7190g in this case. 
    // Additional code here ...

}

当两个扫描仪使用相同的驱动程序时,才会出现此问题。如果我使用两个或更多不同的扫描仪,它们不共享驱动程序,它会按预期工作。如果我启动应用程序的两个不同实例,每个实例都会从其中一个扫描程序中读取。

问题:如何让我的应用程序触发正确的事件?

备注:对我来说,好像Microsoft.PointOfService包含每个ServiceObject类型的处理程序的单个实例,在这种情况下,它始终是HHP.PointOfService.ServiceObjects.Scanner.HandHeldScanner。更改事件分配的顺序时 识别的扫描仪也会改变。

0 个答案:

没有答案