Link to home
Create AccountLog in
Avatar of ramana_mca03
ramana_mca03

asked on

Read data from Barcode Reader using VB.NET

I am developing windows application using VB.NET 2005

its simple application like

reading Barcodes using Barcode Reader
once i read barcode, the data is comming and displaying Textbox is working fine...
BUT
what i want to do i need to capture the Barcode data before comming to form for some validation purpose...


So how can we get Barcode data from Barcode Reader or Human Interface Device...

so which event will fire on form once data is comming to Form??


thanks
Ramana
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

If you post the manufacture of the barcode reader and model number I will try to do some research on it to see how it can be done.
Avatar of ramana_mca03
ramana_mca03

ASKER

Hi FernandoSoto:

here is the link of my Barcode Reder using to read barcodes.


http://www.symbol.com/ls3408er

waiting for your answer...

thanks
Ramana
On the "Data Sheet" tab in the link you provided it has this section:

    Interfaces Supported:  RS232, Keyboard Wedge, Wand Emulation, Scanner Emulation, IBM 468X/469X, USB and Synapse

If you are using the "Keyboard Wedge" option then there isn't really a way to "query" the scanner as it simply sends the barcode as normal keyboard input.

If you hook up the scanner using the RS232 option then you can query it directly...but you have to write lower level software to do so.  You can also buy third party software to handle this for you:
http://www.taltech.com/products/interface.htm
http://www.taltech.com/products/bcwedge.html
Hi Ramana;

What interface are you using?

    RS-232 , USB , Scanner Emulation Interface

Fernando
Hi FernandoSoto:

I am using USB.
I plugged my Barcode Reader to one of my computer USB port..

thanks
Ramana
From the link I gave above:

USB Output

Bar code scanners that have a USB output can work one of two ways.
The first is that they can work exactly like a Keyboard Wedge scanner and the second is that they can work exactly like a RS232 serial output scanner.

