Barcode scanner with C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Barcode scanner with C#

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Barcode scanner with C#

    Hi guys.

    I just started to learn C# and having a lot of fun with it. Currently i am working on a program for a gym. it's a simple windows form app that keep track of comings in gym and some statistic (with a mdf database)

    recently my friend asked me to implement a barcode scanner, and i thought no big deal. So i purchased ps2 barcode scanner (that returns strings like keyboard) and its very easy to read the data and get the wanted string from barcode.

    but my question is this: when a scanner reads some code (like 38503085 <-barcode) how do i trigger an event (something similar to KeyPress but actually this is a string).

    so i use these codes (from barcode scanner) as an ID for a member and when i read a certain barcode i want that member to be displayed in form. (i dont want to make a textbox, focus it, get the barcode string there and press enter)

    i hope you can help me and for sure i will be tracking this form and help you guys with my knowledge

  2. #2
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,834

    Re: Barcode scanner with C#

    Most wedge type scanners such as you describe have the ability to add a suffix to the data scanned. Typically the way you would handle this is to set the scanner to send a CR after the data then in the keypress event check to see if a CR was entered and if so then call whatever sub to process the data.

    Of course you could do this with any character or if the barcode is fixed length you could even do it based on the length of the barcode.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile Re: Barcode scanner with C#

    but my question is this: when a scanner reads some code (like 38503085 <-barcode) how do i trigger an event (something similar to KeyPress but actually this is a string).

    so i use these codes (from barcode scanner) as an ID for a member and when i read a certain barcode i want that member to be displayed in form. (i dont want to make a textbox, focus it, get the barcode string there and press enter)
    instead of Writing in Keypress event you handle it in Timer_Tick Event.Like The following .

    Code:
    privatevoid timer1_Tick(object sender, EventArgs e)
    {
    if (txtbarcode.Text.Length >= 12)
    {
    PrintLabel(); 'if you want to print in form .you can apply the same
    }
    }


  4. #4
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,834

    Re: Barcode scanner with C#

    No you don't need to use a timer.

    A wedge scanner fires the leypress event with every character. The there is no need nor point in using a timer. Most of these scanners come with a manual in which there is usually some barcodes you scan for configuration one of which should give you an enter keypress.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Re: Barcode scanner with C#

    No you don't need to use a timer.

    A wedge scanner fires the leypress event with every character. The there is no need nor point in using a timer. Most of these scanners come with a manual in which there is usually some barcodes you scan for configuration one of which should give you an enter keypress.
    Can you post some code ?.What are you trying to explain ?

  6. #6
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,834

    Re: Barcode scanner with C#

    I am not going to write the code but it is very very simple.
    1: Configure the device to add a CR after each scan.
    2: Place code in the keypress event to check if the keypressed is the enter key.
    3: Place whatever code you want to process the barcode when the test is true.

    As for configuring the device that depends on the device but I have never saw one that did not have this capability. Normally there are several barcodes in the manual that you can scan to setup the device. They will normally allow you to set it for the type of barcodes you want to decode and normally allow you to add a prefix and/or suffix to the data. In this case you would add a CR as the suffix so the device will send a CR after each decoded string.
    Always use [code][/code] tags when posting code.

  7. #7

    Re: Barcode scanner with C#

    sorry, as my project is due this friday, so I have no time to start a new discussion and wait for others to find that new thread. Here is my problem

    I am working on a project that updates the records in my database from a barcode scanner, at the moment when you scan an item it places the barcode ina textbox on my form. Which needs a button click to submit the record to the database. and I am trying to achieve this: once the item has been scanned for the record to be inserted into the database without having to manually clicking a button.

    So please give me some feasible advice, thank you so much.

  8. #8
    Join Date
    Mar 2014
    Posts
    6

    Re: Barcode scanner with C#

    Quote Originally Posted by barcode addict View Post
    sorry, as my project is due this friday, so I have no time to start a new discussion and wait for others to find that new thread. Here is my problem

    I am working on a project that updates the records in my database from a barcode scanner, at the moment when you scan an item it places the barcode created ina textbox on my form. Which needs a button click to submit the record to the database. and I am trying to achieve this: once the item has been scanned for the record to be inserted into the database without having to manually clicking a button.

    So please give me some feasible advice, thank you so much.
    Actually your method can be used to count how many products have been scanned.

  9. #9
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Barcode scanner with C#

    barcode addict: Actually it's more probable that you will get replies faster if you start new threads.

    The laziest possible thing you could do would be to just have the method that populates the textbox call the button's click event handler method (e.g. Button_Click(...)). Alternatively, you could just put the button click code on the end of the barcode scanner's event handler. If the barcode is read in character-by-character, you might need to do some sort of checking or validation to see when the complete code has been read.

    Simple enough?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  10. #10

    Re: Barcode scanner with C#

    Quote Originally Posted by BioPhysEngr View Post
    barcode addict: Actually it's more probable that you will get replies faster if you start new threads.

    The laziest possible thing you could do would be to just have the method that populates the textbox call the button's click event handler method (e.g. Button_Click(...)). Alternatively, you could just put the button click code on the end of the barcode scanner's event handler. If the barcode is read in character-by-character, you might need to do some sort of checking or validation to see when the complete code has been read.

    Simple enough?
    Thank you so so much! I will instantly give it a shot and check whether my client is satisfied. Really, thanks a lot!

  11. #11
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,834

    Re: Barcode scanner with C#

    That is actually covered in the post #6. Simply have the scanner append a CR to the end of the barcode then in the keypress event look for the CR and call the code to insert your record. Assuming of course you are talking about a Wedge type scanner I.E. one that mimics keyboard input. Other types of scanner interface such as serial would be a bit different but still simple if you are already getting a barcode from it.
    Last edited by DataMiser; February 18th, 2013 at 10:48 PM.
    Always use [code][/code] tags when posting code.

  12. #12

    Re: Barcode scanner with C#

    keydown or the keypress event is the best way to deal with it and simple, easy. Its also in the TextChanged method - check for the format you need for it to be a barcode and then do processing. Thats how it has to be done. There must be free barcode libs as wellt hat let you do more.

    --
    BossMode - http://bossware.blogspot.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center