Search code examples
c#barcodemotorola

CoreScanner (Motorola) Events not being triggered C#


I am attempting to a simple windows form application, where the users scans a barcode then the application decodes the barcode, then inserts an row into a database. A basic track application. I picked up a Motorola scanner and downloaded the SDK for windows development. I read though "APPENDIX A WRITE SIMPLE APPLICATIONS USING THE SCANNER SDK API" seemed like a good place to start in the Developers guide (http://support.symbol.com/support/search.do?cmd=displayKC&docType=kc&externalId=14978402apdf&sliceId=&dialogID=311240750&stateId=1%200%20311224446). I get the 5 console examples working fine but I can't get the windows form application to work, the OnBarcode Event is never triggered. I followed this video(http://www.youtube.com/watch?v=GfIWWUw4YSc&t=15m47s) by Motorola step by step.

I seem to be having a similar problem to this: Motorola barcode scanner SDK events C# but I am using a USB connection.

I realized that the sample code was original written in .net 2.0 so I tried recompiling the project and it still didn't' work. I then tried changing CCoreScannerClass to CCoreScanner so that Embeded Interop Types would work but that didn't help either. Here is the sample code:

using CoreScanner;

namespace Scanner_WindowsFormsApplication
{
public partial class Form1 : Form
{
    CCoreScanner cCoreScanner;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    void OnBarcodeEvent(short eventType, ref string pscanData)
    {
        string barcode = pscanData;
        this.Invoke((MethodInvoker)delegate { textBox1.Text = barcode; });


    }
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Instantiate CoreScanner Class
            cCoreScanner = new CCoreScanner();
            //Call Open API
            short[] scannerTypes = new short[1];//Scanner Types you are interested in
            scannerTypes[0] = 1; // 1 for all scanner types
            short numberOfScannerTypes = 1; // Size of the scannerTypes array
            int status; // Extended API return code
            cCoreScanner.Open(0, scannerTypes, numberOfScannerTypes, out status);
            // Subscribe for barcode events in cCoreScannerClass
            cCoreScanner.BarcodeEvent += new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
            // Let's subscribe for events
            int opcode = 1001; // Method for Subscribe events
            string outXML; // XML Output
            string inXML = "<inArgs>" +
            "<cmdArgs>" +
            "<arg-int>1</arg-int>" + // Number of events you want to subscribe
            "<arg-int>1</arg-int>" + // Comma separated event IDs
            "</cmdArgs>" +
            "</inArgs>";
            cCoreScanner.ExecCommand(opcode, ref inXML, out outXML, out status);
            Console.WriteLine(outXML);
        }
        catch (Exception exp)
        {
            Console.WriteLine("Something wrong please check... " + exp.Message);
        }
    }
}

}

I read through the Developer guide and found this: "BarcodeEvent Triggered when a scanner captures bar codes. To receive BarcodeEvents, an application needs to execute the REGISTER_FOR_EVENTS method with the SUBSCRIBE_BARCODE event type." I am new to c# so I don't really know what this means and how it applies to the example.

If https://stackoverflow.com/users/68043/scott reads this thread I would love to know how you got the onBarcodeEvent to function in your thread: Dialog hangs when called from event


Solution

  • To get a barcode event from Motorola Scanner SDK your scanner should be in IBM handheld USB or SNAPI. If it is connected to the serial port it should be in NIXDORF MODE B.If your scanner connected in HIDKB mode you can not have barcode events through SDK since scanner works as a keyboard. My advice is to first try the executable of the sample application comes with the SDK and check whether you can see the event from the provided application.

    To configure your scanner to proper mode, see the documentation - pages 5 and 6