BarcodeScanner
BarcodeScanner
BarcodeScanner
BarcodeScanner
Class
Definition
Represents the barcode scanner device.
public : sealed class BarcodeScanner : IBarcodeScanner, IBarcodeScanner2, IClosablepublic sealed class BarcodeScanner : IBarcodeScanner, IBarcodeScanner2, IDisposablePublic NotInheritable Class BarcodeScanner Implements IBarcodeScanner, IBarcodeScanner2, IDisposable// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
This object is created when GetDefaultAsync or FromIdAsync method completes.
See the barcode scanner sample for an example implementation.
Properties
Capabilities Capabilities Capabilities Capabilities
Gets the capabilities of the specified barcode scanner.
public : BarcodeScannerCapabilities Capabilities { get; }public BarcodeScannerCapabilities Capabilities { get; }Public ReadOnly Property Capabilities As BarcodeScannerCapabilities// You can use this property in JavaScript.
- Value
- BarcodeScannerCapabilities BarcodeScannerCapabilities BarcodeScannerCapabilities BarcodeScannerCapabilities
The capabilities of the barcode scanner.
DeviceId DeviceId DeviceId DeviceId
Gets the DeviceInformation.Id of the barcode scanner.
public : PlatForm::String DeviceId { get; }public string DeviceId { get; }Public ReadOnly Property DeviceId As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
The DeviceInformation.Id of the barcode scanner.
VideoDeviceId VideoDeviceId VideoDeviceId VideoDeviceId
Retrieves the video device ID which represents the camera lens associated with the claimed barcode scanner. (Not supported on mobile platforms)
public : PlatForm::String VideoDeviceId { get; }public string VideoDeviceId { get; }Public ReadOnly Property VideoDeviceId As string// You can use this property in JavaScript.
- Value
- PlatForm::String string string string
The video device ID.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
Methods
CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel)
Tests the state of the barcode scanner.
public : IAsyncOperation<PlatForm::String> CheckHealthAsync(UnifiedPosHealthCheckLevel level)public IAsyncOperation<string> CheckHealthAsync(UnifiedPosHealthCheckLevel level)Public Function CheckHealthAsync(level As UnifiedPosHealthCheckLevel) As IAsyncOperation( Of string )// You can use this method in JavaScript.
- level
- UnifiedPosHealthCheckLevel UnifiedPosHealthCheckLevel UnifiedPosHealthCheckLevel UnifiedPosHealthCheckLevel
The specified health check level.
A text description of the test result. Returns an error if the specified check level is not supported by the device.
ClaimScannerAsync() ClaimScannerAsync() ClaimScannerAsync() ClaimScannerAsync()
Attempts to get an exclusive access to the barcode scanner.
public : IAsyncOperation<ClaimedBarcodeScanner> ClaimScannerAsync()public IAsyncOperation<ClaimedBarcodeScanner> ClaimScannerAsync()Public Function ClaimScannerAsync() As IAsyncOperation( Of ClaimedBarcodeScanner )// You can use this method in JavaScript.
When the method completes, it returns a ClaimedBarcodeScanner.
Examples
// Claims the barcode scanner for exclusive use
task<void> Scenario1::ClaimScanner()
{
return create_task(scanner->ClaimScannerAsync()).then([this] (ClaimedBarcodeScanner^ _claimedScanner)
{
this->claimedScanner = _claimedScanner;
if (claimedScanner != nullptr)
{
// UpdateOutput("Barcode scanner claimed successfully.");
}
else
{
// UpdateOutput("Failed to claim barcode scanner.");
}
});
}
// Claims the barcode scanner for exclusive use.
private async Task<bool> ClaimScanner()
{
if (claimedScanner == null)
{
claimedScanner = await scanner.ClaimScannerAsync();
if (claimedScanner != null)
{
// UpdateOutput("Barcode scanner claimed successfully.");
}
else
{
// UpdateOutput("Failed to claim the barcode scanner.");
return false;
}
}
return true;
}
//Creates the barcode scanner, claims it for exclusive use, adds a data event listener,
//and enables it to receive data.
var _scanner = null;
var _claimedScanner = null;
function startReceivingData() {
Windows.Devices.PointOfService.BarcodeScanner.getDefaultAsync().then(function (scanner) {
if (scanner !== null) {
_scanner = scanner;
scanner.claimScannerAsync().done(function (claimedScanner) {
if (claimedScanner !== null) {
_claimedScanner = claimedScanner;
claimedScanner.isDecodeDataEnabled = true;
claimedScanner.addEventListener("datareceived", onDataReceived);
claimedScanner.enableAsync().done(function () {
document.getElementById("btnStartReading").disabled = true;
document.getElementById("btnEndReading").disabled = false;
}, function error(e) {
// "Failed to enable scanner."
});
} else {
//"Could not claim the scanner."
}
}, function error(e) {
//"Could not claim the scanner."
});
} else {
//"Barcode scanner not found. Connect a barcode scanner."
}
}, function error(e) {
//"Asynchronous method failed."
});
}
- See Also
Close() Close() Close() Close()
Close the barcode scanner session, allowing it to be claimed by another client. For C++ and JavaScript, use Close(). For C# and Visual Basic, use Dispose().
public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
Dispose() Dispose() Dispose() Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()
FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)
Creates BarcodeScanner object from the DeviceInformation.Id.
public : static IAsyncOperation<BarcodeScanner> FromIdAsync(PlatForm::String deviceId)public static IAsyncOperation<BarcodeScanner> FromIdAsync(String deviceId)Public Static Function FromIdAsync(deviceId As String) As IAsyncOperation( Of BarcodeScanner )// You can use this method in JavaScript.
- deviceId
- PlatForm::String String String String
The DeviceInformation.Id that identifies a specific barcode scanner, which can be retrieved from the DeviceId property.
The barcode scanner specified by the unique device identifier. Returns a null object in the following cases:
- The specific device is not found.
- Access denied to the existing device. The user can deny access to a device, which is not treated as an exception.
GetDefaultAsync() GetDefaultAsync() GetDefaultAsync() GetDefaultAsync()
Returns the first available barcode scanner.
public : static IAsyncOperation<BarcodeScanner> GetDefaultAsync()public static IAsyncOperation<BarcodeScanner> GetDefaultAsync()Public Static Function GetDefaultAsync() As IAsyncOperation( Of BarcodeScanner )// You can use this method in JavaScript.
The first available barcode scanner. Returns a null object in the following cases:
- A device is not found.
- Access denied to the existing device. The user can deny access to a device, which is not treated as an exception.
Examples
// Creates the barcode scanner.
task<void> Scenario1::CreateDefaultScannerObject()
{
return create_task(BarcodeScanner::GetDefaultAsync()).then([this] (BarcodeScanner^ _scanner)
{
this->scanner = _scanner;
if (this->scanner != nullptr)
{
// UpdateOutput("Barcode Scanner created.");
// UpdateOutput("Device Id is:" + this->scanner->DeviceId);
}
else
{
// UpdateOutput("Barcode scanner not found. Connect a barcode scanner.");
}
});
}
//Creates a barcode scanner.
private async Task<bool> CreateDefaultScannerObject()
{
if (scanner == null)
{
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
// UpdateOutput("Default Barcode Scanner created.");
// UpdateOutput("Device Id is:" + scanner.DeviceId);
}
else
{
// UpdateOutput("Barcode Scanner not found. Please connect a Barcode Scanner.");
return false;
}
}
return true;
}
//Creates the barcode scanner, claims it for exclusive use, adds a data event listener,
//and enables it to receive data.
var _scanner = null;
var _claimedScanner = null;
function startReceivingData() {
Windows.Devices.PointOfService.BarcodeScanner.getDefaultAsync().then(function (scanner) {
if (scanner !== null) {
_scanner = scanner;
scanner.claimScannerAsync().done(function (claimedScanner) {
if (claimedScanner !== null) {
_claimedScanner = claimedScanner;
claimedScanner.isDecodeDataEnabled = true;
claimedScanner.addEventListener("datareceived", onDataReceived);
claimedScanner.enableAsync().done(function () {
document.getElementById("btnStartReading").disabled = true;
document.getElementById("btnEndReading").disabled = false;
}, function error(e) {
// "Failed to enable scanner."
});
} else {
//"Could not claim the scanner."
}
}, function error(e) {
//"Could not claim the scanner."
});
} else {
//"Barcode scanner not found. Connect a barcode scanner."
}
}, function error(e) {
//"Asynchronous method failed."
});
}
- See Also
GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()
Gets an Advanced Query Syntax (AQS) string that you can use to list the available barcode scanners.
public : static PlatForm::String GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string// You can use this method in JavaScript.
An Advanced Query Syntax (AQS) string that is used to enumerate available barcode scanners.
GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes)
Gets an Advanced Query Syntax (AQS) string that you can use to list the barcode scanners available over the specified connection types
public : static PlatForm::String GetDeviceSelector(PosConnectionTypes connectionTypes)public static string GetDeviceSelector(PosConnectionTypes connectionTypes)Public Static Function GetDeviceSelector(connectionTypes As PosConnectionTypes) As string// You can use this method in JavaScript.
- connectionTypes
- PosConnectionTypes PosConnectionTypes PosConnectionTypes PosConnectionTypes
A list of the connection types to test for available barcode scanners.
An Advanced Query Syntax (AQS) string that is used to enumerate the barcode scanners available over the specified connection types
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
GetSupportedProfiles() GetSupportedProfiles() GetSupportedProfiles() GetSupportedProfiles()
Gets the list of profiles supported by the barcode scanner.
public : IVectorView<PlatForm::String> GetSupportedProfiles()public IReadOnlyList<string> GetSupportedProfiles()Public Function GetSupportedProfiles() As IReadOnlyList( Of string )// You can use this method in JavaScript.
As array of strings representing the supported profiles. Returns an empty list if the scanner does not support profiles.
Remarks
A barcode scanner can support a number of features in addition to scanning, such as focal length and scan duration. There can be as many as 100 features exposed through settings or properties. To simplify the scanner configuration, the concept of a profile is introduced, which wraps one or more settings defined by the manufacturer. An application developer can query for a list of supported profiles and set a profile.
GetSupportedSymbologiesAsync() GetSupportedSymbologiesAsync() GetSupportedSymbologiesAsync() GetSupportedSymbologiesAsync()
Gets the symbologies supported by the claimed barcode scanner.
public : IAsyncOperation<IVectorView<unsigned int>> GetSupportedSymbologiesAsync()public IAsyncOperation<IReadOnlyList<uint>> GetSupportedSymbologiesAsync()Public Function GetSupportedSymbologiesAsync() As IAsyncOperation( Of IReadOnlyListuint )// You can use this method in JavaScript.
When the method completes successfully, it returns a list of values that represent the symbologies supported by the device.
IsProfileSupported(String) IsProfileSupported(String) IsProfileSupported(String) IsProfileSupported(String)
Determines whether the profile is supported.
public : PlatForm::Boolean IsProfileSupported(PlatForm::String profile)public bool IsProfileSupported(String profile)Public Function IsProfileSupported(profile As String) As bool// You can use this method in JavaScript.
- profile
- PlatForm::String String String String
Barcode scanner profile.
True if the barcode scanner supports the profile; otherwise false.
IsSymbologySupportedAsync(UInt32) IsSymbologySupportedAsync(UInt32) IsSymbologySupportedAsync(UInt32) IsSymbologySupportedAsync(UInt32)
Determines whether the specified symbology is supported by the barcode scanner.
public : IAsyncOperation<PlatForm::Boolean> IsSymbologySupportedAsync(unsigned int barcodeSymbology)public IAsyncOperation<bool> IsSymbologySupportedAsync(UInt32 barcodeSymbology)Public Function IsSymbologySupportedAsync(barcodeSymbology As UInt32) As IAsyncOperation( Of bool )// You can use this method in JavaScript.
- barcodeSymbology
- unsigned int UInt32 UInt32 UInt32
The specific barcode symbology.
True if the device supports the specified symbology; otherwise, false.
RetrieveStatisticsAsync(IIterable)
RetrieveStatisticsAsync(IIterable)
RetrieveStatisticsAsync(IIterable)
RetrieveStatisticsAsync(IIterable)
Retrieves the requested statistics from the barcode scanner.
public : IAsyncOperation<IBuffer> RetrieveStatisticsAsync(IIterable<PlatForm::String> statisticsCategories)public IAsyncOperation<IBuffer> RetrieveStatisticsAsync(IEnumerable<String> statisticsCategories)Public Function RetrieveStatisticsAsync(statisticsCategories As IEnumerable<String>) As IAsyncOperation( Of IBuffer )// You can use this method in JavaScript.
- statisticsCategories
- IIterable<PlatForm::String> IEnumerable<String> IEnumerable<String> IEnumerable<String>
The list of statistics to retrieve.
- An empty string ("") retrieves all statistics.
- "U_" retrieves all UnifiedPOS defined statistics.
- "M_" retrieves all manufacturer defined statistics.
- "name1" and/or "name2" retrieves specific named statistics as defined by the UnifiedPOS or manufacturer.
- Any combination of individual and groups names ("name3", "U_", "M_").
IBuffer representing the requested statistics.
Remarks
The result does not contain any duplicate statistics even if the input contains duplicates.
Events
StatusUpdated StatusUpdated StatusUpdated StatusUpdated
Occurs when the barcode scanner detects an operation status change.
public : event TypedEventHandler StatusUpdated<BarcodeScanner, BarcodeScannerStatusUpdatedEventArgs>public event TypedEventHandler StatusUpdated<BarcodeScanner, BarcodeScannerStatusUpdatedEventArgs>Public Event StatusUpdated<BarcodeScanner, BarcodeScannerStatusUpdatedEventArgs>// You can use this event in JavaScript.