Barcode reading extra digits values in C# RRS feed

  • Question

  • Problem

    when read barcode scanner by c# and receive value of reading in variable

    msg it reading scanned ItemCode as 3300002266/r AND this value is wrong

    but when reading in notepad or text box it reading Item Code correct as  30026 .

    Why this extra digits read and how to make it read correct as 30026 ?

    my scanner reader data as below   :

    Barcode read 2d for Items 
    Barcode Device DataLogic Lite QW2100
    MODEL QY2100
    CLASS QY2120-BK
    S/N G17079019                                

    What I have tried:

     DateTime _lastKeystroke = new DateTime(0);
            List<char> _barcode = new List<char>(10);

    privatevoid Form1_KeyPress(object sender, KeyPressEventArgs e) { TimeSpan elapsed = (DateTime.Now - _lastKeystroke); if (elapsed.TotalMilliseconds >100) _barcode.Clear(); // record keystroke & timestamp _barcode.Add(e.KeyChar); _lastKeystroke = DateTime.Now; if (e.KeyChar == 13 && _barcode.Count >0) { string msg = newString(_barcode.ToArray()); MessageBox.Show(msg); _barcode.Clear(); } }

    Tuesday, September 11, 2018 2:15 AM

All replies

  • You forgot the important part: you're running the scanner as HID (Keyboard).

    In this case, you have two choices:

    1) no special codeing, the user is responsible to place the focus into the correct destination (TextBox).

    2) Change the scanner setup, so that it uses a special start and end of barcode marker (see its documentation). Then use a filter on the form. When the start marker was sent redirect any data to your barcode buffer until the end marker is received. Use also a timer to detect aborted communication.

    Tuesday, September 11, 2018 9:09 AM
  • Hello 

    Expected 30026

    ItemCode as 3300002266

    Something in your code simply double each char from device. Most likely you process it twice - once this do driver and second time yourself.

    You should look on KeyPressEventArgs.Handled and set it true if you do handle the key press.

    In my app I simply put all operations with scanner into BackgroundWorker and have only notification about "Line Scanned". 

    Best regards,


    Tuesday, September 11, 2018 11:17 AM
  • In my app I simply put all operations with scanner into BackgroundWorker and have only notification about "Line Scanned".

    But then you don't operate the scanner as HID, do you?

    Tuesday, September 11, 2018 12:18 PM
  • Thank you for reply

    In my app I simply put all operations with scanner into BackgroundWorker and have only notification about "Line Scanned". 

    can you send to me full sample or send to me full source code operations if possible 

    Tuesday, September 11, 2018 12:20 PM
  • Hello,


    Scanner are operated as HID, but I didn't interfere with his behaviour - I do copy data from the scanner (by the way - on the factory floor are more than 10 types of scanners) into internal package (string) and pass package (string) to the application when ready.

    I do not do anything with entering data from scanner into fields - this work completely separately.

    Best regards,


    Tuesday, September 11, 2018 1:19 PM
  • Hello, 

    It's a part of application and app. 30Mb of sources.

    But you need very simple part - inherit from BackgroundWorker, add an event for subscription and do very similar with what you doing in your key press handler, with triggering an event on "\r".

    So simple.

    Best regards,


    Tuesday, September 11, 2018 1:32 PM
  • How do you distinguish keyboard input from scanner input?
    Tuesday, September 11, 2018 2:48 PM
  • Hello Stefan,

    To whom was addressed your question?

    Best regards,


    Tuesday, September 11, 2018 3:17 PM
  • Hi Andrey Belyakov,

    Please try to the following code, which use LINQ to remove extra values.

    string test = "3300002266";
    string result = string.Join("", test.ToArray().Where((c, i) => i % 2 != 0));

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, September 12, 2018 2:00 AM
  • Hello Zhanglong,

    I didn't have problem with scanners.

    The TS have.

    His problem, however, not in how to dealing with consequences, but how to get proper data from device.

    Best regards,


    Wednesday, September 12, 2018 7:43 AM