Enumerate devices in Windows Embedded Handheld 8.1
7/17/2014
In Windows Embedded 8 Handheld, you could enumerate attached devices using a Handheld-specific namespace, Microsoft.Embedded.Devices.Enumeration; however, this namespace has been deprecated for Windows Embedded 8.1 Handheld and superseded by the equivalent WinRT namespace, Windows.Devices.Enumeration. This topic explains how the process of enumerating attached devices in Handheld 8.1 has changed. For more detailed information, see the associated WinRT documentation here.
The new method for enumerating devices
Classes in both of those namespaces are designed to enumerate external devices attached to a handheld device. You could retrieve a device selector using Advanced Query Syntax (AQS) — for example, BarcodeScanner:: GetDeviceSelector()
or MagneticStripeReader::GetDeviceSelector()
. For more information on using AQS, see this page. You could then pass the AQS string into the APIs exposed by the enumeration namespace to return a collection of DeviceInformation objects corresponding to device(s) matching the query. A common scenario for using this collection programmatically might be to prompt the user to choose one of the attached devices, then pass the device ID back into the POS APIs to instantiate an object associated with the desired device.
Apart from the use of a different namespace and its associated classes, the process is almost identical in Handheld 8.1. The most significant difference is that the FindAll method used in Windows Embedded 8 Handheld has been superseded by an asynchronous method, FindAllAsync, as shown in the code snippet below.
In Windows Embedded 8 Handheld:
deviceList = MEDE.DeviceInformation.FindAll(scannerString);
In Windows Embedded 8.1 Handheld:
Task<DeviceInformationCollection> asyncOp =
Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(scannerString).AsTask();
deviceList = asyncOp.Result;