I have a WPF point of sale app which I have recently ported from net48 to netcore3.1 (what a job!). In the app, I use a Honeywell Voyager 1200g via a POS4NET service object (HHSO4NET.dll) for scanning simple barcodes and all was well. However In the new netcore3.1 world, I could no longer open the device. I got the following error:-
The Type initializer for `Microsoft.Pointofservice.management.Explorer
Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)'.
I presume that there is something now not available in dotnet core runtime that used to be there in the net framework. So, I decided to look to Windows.Devices.PointOfService in the UWP world to help me integrate the scanner (which is a supported model).
In order to be able to reference these UWP libraries, I followed the following guide which describes adding some additional references
https://blogs.windows.com/windowsdeveloper/2017/01/25/calling-windows-10-apis-desktop-application/
Now I can find, claim and open the scanner just fine! But no events seem to be handled. My code is almost identical to the UWP sample: -
string selector = BarcodeScanner.GetDeviceSelector();
DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(selector);
var device = deviceCollection.FirstOrDefault();
if (device != null)
{
barcodeScanner = await BarcodeScanner.FromIdAsync(device.Id);
if (barcodeScanner != null)
{
//after successful creation, claim the scanner for exclusive use
var claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();
if (claimedBarcodeScanner != null)
{
//Subscribe to the events
claimedBarcodeScanner.ReleaseDeviceRequested += ClaimedBarcodeScanner_ReleaseDeviceRequested;
claimedBarcodeScanner.DataReceived += WhenScannerDataReceived;
claimedBarcodeScanner.IsDecodeDataEnabled = true;
//after successful claim, enable scanner for data events to fire
await claimedBarcodeScanner.EnableAsync();
}
else
{
FrameworkDI.Logger.LogErrorSource("Failure to claim barcodeScanner");
}
}
else
{
FrameworkDI.Logger.LogErrorSource("No Barcode Scanner Present");
}
}
else
{
FrameworkDI.Logger.LogErrorSource("No Barcode Scanner Present");
}
private void WhenScannerDataReceived(object sender, DataEventArgs args)
{
string symbologyName = BarcodeSymbologies.GetName(args.Report.ScanDataType);
var scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
string barcode = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);
}
With a break point in the handler, I cannot seem to hit the event. I downloaded the UWP sample app and ran it using the same machine/scanner and it captured all the events and read the data just fine, so I assume that the scanner is emitting events. It must be something to do with the WPF app not getting the events in the same way that the UWP app did somehow.
Is there something I'm missing here?