BarcodeScanner.GetDefaultAsync() 总是返回 null

BarcodeScanner.GetDefaultAsync() is always returning null

我正在尝试在 UWP 中为 Zebra 设备(型号 TC700J)创建一个简单的应用程序 运行 Windows 8,我在其中使用了内置的条码扫描器。

根据我的发现,在 Android 上编程时有很多 Zebra 教程可以访问扫描仪,但是 none 对于 Windows 因为 Microsoft 提供了他们的在 Windows.Devices.PointOfService 命名空间中找到自己的通用条码扫描器 API。

我目前的代码看起来像这样:

BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;    

scanner = await BarcodeScanner.GetDefaultAsync();

if (scanner != null)
{
    claimedScanner = await scanner.ClaimScannerAsync();
}

问题是 if 语句永远不会计算为真,因为 GetDefaultAsync 方法总是 returns null。

Over here 有一个答案似乎有效,指出这取决于 GetDefaultAsync 方法的放置位置。我已经尝试将它放在所有建议的位置,但无济于事。

还有另一种方法,BarcodeScanner.FromIdAsync() returns 条码基于作为参数发送的条码扫描器 ID 的字符串表示形式,但我不确定这在这里是否有效,因为设备内置了条形码扫描仪。

似乎Async方法的用法不太正确。

试试下面的代码:

BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;    

scanner = await BarcodeScanner.GetDefaultAsync();

if (scanner != null)
{
    claimedScanner = await scanner.ClaimScannerAsync();
}

更多详情:

https://docs.microsoft.com/en-us/dotnet/csharp/async

https://msdn.microsoft.com/en-us/magazine/jj991977.aspx?f=255&MSPPError=-2147217396

查看 Zebra 的网站,TC700J 似乎是 Windows 10 Mobile IoT Enterprise OS 的型号。 而且平台是ARM(高通骁龙),不是Intel x86/x64.

TC70/TC75触控电脑系列

https://www.zebra.com/us/en/products/mobile-computers/handheld/tc7x-touch-computer-series.html

TC70x 操作系统 (TC700J) Windows 10 Mobile IoT Enterprise v1.13.02 发行说明

https://www.zebra.com/us/en/support-downloads/software/release-notes/operating-system/tc70x-operating-system-v1-13-02--release-notes.html

例如,如果您的 Zebra 设备是旧硬件并且 Windows Phone 8/8.1 是 运行,Windows Phone 似乎不是支持 Windows.Devices.PointOfService 命名空间。

在下一篇文章的评论中有说明。 Windows Phone 8.1: Scan Barcodes using Camera

如果您的 Zebra 设备可以更新到 Windows10 Mobile IoT Enterprise,请在完成后检查。

如果可以更新,可以使用Windows10的条码扫描器样本

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BarcodeScanner

如果您的设备是 运行 Windows 8 for x86,因为 Windows 8.1 支持 Windows.Devices.PointOfService 命名空间,您需要更改 OS 到 Windows 8.1/10 如果可能的话。

在那种情况下,您可以使用以下或以上(对于 Windows10)示例。

Windows8.1

条码扫描仪样本

https://code.msdn.microsoft.com/windowsapps/Barcode-scanner-sample-f39aa411

如果无法更新,请从Windows上的供应商处获取使用BarcodeScanner的软件和文档(Phone?) 8.