我正在为Intermec CK3和CK30使用.NET CF 2.0开发应用程序。
我正在为应用程序的两个版本使用最新且相同版本的IntermecDataCollection,并使用相同的代码来读取条形码。
该应用程序在CK3(最新型号)上完美运行,但当我尝试使用CK30读取内容时,结果是与预期不同的代码。
Usuaaly有些字符出现在正确的代码前面,但在某些情况下,结果与原始字符完全不同。
已经成功的Googloed。
任何人都可以帮助我吗?
在CK3上工作但不在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;
}
}
}
}
答案 0 :(得分:1)
有些事情会浮现在脑海中。
首先,您的BarcodeReadEventHandler
可能无法保证一次性发送所有数据。
BarcodeReadEventHandler
解雇多项活动?换句话说,此代码可能不收集整个条形码:
void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
}
接下来,Trim()
和ToUpper()
可能会弄乱您的数据。您可以尝试删除这些内容以查看您的数据是否已清除。
您可能希望使用静态缓冲区来存储数据,这样您就可以确定显示所有已发送的内容。
我没有你的Intermec BarcodeReader控件,所以我无法测试和验证下面的代码,但这是我建议的方法。
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();
}
}
}