intermec multiple barcode read events

K

kdmerkle

I'm developing a vb.netCF windows forms app on an intermec 700 series
(730) with PPC 2003. I have a Main module that calls
Application.Run(Form1)

I'm instantiating a barcode reader object in Form1 and call
ThreadedRead(False) at the end of each successful barcoderead event.
At a certain point, I call Form2.show from Form1.

Form2 has it's own instance of a barcode reader object. My problem is
that when I call Me.Hide and Form1.Show, all the scans performed in
Form2 have somehow been buffered in the Form1 barcode reader object and
get processed on Form1.

What am I missing? Thanks

Here's Form1 code:

Imports Intermec.DataCollection

Public Class Form1
Inherits System.Windows.Forms.Form

Private WithEvents bcr As Intermec.DataCollection.BarcodeReader

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'TODO: Uncomment this line for production
InitializeBarcodeReader()

End Sub


Private Sub InitializeBarcodeReader()
Try
'hide btnSimulateScan for deployment
btnSimulateScan.Visible = False

'Add any initialization after the InitializeComponent() call
Me.bcr = New Intermec.DataCollection.BarcodeReader

Catch IntEx As Intermec.DataCollection.BarcodeReaderException
MsgBox(IntEx.Message)
Me.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

' add the barcoderead eventhandler
AddHandler bcr.BarcodeRead, AddressOf Me.bcr_BarcodeRead
End Sub




Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'These two lines allow the app to be closed (instead of minimized) by
clicking the OK button
Me.ControlBox = True
Me.MinimizeBox = False

lblMessage.Text = "Please scan a Pick Ticket barcode from the
Shipping Schedule."
lblMessage.ForeColor = Color.Black
End Sub

Private Sub bcr_BarcodeRead(ByVal sender As System.Object, ByVal bre
As BarcodeReadEventArgs)

Try
'this event runs in a separate thread so a handler must be invoked
on the parent form
MyPublicBO.Barcode = bre.strDataBuffer
Me.Invoke(New EventHandler(AddressOf ProcessBarcode))

Catch IntEx As Intermec.DataCollection.BarcodeReaderException
MyPublicBO.ErrorMessage = IntEx.Message
Me.Invoke(New EventHandler(AddressOf DisplayErrorMessage))

End Try
End Sub

Public Delegate Sub ProcessBarcodeDelegate(ByVal sender As Object,
ByVal e As EventArgs)
Public Sub ProcessBarcode(ByVal sender As Object, ByVal e As
EventArgs)

Dim sBarcode As String = MyPublicBO.Barcode

Try


'If Barcode scanned is a valid Pick Ticket...
If MyPublicBO.IsValid Then

'...do stuff here
bcr.ScannerEnable = False

End If


Catch ex As Exception

'enable scanner for next scan
bcr.ThreadedRead(False)


End Try

End Sub

Public Delegate Sub DisplayErrorMessageDelegate(ByVal sender As
Object, ByVal e As EventArgs)
Public Sub DisplayErrorMessage(ByVal sender As Object, ByVal e As
EventArgs)
lblMessage.Text = "An error occurred while trying to read the
barcode:" & MyPublicBO.ErrorMessage
lblMessage.ForeColor = Color.Red

End Sub


Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

'dispose of barcode reader object
bcr.Dispose()
End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
bcr.ScannerEnable = True
bcr.ThreadedRead(False)
End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Application.Exit()
End Sub

End Class


Here's Form2 Code:

Imports Intermec.DataCollection

Public Class Form2
Inherits System.Windows.Forms.Form
Private WithEvents bcr As Intermec.DataCollection.BarcodeReader

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
InitializeBarcodeReader()
End Sub

Private Sub InitializeBarcodeReader()
Try
'hide btnSimulateScan for deployment
btnSimulateScan.Visible = False

'Add any initialization after the InitializeComponent() call
Me.bcr = New Intermec.DataCollection.BarcodeReader

Catch IntEx As Intermec.DataCollection.BarcodeReaderException
MsgBox(IntEx.Message)
Me.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

' add the barcoderead eventhandler
AddHandler bcr.BarcodeRead, AddressOf Me.bcr_BarcodeRead
bcr.ThreadedRead(False)
End Sub

