C# 获取条形码扫描事件摩托罗拉条形码扫描程序

C# 获取条形码扫描事件摩托罗拉条形码扫描程序,c#,barcode,C#,Barcode,其他的帖子也与此非常相似,但是,我一直在努力使用其他线程中提供的解决方案来实现这一点,但没有任何运气 我有一台摩托罗拉DS3578无线扫描仪。我试图让我的C#应用程序在扫描条形码时处理一个事件。我一直在参考摩托罗拉开发人员文档 这是我的密码: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Xml; using CoreScanner; name

其他的帖子也与此非常相似,但是,我一直在努力使用其他线程中提供的解决方案来实现这一点,但没有任何运气

我有一台摩托罗拉DS3578无线扫描仪。我试图让我的C#应用程序在扫描条形码时处理一个事件。我一直在参考摩托罗拉开发人员文档

这是我的密码:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml; 

using CoreScanner;

namespace MotarolaScannerTesting
{
class Program
{

    //declare the core scanner class 
    static CCoreScannerClass cCoreScannerClass; 

    static void Main(string[] args)
    {

        cCoreScannerClass = new CoreScanner.CCoreScannerClass(); 

        //CALL OPEN API
        short[] scannerTypes = new short[1];        //scanner types intrested in
        scannerTypes[0] = 1;                        // set all scanner types to 1
        short numberOfScannerTypes = 1;             // size of the scanner type array 
        int status;                                 // Extend API return code

        cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);

        if (status == 0)
            Console.WriteLine("CoreScanner API OPEN");
        else
            Console.WriteLine("CoreScanner API CLOSED");

        // Lists all scanners connected to the host computer.
        // will return nothing

        short numberOfScanners;
        int[] connectedScannerIDList = new int[255];

        string outXML;

        cCoreScannerClass.GetScanners(out numberOfScanners, connectedScannerIDList, out outXML, out status);

        //below does not work because string is an xml file and is never NULL
        Console.WriteLine(outXML);
       // Console.WriteLine(outXML.ToString()); 

        int opcode = 1001;
        string inXML =  "<inArgs>" +
            "<cmdArgs>" +
            "<arg-int>1</arg-int>" +
            "<arg-int>1</arg-int>" +
            "</cmdArgs>" +
            "</inArgs>";
        cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);  

      opcode = 2011; 
        inXML = "<inArgs>" +
           "<scannerID>1</scannerID>" +
              "</inArgs>";
        cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status); 


        Console.Read(); 

    }

    void OnBarcodeEvent(short eventType, ref string pscanData)
    {
        Console.WriteLine("Scannner Event! Scan Data: " + pscanData);
    }
}
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用System.IO;
使用System.Xml;
使用岩心扫描仪;
名称空间Motarolascannerting
{
班级计划
{
//声明核心扫描程序类
静态CCoreScannerClass CCoreScannerClass;
静态void Main(字符串[]参数)
{
cCoreScannerClass=新的CoreScanner.cCoreScannerClass();
//调用开放API
short[]scannerTypes=new short[1];//感兴趣的扫描仪类型
scannerTypes[0]=1;//将所有扫描仪类型设置为1
short numberOfScannerTypes=1;//扫描仪类型数组的大小
int status;//扩展API返回代码
cCoreScannerClass.Open(0,扫描类型,扫描类型数,输出状态);
如果(状态==0)
Console.WriteLine(“CoreScanner API打开”);
其他的
Console.WriteLine(“CoreScanner API关闭”);
//列出连接到主机的所有扫描仪。
//什么也不还
短数量扫描仪;
int[]connectedScannerIDList=新int[255];
字符串输出XML;
cCoreScannerClass.GetScanners(输出扫描仪编号、connectedScannerIDList、输出XML、输出状态);
//以下内容不起作用,因为字符串是xml文件,并且从不为NULL
Console.WriteLine(outXML);
//WriteLine(outXML.ToString());
int操作码=1001;
字符串inXML=“”+
"" +
"1" +
"1" +
"" +
"";
ExecCommand(操作码,ref-inXML,out-outXML,out-status);
操作码=2011;
inXML=“”+
"1" +
"";
ExecCommand(操作码,ref-inXML,out-outXML,out-status);
Console.Read();
}
void OnBarcodeEvent(短事件类型,引用字符串pscanData)
{
Console.WriteLine(“扫描事件!扫描数据:+pscanData”);
}
}
}
如上所示,我打开scanner API,列出可用的扫描器,使用操作码1001启用事件处理,并添加了OnBarcodeEvent方法

我得到以下输出,光标在底线处准备好输入:

当我扫描条形码时,光标所在的位置没有输入任何内容。OnBarcodeEvent()中的行应该正在执行,将消息写入控制台

我知道扫描仪能够监听事件,因为当我将其与摩托罗拉提供的示例应用程序一起使用时,我得到以下信息:

最后,我将扫描仪从“HIDKB”更改为“IBM掌上电脑”,以便处理事件


有人对如何使OnBarcodeEvent工作有什么建议吗?

我在哪里都看不到OnBarcodeEvent的引用。它并没有凌驾于祖先之上。因此,它到底应该如何命名?

我在哪里都看不到对OnBarcodeEvent的引用。它并没有凌驾于祖先之上。因此,它到底是如何被调用的?

不是
Console.Read()
阻塞吗?然而,每当我移除Console.Read()时,窗口在打开后立即关闭,这是可能的。在没有console.Read()的情况下,是否仍然可以在屏幕上保留控制台?控制台程序不会响应事件。你得把它做成一个窗口程序。我明白了。我已经使用窗口程序解决方案实现了代码,但仍然没有结果。我不知道您在哪里添加了OnBarCodeEvent
cCoreScannerClass.BarcodeEvent+=新的_ICoreScannerEvents_barcodeEventHandler(OnBarcodeEvent)
不是
Console.Read()
阻塞吗?但是,每当我移除Console.Read()时,窗口在打开后立即关闭,这是可能的。在没有console.Read()的情况下,是否仍然可以在屏幕上保留控制台?控制台程序不会响应事件。你得把它做成一个窗口程序。我明白了。我已经使用窗口程序解决方案实现了代码,但仍然没有结果。我不知道您在哪里添加了OnBarCodeEvent
cCoreScannerClass.BarcodeEvent+=新的_ICoreScannerEvents_barcodeEventHandler(OnBarcodeEvent)我需要添加:cCoreScannerClass.BarcodeEvent+=new\u ICoreScannerEvents\u BarcodeEventEventHandler(OnBarcodeEvent);我需要添加:cCoreScannerClass.BarcodeEvent+=new\u ICoreScannerEvents\u barcodeEventHandler(OnBarcodeEvent);