首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Intermec CK30 BarcodeReader错误

Intermec CK30 BarcodeReader错误
EN

Stack Overflow用户
提问于 2013-04-12 02:44:16
回答 1查看 1.4K关注 0票数 1

我正在为Intermec CK3和CK30开发一个使用.NET CF 2.0的应用程序。

我在两个版本的应用程序上都使用了最新的相同版本的IntermecDataCollection,读取条形码的代码也是相同的。

这个应用程序在CK3 (newst模型)上工作得很好,但是当我尝试使用CK30读取一些东西时,结果是一个与预期不同的代码。

通常,一些字符出现在正确的代码前面,但在某些情况下,结果与原始代码完全不同。

已经在Googlo上获得了成功。

有谁可以帮我?

在CK3上工作而不是在CK30上工作的代码示例:

代码语言:javascript
复制
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;
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-13 00:03:54

脑海中浮现出几件事。

首先,您的BarcodeReadEventHandler可能无法保证一次发送所有数据。

  • 如何处理BarcodeReadEventHandler触发多个事件?

换句话说,此代码可能不会收集整个条形码:

代码语言:javascript
复制
void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
  tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
}

接下来,Trim()ToUpper()可能会弄乱你的数据。你可以试着删除它们,看看你的数据是否被清除了。

您可能希望使用静态缓冲区来存储您的数据,这样您就可以确定您正在显示所发送的所有内容。

我没有你的Intermec BarcodeReader控件,所以我不能测试和验证works下面的代码,但这是我建议的方法。

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15956431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档