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
(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