Barcode scanning

Posted on 2014-08-17
Last Modified: 2014-10-25
Hi All,

I am working on a c# winforms application, which should read the barcode value when scanned from barcode sanner pick the required information from database and display that on the screen.

Till now i have worked on such applications, where i will have a cursor on some textbox control, when the user scans the barcode, it will be printed on the textbox. Based on the value on the textbox I use to write a query to get the value from database. But with the new application, it is told that there will be no control on the screen, It is told that if the user keeps the screen active and scans the barcode, the application should read the scanned value and get data from database and print that on the screen.

Can anyone please help me in getting the barcode value without having the control on the screen.

Thanks in advance,
Question by:rajeeva_nagaraj
    LVL 4

    Expert Comment

    by:Sathish DV
    Hi Rajeev,

    As per my understanding, in your previous projects you use to scan the barcode and set it values directly to textbox say for eg. txtBarcode be your text box name. So you have set the value of barcode directly to text box like txtBarCode.Text = <scanned value from scanner>, then u might read the data from text box as string someVal = txtBarcode.Text and pass the someVal to database to query the database.
    Instead set the string variable directy from scanned value like string someVal = <scanned value from scanner>, then you can use the same the existing code to fetch the data from database.
    Check if this helps you. If not is it possible to post some sample code on you set data to  textbox?


    Author Comment

    Thanks for the reply Sathish,

    I am looking at the C# code which can catch the value in to a variable. If you could get me the sample code, that will be nice for me.

    LVL 13

    Accepted Solution

    I don't have my VS at hand, but I'll try a quick outline ...

    The usual scanners for your "old" application worked probably by slicing the device into the keyboard cable (not literally, but with some kind of Y cable). When the user scans, the input is fed into the keyboard queue and processed similar.

    The async usage works on another way ... the scanner in that case sends its data automatically via some more "industrial" interface, like as serial interface (RS232, V.24, RS485, a industrial field bus interface like CAN bus or I2C etc, or possibly socket acces on Ethernet ... there are much possiblities).

    Your program would have to connect that interface and implement to get events if data arrives, and it would have to sort out complete and valid datasets for processing. The data may arrive in various formats, depending on your preferred device. The most easy way would be ASCII, like [STX]<ascii data>[ETX], but there are various flavours of that around. Depending on the code to read and the used scanner, the data may be in some kind of binary format, could contain check sum parts, and other nasty strings attached. After receiving a complete dataset, your code needs to take the needed measures like servicing any other event (i.e. as having got a button pess)

    I've done such software myself (with an easy config: RS232 interface, plain ASCII data), but the implementation depends much on your detailled config.

    Can you elaborate a bit more on your configuration ?

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now