Deepanshu Mishra
Deepanshu Mishra

Reputation: 303

How to Develop a Desktop Application using C# which can Utilize USB Barcode Scanner. How to start

I have gone through Microsoft Developer website. There is development using pointOfService. but I am getting error in:

 scanner = await BarcodeScanner.GetDefaultAsync();

SAYING: IAsyncOperation does not contain definition for GetAwaiter

May be I am missing any Reference but not sure which one. If there is any other way to do please share it. And one Important thing I am developing Windows Desktop Application.

Complete Code is:

 private async Task<bool> CreateDefaultScannerObject()
    {
        if (scanner == null)
        {
            UpdateOutput("Creating Barcode Scanner object.");
            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;
    }

Upvotes: 1

Views: 2055

Answers (1)

NineBerry
NineBerry

Reputation: 28499

You cannot use the BarcodeScanner class in a Desktop application. This class is part of the new "Universal Windows Platform" that only works in Universal Apps for Windows 8 and Windows 10.

The easiest way to use barcode scanners is by having them emulate the keyboard. You can configure the scanners to send prefix and suffix characters before and after the actual code.

Usually, you will configure "Return" as the suffix and some special code that the user usually never enters as the prefix.

If you process all keypress events in your application you can react to receiving the configured prefix by clearing and setting focus to a textbox that is meant to receive the barcode. The barcode is then (via the keyboard emulation) inserted into the textbox and return is pressed.

The textbox can then process this the same way as if a user had entered the code into the textbox and pressed Return.

For some more details and code samples see http://www.codeproject.com/Articles/296533/Using-a-bar-code-scanner-in-NET

Upvotes: 1

Related Questions