POS .NET problem, cannot enable scanner or fire DataEvent event

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small 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.
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small My environment is Windows 7, VB 2010, Microsoft POS 1.12
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt Private<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue WithEvents _explorer <span style="color:blue As PosExplorer
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt Private<span style="font-family:Consolas; font-size:9.5pt _scannerList
<span style="color:blue As DeviceCollection
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt Public<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue WithEvents _activeScanner <span style="color:blue
As Scanner
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt Private<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Sub Form1_Load(<span style="color:blue ByVal sender
<span style="color:blue As <span style="color:blue Object, <span style="color:blue
ByVal e <span style="color:blue As System.<span style="color:#2b91af EventArgs)
<span style="color:blue Handles <span style="color:blue Me.Load
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim count <span style="color:blue As
<span style="color:blue Integer = <span style="color:blue Nothing
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Try
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
count = 0
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green Open Explorer and Get list of scanner
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_explorer = <span style="color:blue New PosExplorer()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green _explorer = New PosDevice()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_scannerList = _explorer.GetDevices(DeviceType.Scanner)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green Activate the metrologic scanner
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue For <span style="color:blue Each item
<span style="color:blue As DeviceInfo <span style="color:blue In _scannerList
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green For Each item As Scanner In _scannerList
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
count += 1
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue If item.ServiceObjectName = <span style="color:#a31515
"MetroRS232Scanner" <span style="color:blue Then
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green If active scanner is set close it
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue If <span style="color:blue Not _activeScanner
<span style="color:blue Is <span style="color:blue Nothing <span style="color:blue
Then
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style=" _activeScanner.Close()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner = <span style="color:blue Nothing
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue If
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner = <span style="color:blue DirectCast(_explorer.CreateInstance(item), Scanner)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.Open()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.Claim(1000)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green this line will not enable the device
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.DeviceEnabled = <span style="color:blue True
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.AutoDisable = <span style="color:blue False
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.DecodeData = <span style="color:blue True
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style=" _activeScanner.DataEventEnabled =
<span style="color:blue True
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue If
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Next
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Catch ex <span style="color:blue As PosControlException
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af MessageBox.Show(ex.ToString)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Finally
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_explorer = <span style="color:blue Nothing
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Try
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Sub
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <strong style=" <span style="font-family:Consolas; font-size:12pt The below event will NOT FIRE!

<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Private <span style="color:blue Sub activeScanner_DataEvent(<span style="color:blue ByVal sender
<span style="color:blue As <span style="color:blue Object, <span style="color:blue
ByVal e <span style="color:blue As DataEventArgs) <span style="color:blue
Handles _activeScanner.DataEvent
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim encoder <span style="color:blue As
<span style="color:#2b91af ASCIIEncoding = <span style="color:blue New
<span style="color:#2b91af ASCIIEncoding()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Try
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green Display the ASCII encoded label text
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Label1.Text = encoder.GetString(_activeScanner.ScanDataLabel)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green Display the encoding type
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
Label1.Text = _activeScanner.ScanDataType.ToString()
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:green re-enable the data event for subsequent scans
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
_activeScanner.DataEventEnabled = <span style="color:blue True
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Catch ex <span style="color:blue As PosControlException
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:#2b91af MessageBox.Show(ex.ToString)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Finally
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
encoder = <span style="color:blue Nothing
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Try
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue Dim sCode <span style="color:blue As
<span style="color:blue String = System.Text.<span style="color:#2b91af Encoding.ASCII.GetString(_activeScanner.ScanDataLabel)
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; font-size:9.5pt <span style="
<span style="color:blue End <span style="color:blue Sub
<p style="margin:0cm 0cm 0pt <span style="font-family:Consolas; color:blue; font-size:9.5pt
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small 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 <span style="font-family:"Courier New"; font-size:10pt "HID_DEVICE_UP:0001_U:0006".
<span style="font-family:Arial; font-size:small It will not pickup the device IDâs

<p style="margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt âHIDVID_0C2E&PID_0200&REV_0100 <span style="font-family:"Verdana","sans-serif"; color:blue; font-size:8pt "<span style="font-family:"Verdana","sans-serif"; color:#990000; font-size:8pt
<span style="font-family:Arial; font-size:small or <span style="font-family:"Verdana","sans-serif"; color:blue; font-size:8pt " <span style="font-family:"Verdana","sans-serif"; font-size:8pt HID_DEVICE_UP:0001_U:0006 <span style="font-family:"Verdana","sans-serif"; color:blue; font-size:8pt "
<span style="font-family:Arial; font-size:small For these, it will not set the DeviceID property, just blank so then the active scanner cannot be opened.

<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small
<p style="text-indent:-24pt; margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt file:///C:/Users/NHARGREA/Desktop/BarCodeTest/Control%20Configurations.xml <span style="font-family:"Courier New"; color:red -
<span style="color:blue <<span style="color:#990000 PointOfServiceConfig Version<span style="color:blue =" 1.0 <span style="color:blue
<p style="text-indent:-24pt; margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt file:///C:/Users/NHARGREA/Desktop/BarCodeTest/Control%20Configurations.xml <span style="font-family:"Courier New"; color:red -
<span style="color:blue <<span style="color:#990000 ServiceObject Type<span style="color:blue =" Scanner <span style="color:blue "<span style="color:#990000 Name<span style="color:blue =" MetroRS232Scanner <span style="color:blue
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt -
<span style="color:blue <!-- <span style="font-family:Courier; color:#888888; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:#888888; font-size:8pt <HardwareID From="HIDVID_0C2E&amp;PID_0200" To="HIDVID_0C2E&amp;PID_0200" /><span style="font-family:"Courier New"; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue -->
<p style="text-indent:-24pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue <<span style="color:#990000 HardwareID
<span style="color:#990000 From<span style="color:blue =" HIDVID_0C2E&PID_0200&REV_0100 <span style="color:blue "<span style="color:#990000 To<span style="color:blue =" HID_DEVICE_UP:0001_U:0006 <span style="color:blue "
/>
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt -
<span style="color:blue <!-- <span style="font-family:Courier; color:#888888; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:#888888; font-size:8pt <HardwareId From="HID_DEVICE_UP:0001_U:0006" To="HID_DEVICE_UP:0001_U:0006" /><span style="font-family:"Courier New"; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue -->
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt -
<span style="color:blue <!-- <span style="font-family:Courier; color:#888888; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:#888888; font-size:8pt <HardwareId From="HID_DEVICE_SYSTEM_KEYBOARD" To="HID_DEVICE_SYSTEM_KEYBOARD" />
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:#888888; font-size:8pt <span style="
<HardwareId From="HID_DEVICE" To="HID_DEVICE" /><span style="font-family:"Courier New"; font-size:8pt
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue -->
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue </<span style="color:#990000 ServiceObject<span style="color:blue >
<p style="text-indent:-12pt; margin:0cm 0cm 0pt <span style="font-family:"Courier New"; color:red; font-size:8pt <span style="font-family:"Verdana","sans-serif"; font-size:8pt
<span style="color:blue </<span style="color:#990000 PointOfServiceConfig<span style="color:blue >
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small So, in a nutshell, my problem is, my code cannot enable the scanner or fire the DataEvent. Any ideas????
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Arial; font-size:small Thanks in advance

View the full article
 
Back
Top