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

萝らか妹 提交于 2019-12-06 14:30:50

问题


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;
    }

回答1:


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



来源:https://stackoverflow.com/questions/35105510/how-to-develop-a-desktop-application-using-c-sharp-which-can-utilize-usb-barcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!