user2007758
user2007758

Reputation: 41

Motorola Scanner SDK BarcodeEvent Trigger

Any help with this is much appreciated -

I'm having trouble firing BarcodeEvent in VB .NET. The scanner is in USB(IBM Hand Held) Mode and everything works fine with the C# sample application that came with the SDK. Also, I am able to make the scanner Beep in VB .net, so the driver is working fine. I probably messed up converting this C# code to VB

cCoreScannerClass.BarcodeEvent += new
_ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);

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

-- Here is my code: -------

Imports CoreScanner
Imports System.Collections.Generic
Imports System.Text

Public Class Form1

    Public WithEvents cCoreScannerClass As CCoreScannerClass

    Sub Main()

        cCoreScannerClass = New CCoreScannerClass
        Dim scannertype(1) As Short
        scannertype(0) = 1
        Dim numberOfScannerTypes As Short
        numberOfScannerTypes = 1
        Dim status As Integer

        cCoreScannerClass.Open(0, scannertype, numberOfScannerTypes, status)

        AddHandler cCoreScannerClass.BarcodeEvent, AddressOf OnBarcodeEvent

        Dim opcode As Integer = 1001
        Dim outXML As String 
        Dim inXML = "<inArgs>" +
                       "<cmdArgs>" +
                           "<arg-int>1</arg-int>" +
                           "<arg-int>1</arg-int>" +
                       "</cmdArgs>" +
                    "</inArgs>"

        cCoreScannerClass.ExecCommand(opcode, inXML, outXML, status)

    End Sub

    Public Sub OnBarcodeEvent(eventType As Short, ByRef pscanData As String) Handles cCoreScannerClass.BarcodeEvent
        MsgBox("Success!")
    End Sub

Upvotes: 3

Views: 4052

Answers (2)

Kevin Vermeer
Kevin Vermeer

Reputation: 2852

I had an identical problem, and eventually determined that it was related to the permissions of the Interop.CoreScanner.dll file.

On a clean install, a straightforward "Build" of the demo app would work. Cleaning and rebuilding would cause events to fail, but other calls (like discovering scanners or sounding the beeper) would work. My custom app behaved in the same way as the cleaned-and-rebuilt demo app.

It turns out that the SDK ships the demo apps with pre-built binaries that have different permissions than the installer:

  • Pre-built binary at Motorola Scanner\Scanner SDK\Scanner SDK\Sample Applications\bin
           Group:       System    Administrators    Users
Permission:                
 - Full Control            X            X             
 - Modify                  X            X             
 - Read and Execute        X            X             X
 - Read                    X            X             X
 - Write                   X            X            
 - Special Permissions
  • Library copy at Motorola Scanner\Common
           Group:       System    Administrators    BUILTIN (BUILTIN)?
Permission:                
 - Full Control            X            X             X
 - Modify                  X            X             X
 - Read and Execute        X            X             X
 - Read                    X            X             X
 - Write                   X            X             X
 - Special Permissions

I have no idea who the 'BUILTIN' user is, or why the Users group has no permissions, or why you can execute some but not all code in the DLL with the latter setup.

However, replacing the latter with the former solved my problem.

Upvotes: 1

user2007758
user2007758

Reputation: 41

After playing around with all the events, this same exact VB .net Code started working all of the sudden. I guess the scanner came to its senses when I did a reboot event. There is not a single example of VB .net for Motorola corescanner class, sooo You are welcome :)

Upvotes: 1

Related Questions