问题
I want to read input from two Honeywell scanners, namely Voyager 1202g and Orbit 7190g. For some business requirements, both devices need to be used from the same machine. Both scanners use the Honeywell POS4NET driver.
I need to know, which scanner is delivering the data.
The Scanner
objcts are created as follows
// 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;
}
}
Problem: When reading data inside the event handler ScanningDevice_DataEvent
, I can no longer distinguish between them, because for both scanners, the identical event is fired, no matter which scanner is actually reading the barcode.
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 ...
}
This issue only arises, when two scanners use the same driver. If I use two or more different scanners, that do not share the driver, it works as expected. It also does, if I start 2 different instances of my application, each one reading from one of the scanners.
Question: How can I make my application fire the correct event?
Remark: To me, it looks as if Microsoft.PointOfService
holds a single instance of the handler per ServiceObject type , which, in this case, is always HHP.PointOfService.ServiceObjects.Scanner.HandHeldScanner
. When changing the order in which the events are assigned,
the recognized scanner also changes.
来源:https://stackoverflow.com/questions/50351121/why-does-honeywell-pos4net-fire-the-same-event-for-two-different-scanners