Private Sub bcr_BarcodeRead(ByVal sender As System.Object, ByVal bre
As BarcodeReadEventArgs)

Try
'this event runs in a separate thread so a handler must be invoked
on the parent form
MyPublicBO.Barcode = bre.strDataBuffer
Me.Invoke(New EventHandler(AddressOf ProcessBarcode))

Catch IntEx As Intermec.DataCollection.BarcodeReaderException
MyPublicBO.ErrorMessage = IntEx.Message
Me.Invoke(New EventHandler(AddressOf DisplayErrorMessage))

End Try

End Sub

Public Delegate Sub ProcessBarcodeDelegate(ByVal sender As Object,
ByVal e As EventArgs)
Public Sub ProcessBarcode(ByVal sender As Object, ByVal e As
EventArgs)

Dim sBarcode As String = MyPublicBO.Barcode

dim blnEverythingIsDone as Boolean = False

Try
If not blnEverythingIsDone

'...Do Stuff

Else
Me.Hide
Form1.Show
End If

Catch ex As Exception

Finally
bcr.ThreadedRead(False)

End Try

End Sub

Public Delegate Sub DisplayErrorMessageDelegate(ByVal sender As
Object, ByVal e As EventArgs)
Public Sub DisplayErrorMessage(ByVal sender As Object, ByVal e As
EventArgs)
MsgBox("An error occurred while trying to read the barcode:" &
MyPublicBO.ErrorMessage)
End Sub


Private Sub Form2_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
bcr.Dispose()
End Sub

Private Sub Form2_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
bcr.ScannerEnable = True
bcr.ThreadedRead(False)
End Sub

Private Sub Form2_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
bcr.ScannerEnable = False
End Sub
End Class
 
G

Graham McKechnie

Hi,

I have a BarcodeScanner class, which has a static GetInstance method (don't
know what you call that in VB) which will instantiate a single instance of
an Intermec BarcodeReader with its BarcodeReaderEventHandler

I then use the Activated/Deactivate events of each window that is required
to scan to turn things on and off.
Each of those windows also has a InitializeBarcodeScanner method.

eg

private void InitializeBarcodeScanner()
{
// These 3 lines must go together for any window that can scan
barcodeScanner = BarcodeScanner.GetInstance();
this.Activated += new EventHandler(TransporterForm_Activated);
this.Deactivate += new EventHandler(TransporterForm_Deactivate);
}
private void TransporterForm_Activated(object sender, EventArgs e)
{
barcodeScanner.SingleScan += new
SingleScanEventHandler(BarcodeScannerSingleScan);
barcodeScanner.DoubleScan += new
DoubleScanEventHandler(BarcodeScannerDoubleScan);
barcodeScanner.Enable();
}
private void TransporterForm_Deactivate(object sender, EventArgs e)
{
barcodeScanner.SingleScan -= new
SingleScanEventHandler(BarcodeScannerSingleScan);
barcodeScanner.DoubleScan -= new
DoubleScanEventHandler(BarcodeScannerDoubleScan);
barcodeScanner.Disable();
}

As you can see its a little more complicated because we have a need for
SingleScan and DoubleScan events, but I would have thought a BarcodeScanner
class would be the way to go.


Graham
 
K

kdmerkle

Thanks Graham, I was thinking I would need to do something like that.
Would you mind sharing your code for the BarcodeScanner class? I'd
appreciate it. And by the way, a Shared method in VB is the same as a
Static method in C#.

Kurt
 
C

Chris Botha

This does not answer your question directly, but my solution was, after
fighting the scanner and "you should not install the Microsoft SDK stuff
with the Symbol SDK" - just imagine, I don't know if this is still a
requirement, then one day, halfway through the argument with the technical
support guy after he mentioned ScanWedge it struck me - what am I arguing
about, and since then ScanWedge is what they get.
 
K

kdmerkle

Graham,

I wrote a quick class per your recommendation & it works great.
Thanks.

Kurt
 

jpn

Joined
Aug 11, 2011
Messages
1
Reaction score
0
hi,i hv one issue, when on continously scanning the barcodes, the "Hardware trigger" is getting enabled automatically. so that am not able to scan atleast even once. can someone pls say me the reason. (on intermec cn70 device, settings/system/intermec settings/Data collection/internal scanner/scanner settings/HARDWARE TRIGGER)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top