When you purchase a bar code scanner that has a USB output, you normally will also need to specify which interface you want - either "USB Keyboard Wedge" or "USB RS232 serial port". (Some bar code scanners are only available with the USB Keyboard Wedge option



Which mode are you working ?...
Hi Idle mind:

i think i am using "USB RS232 serial port".
once i scan the barcode i am getting that data and displaying Textbox working fine...
but i dont want to dispaly that data in to directly my Textbox..
Before comming in to Textbox i need do some validation like whether that basr code is correct or not like that....

how can we get that data..??

thanks
Ramana
What code do you use to get the data into the text box?
Hi FernandoSoto:
I am not using any code to get data in to Textbox..
Its automatically process.the data is comming through the Barcode Scanner (or) Reader and putting in to our system...

The thing is
Once i use my Barcode Reader to use for read Barcodes its read that barcode and put it in to Textbox(Not only Textbox where the cursor blinks on the screen.Suppose if you open notepad in our system
and use the Barcode Scanner and press scan button the data is showing in to Notepad.What i am trying to say here the Scan data is displaying where the cursor blinks..)

So the data is comming properrly .but i need to Capture that data before dispalying in to textbox or other control...

how can we do...?
please help me..its very arjunt...


thanks
Ramana






Go here
http://www.symbol.com/category.php?category=31
and try to get their SDK

you will have to use their SDK to capture that data.

They should have an interrupt being sent back to the OS that you can handle in your app and get the data that way.

hope that helps
-smit.
You said:

    "Suppose if you open notepad in our system and use the Barcode Scanner and press scan button the data is showing in to Notepad."

That REALLY sounds like you are using the "USB Keyboard Wedge" mode...which requires no additional software to be installed...and doesn't allow you to do what you like.
Hi Idle Mind:
This is same device i am using for Scan:

http://www.symbol.com/ls3408er

i am not sure whether thats USB or Keyboard Wedge because this is the first time i am working on Barcode Readers...

Just i need capture the Scan data and  store in to Variable... thats it...

how can we do this...??

thanks
Ramana








try getting the value from the textbox based on the onchange event
else, use their sdk to handle the events/interrups from the barcode scanner
Hi ullfindsmit:

I tryied their sdk but i dont find any usefull tips for me...
can you provide any other sample code...please


thnaks
Ramana
i tried searching on their documents but was unsuccessfull, but try their support forums
Hi Ramana;

So it sounds like the scanner is acting like a keyboard input device. If that is the case then this should work. Set the Forms KeyPreview property to True. Then add a Forms KeyPress event handler as shown below. Each time a character is set to the TextBox with the focus the Forms KeyPress event gets it first. Then do what test you need on the character. If you do not want the character to go to the TextBox set the e.Handled property to True other wise leave it alone and let the handler goto completion.

    Private Sub Form1_KeyPress(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        If e.KeyChar <> "Character to be tested" Or e.KeyChar <> "Character to be tested" Then
            ' Send the data to the TextBox that has focus
        Else
            ' Do what I need to with the character and do not send to the textbox
            e.Handled = True
        End If

    End Sub

See if that does what you need.

Let me know.
Fernando
Hi FernandoSoto:

Thanks for your time effort....
the above code is working good...
But problem is e.KeyChar is giving only first letter in my Barcode

suppose my barcode has 9 letters but e.Keychar is giving only first letter(B) of that barcode

Sample Barcode:
BCSPT0157

so how can we get the whole Barcode??

thanks
Ramana
Can you post the code the way you placed it into your solution.
Private Sub frmHID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        If e.KeyChar <> "BCSPT0157" Or e.KeyChar <> "BCSPT0158" Then
            TextBox1.Text = e.KeyChar
              Else
             e.Handled = True
        End If

    End Sub
Hi Ramana;

The Forms KeyPress event handler receives only one character at a time so you will need to do something like the following.

    ' Class level variables
    ' Holds the barcode while it is being read.
    Private Barcode As StringBuilder
    ' Holds the barcodes that you donot want in the text box
    Private InvalidBarcode As Hashtable
    ' Current status of the Forms KeyPress event mode
    Private Scanning As Boolean

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' Create a StringBuilder to hold barcode being read in to the system
        Barcode = New StringBuilder()
        ' Create the hash table to hold barcodes you do not want to process
        InvalidBarcode = New Hashtable()
        ' Populate the hash table
        InvalidBarcode.Add("BCSPT0157", Nothing)
        InvalidBarcode.Add("BCSPT0158", Nothing)
        ' Set scan mode to not scanning
        Scanning = False

    End Sub

    Private Sub Form1_KeyPress(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        ' If in scan mode process the characters from the scanner. This is needed because if we did not
        ' then other parts of the application would not get keyboard input. If not in scan mode just exit.
        If Scanning Then
            ' Place the character just read into the StringBuffer
            Barcode.Append(e.KeyChar)
            ' Check to see if we have read the complete barcode
            If Barcode.Length = 9 Then
                ' The complete barcode was read in. Check to see if the code we read in is one
                ' to be processed.
                If InvalidBarcode.Contains(Barcode.ToString()) Then
                    ' The bar code is one of the ones we do not want to process
                    TextBox1.Text = "Invalid Barcode"
                Else
                    ' Is a valid barcode so send it to the text box.
                    TextBox1.Text = Barcode.ToString()
                End If
                ' Clear the StringBuffer to get ready for the next barcode.
                Barcode.Length = 0
            End If
            ' When in this mode do not send the characters read to the text box.
            e.Handled = True
        End If

    End Sub


    Private Sub btnScanning_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnScanning.Click

        ' This button places the application in scan mode or regular mode.
        If btnScanning.Text = "Scan" Then
            Scanning = True
            btnScanning.Text = "Stop"
        Else
            Scanning = False
            btnScanning.Text = "Scan"
        End If
        ' Reset the StringBuffer for the next scan
        Barcode.Length = 0

    End Sub

Fernando
Hi FernandoSoto:
I really thanks for your  time effort to slove this problem

once i placed your code in to my form it's getting error
****  Private Barcode As StringBuilder

which namespace can i Import for String Builder?


Thanks
Ramana
Yes as Idle_Mind stated the namespace is System.Text so add this line to the top of your code file

Imports System.Text
Hi FernandoSoto:

Now the code is working good...
but actually that is not the requirmnet...
I need to get that data directly in to my class
is it possible..?

here i am posting the code for
detecting Human Interface Device(HID) or Barcode Reader in to our system
so can we read data directly from the device....?

Public Shared Function GetList() As Dictionary(Of String, String)
        Dim controllerSearcher As New ManagementObjectSearcher("Select * from Win32_USBControllerDevice")
        Dim controllerResults As ManagementObjectCollection = controllerSearcher.Get()

        Dim list As New Dictionary(Of String, String)

        For Each controllerObject As ManagementObject In controllerResults

            Dim deviceName As String = controllerObject("Dependent").ToString.Replace(Chr(34), "")
            Dim device As String = deviceName.Substring(deviceName.IndexOf("=") + 1)

            Dim deviceSearcher As New ManagementObjectSearcher("Select * From Win32_PnPEntity Where DeviceID = '" & device & "'")
            Dim deviceResults As ManagementObjectCollection = deviceSearcher.Get()

            For Each deviceObject As ManagementObject In deviceResults

                Dim deviceID As String = deviceObject("DeviceID").ToString().ToUpper()
                Dim description As String = deviceObject("Description").ToString()

                list.Add(deviceID, description)
            Next deviceObject

        Next controllerObject
        Return list
    End Function



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mylist As Dictionary(Of String, String) = GetList()
        Dim I As Integer = 0
        For Each mykey As String In mylist.Keys
            If mylist.Item(mykey) = "USB Human Interface Device" Then
                MessageBox.Show("HID Found in your System.")
            End If
            I = I + 1
        Next

    End Sub


so how can we read data directly from Barcode Reader in to our class (bcz i am planning to implement a class for this Barcode Validation) ??

thanks
Ramana
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
If you don't want to intercept each keystroke and "build" the barcode incrementally,  then you need to use a DIFFERENT mode (such as RS232) on your scanner...
Hi FernandoSoto:
I  understood your validation thing

but i need the data directly in to my class from Barcode Reader

like
Public Class BarcodeValidation

Dim myBarcode as String=BarcodeReder.Getdata()

End Class

so it is possible to get data directly from Reader....??

Thanks
Ramana
Hi Idle_Mind:

Yes your right.I dont want to intercept each keystroke and "build" the barcode incrementally...
How can we get data  from DIFFERENT mode (such as RS232) ???
can you provifde some sample code...it would really help for me....

Thanks
Ramana
For you to be able to do something like this:

Dim myBarcode as String=BarcodeReder.Getdata()

You will need to do something like what Idle_Mind stated and reposted here, "If you don't want to intercept each keystroke and "build" the barcode incrementally,  then you need to use a DIFFERENT mode (such as RS232) on your scanner..."

Or another suggestion from Idle_Mind, "If you hook up the scanner using the RS232 option then you can query it directly...but you have to write lower level software to do so.  You can also buy third party software to handle this for you:
http://www.taltech.com/products/interface.htm
http://www.taltech.com/products/bcwedge.html"
To change the mode on your scanner, you need to change the settings on the scanner itself.

My gut feeling, based on your programming experience level, is that you would be best off using some third party software to accomplish this task...