1

I`m developing a application using .NET CF 2.0 for both Intermec CK3 and CK30.

I`m using the latest and same version of the IntermecDataCollection for both versions of the app and the same code for reading barcodes.

The application works perfectly on CK3 (newst model) but when I try to read something using CK30 the result is a code different from the expected.

Usuaaly some characters appear in front of the correct code, but in some cases the result is totally different from the original.

Already Googloed with success.

Can anyone help me?

Sample of code working on CK3 and not on CK30:

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

using WOPT_Coletor.ConectorWOPT;

using Intermec.DataCollection;


namespace WOPT_Coletor.view.CriarOT
{
    public partial class frmCriarOT_5 : Form
    {

        public BarcodeReader leitor;

        public frmCriarOT_5(int areaSelecionada, int tipoOT, long nlenr, int qtdEtq)
        {
            InitializeComponent();


            //Instanciete the barcode reader class.
            model.LeitorCodigoDeBarras classeLeitor = new model.LeitorCodigoDeBarras();
            leitor = classeLeitor.LerCodigoDeBarras();
            leitor.BarcodeRead += new BarcodeReadEventHandler(this.eventoLeitorCodigoDeBarras);


        }

        void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
        {
            tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
        }

       }
}


using System;

using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using Intermec.DataCollection;

namespace WOPT_Coletor.model
{
    class LeitorCodigoDeBarras
    {
        public BarcodeReader LerCodigoDeBarras()
        {
            try
            {
                BarcodeReader meuLeitor = new BarcodeReader("default", 4096);
                meuLeitor.ScannerEnable = true;
                meuLeitor.ThreadedRead(true);

                return meuLeitor;
            }
            catch (BarcodeReaderException bx)
            {
                MessageBox.Show("Não foi possível inicializar o leitor de código de barras. Contate seu supervisor. \n" + bx.Message, "Erro", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                return null;
            }
        }
    }
}
Andrew
  • 134
  • 1
  • 17

1 Answers1

1

A few things come to mind.

First, your BarcodeReadEventHandler is likely not guaranteed to send all of the data in one pass.

  • How do you handle your BarcodeReadEventHandler firing multiple events?

In other words, this code may not be collecting the entire barcode:

void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
  tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
}

Next, Trim() and ToUpper() could be messing up your data. You might try removing those to see if your data clears up.

You may want to use a static buffer to store your data in, that way you know for certain that you are showing everything that is sent in.

I do NOT have your Intermec BarcodeReader control, so I can not test and verify the code below works, but it is the approach I would suggest.

private const int BARCODE_BEGIN = '\u001C'; // our devices start a barcode with a File Separator
private const int BARCODE_END = '\u000A'; // our devices are set to send a Line Feed
private const int MAX_BUFFER = 1024; // set to whatever you want
private const int NULL_CHAR = '\u0000';
private static byte[] buffer;
public BarcodeReader leitor;

public frmCriarOT_5(int areaSelecionada, int tipoOT, long nlenr, int qtdEtq)
{
  InitializeComponent();
  //Instanciete the barcode reader class.
  model.LeitorCodigoDeBarras classeLeitor = new model.LeitorCodigoDeBarras();
  leitor = classeLeitor.LerCodigoDeBarras();
  leitor.BarcodeRead += new BarcodeReadEventHandler(this.eventoLeitorCodigoDeBarras);
  ResetBuffer();
}

private void ResetBuffer()
{
  buffer = new byte[MAX_BUFFER];
  for (int i = 0; i < MAX_BUFFER; i++) {
    buffer[i] = NULL_CHAR;
  }
}

void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
  byte[] data = Encoding.UTF8.GetBytes(e.strDataBuffer);
  int buffIndex = 0;
  for (int i = 0; i < MAX_BUFFER; i++) {
    if (buffer[i] == NULL_CHAR) {
      buffIndex = i;
      break;
    }
  }
  for (int i = 0; (i < data.Length) && (i < MAX_BUFFER); i++) {
    byte c = data[i];
    if (c != BARCODE_END) {
      buffer[i + buffIndex] = c;
    } else {
      tbMaterial.Text = Encoding.UTF8.GetString(buffer, buffIndex, i);
      ResetBuffer();
    }
  }
}
  • 1
    Plus many readers can be configured to insert prefixes and suffixes at the hardware level, so it could be that the readers are configured differently. – ctacke Apr 12 '13 at 16:29
  • 2
    The barcoderead event will always be fired only once for each barcode. If the buffer (4096) is too small, the barcode data coming to the event is truncated. Internal Barcode Reader configuration may differ for CK30 and CK3. For example one is configured to use AIM barcode type ID and the other not. Barcode IDs (AIM) start with ^], which may what you see a special chars? The intermec barcode reader args also provide the binary data in DataBuffer and a lenghth of buffer in BytesInBuffer. If you read EAN128 barcodes, they may contain control chars as (also called FNC1). – josef Apr 14 '13 at 06:49
  • 1
    One more hint: Please post barcode image and sample data you see on the devices. Possibly there is a pattern we know. HINT 2: as you use the barcode reader possibly in multiple forms, change your barcodereader init code a Singleton. The intermec barcode reader supports only one instance per app. – josef Apr 14 '13 at 06:53
  • Josef`s hint solved the problem: it was the AIM barcode type ID config that was making the sufix to appear. I changed it to disabled an it solved the problem! Tks a lot! – Andrew Apr 17 '13 at 11:25