如何开发桌面应用程序使用C#,可利用USB条码扫描器。如何启动 [英] How to Develop a Desktop Application using C# which can Utilize USB Barcode Scanner. How to start

查看:230
本文介绍了如何开发桌面应用程序使用C#,可利用USB条码扫描器。如何启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过微软开发人员网站了。存在使用pointOfService发展。但我得到的错误:

 扫描仪=等待BarcodeScanner.GetDefaultAsync(); 



他说:IAsyncOperation不包含GetAwaiter



定义

可能是我失踪的参考,但不知道哪一个。
如果有任何其他的方式做,请分享。 。其中一个重要的事情,我正在开发的Windows桌面应用程序



完整代码:

 专用异步任务<布尔> CreateDefaultScannerObject()
{
如果(扫描仪== NULL)
{
UpdateOutput(创建条码扫描器对象。);
扫描器=等待BarcodeScanner.GetDefaultAsync();

如果(扫描仪!= NULL)
{
UpdateOutput(默认条码扫描器创建的。);
UpdateOutput(设备ID是:+ scanner.DeviceId);
}
,否则
{
UpdateOutput(条码扫描器没有发现请连接条形码扫描仪。);
返回FALSE;
}
}
返回真;
}


解决方案

您不能使用BarcodeScanner类在桌面应用程序。这个类是新的通用的Windows平台,只有工作在通用应用程序适用于Windows 8和Windows 10的一部分。



使用条形码扫描仪,最简单的方法是通过他们模拟键盘。您可以配置扫描仪前,实际的代码之后发送前缀和后缀的字符。



通常情况下,您将配置回车作为后缀,以及一些特殊的代码,用户通常不会进入作为前缀。



如果您在处理应用程序的所有按键事件可以发生反应,通过清除和设置焦点,是为了接收条形码的文本框接收所配置的前缀。条形码然后(通过键盘仿真)插入文本框并按下回报。



文本框,然后可以处理这就像用户已经输入的代码插入文本框,按下回车以同样的方式。



对于一些更多的细节和代码示例看的 http://www.codeproject.com/Articles/296533/Using-a-bar-code-scanner-in-NET


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

解决方案

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

这篇关于如何开发桌面应用程序使用C#,可利用USB条码扫描器。如何启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