I have a Metro RS232 Scanner which I seem to be able to connect to in the below VB.NET code but I cannot enable the device through the DeviceEnabled = True line. The code will not error, it just refuses to set this Boolean to True. I suspect this is the reason the DataEvent event will not fire.
My environment is Windows 7, VB 2010, Microsoft POS 1.12
Private WithEvents _explorer As PosExplorer
Private _scannerList As DeviceCollection
Public WithEvents _activeScanner As Scanner
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim count As Integer = Nothing
Try
count = 0
'Open Explorer and Get list of scanner
_explorer = New PosExplorer()
'_explorer = New PosDevice()
_scannerList = _explorer.GetDevices(DeviceType.Scanner)
'Activate the metrologic scanner
For Each item As DeviceInfo In _scannerList
'For Each item As Scanner In _scannerList
count += 1
If item.ServiceObjectName = "MetroRS232Scanner" Then
'If active scanner is set close it
If Not _activeScanner Is Nothing Then
_activeScanner.Close()
_activeScanner = Nothing
End If
_activeScanner = DirectCast(_explorer.CreateInstance(item), Scanner)
_activeScanner.Open()
_activeScanner.Claim(1000)
' this line will not enable the device
_activeScanner.DeviceEnabled = True
_activeScanner.AutoDisable = False
_activeScanner.DecodeData = True
_activeScanner.DataEventEnabled = True
End If
Next
Catch ex As PosControlException
MessageBox.Show(ex.ToString)
Finally
_explorer = Nothing
End Try
End Sub
The below event will NOT FIRE!
Private Sub activeScanner_DataEvent(ByVal sender As Object, ByVal e As DataEventArgs) Handles _activeScanner.DataEvent
Dim encoder As ASCIIEncoding = New ASCIIEncoding()
Try
' Display the ASCII encoded label text
Label1.Text = encoder.GetString(_activeScanner.ScanDataLabel)
' Display the encoding type
Label1.Text = _activeScanner.ScanDataType.ToString()
' re-enable the data event for subsequent scans
_activeScanner.DataEventEnabled = True
Catch ex As PosControlException
MessageBox.Show(ex.ToString)
Finally
encoder = Nothing
End Try
Dim sCode As String = System.Text.Encoding.ASCII.GetString(_activeScanne r.ScanDataLabel)
End Sub
I have a configuration XML file as below where I have tried all the Hardware ID’s for my scanner, you can see them commented out below. What I have noticed is that the only Hardware ID it will pick ip is "HID_DEVICE_UP:0001_U:0006". It will not pickup the device ID’s
“HID\VID_0C2E&PID_0200&REV_0100" or "HID_DEVICE_UP:0001_U:0006" For these, it will not set the DeviceID property, just blank so then the active scanner cannot be opened.
- <PointOfServiceConfig Version="1.0">
- <ServiceObject Type="Scanner" Name="MetroRS232Scanner">
- <!--
<HardwareID From="HID\VID_0C2E&PID_0200" To="HID\VID_0C2E&PID_0200" />
-->
<HardwareID From="HID\VID_0C2E&PID_0200&REV_0100" To="HID_DEVICE_UP:0001_U:0006" />
- <!--
<HardwareId From="HID_DEVICE_UP:0001_U:0006" To="HID_DEVICE_UP:0001_U:0006" />
-->
- <!--
<HardwareId From="HID_DEVICE_SYSTEM_KEYBOARD" To="HID_DEVICE_SYSTEM_KEYBOARD" />
<HardwareId From="HID_DEVICE" To="HID_DEVICE" />
-->
</ServiceObject>
</PointOfServiceConfig>
So, in a nutshell, my problem is, my code cannot enable the scanner or fire the DataEvent. Any ideas????
Thanks in advance