Question

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;
            }
        }
    }
}
Was it helpful?

Solution

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();
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top