Adam Jakiela
Adam Jakiela

Reputation: 2248

Getting on Bar code Scan Events Motorola Bar code Scaner

Other posts have been made which are very similar to this, however, I have tried relentlessly to get this to work using the solutions provided in the other threads but have not had any luck.

I have a Motorola DS3578 wireless scanner. I am trying to get my C# application to handle an event when a bar code is scanned. I have been referencing the Motorola Developers documentation.

Here is my code:

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

As shown above, I open the scanner API, list the available scanners, use opcode 1001 to enable handling events, and added the OnBarcodeEvent method.

I get the following output with a cursor ready for input at the bottom line:

enter image description here

When I scan a bar code, nothing is inputted where the cursor is. The line in the OnBarcodeEvent() should be executing, writing a message onto the console.

I know the scanner is capable of listening to the events because when I use it with the sample application provided by Motorola I get this:

enter image description here

As a final note, I have changed the scanner from being in "HIDKB" to "IBM HANDHELD" so events can be handled.

Does anyone have any suggestions how to get the OnBarcodeEvent working?

Upvotes: 1

Views: 2979

Answers (1)

Loren Pechtel
Loren Pechtel

Reputation: 9093

Nowhere do I see a reference to OnBarcodeEvent. It's not overriding an ancestor. Thus how in the world would it be called?

Upvotes: 1

Related Questions