Windows mobile Intermec CK30条形码阅读器错误
我正在为Intermec CK3和CK30开发一个使用.NET CF 2.0的应用程序 我在两个版本的应用程序中都使用了最新和相同版本的IntermecDataCollection,在读取条形码时使用了相同的代码 该应用程序在CK3(newst模型)上运行得非常好,但当我尝试使用CK30读取某些内容时,结果是代码与预期的不同 通常,某些字符出现在正确的代码前面,但在某些情况下,结果与原始代码完全不同 已经因成功而沾沾自喜 有人能帮我吗 在CK3上工作而不是在CK30上工作的代码示例:Windows mobile Intermec CK30条形码阅读器错误,windows-mobile,compact-framework2.0,intermec,Windows Mobile,Compact Framework2.0,Intermec,我正在为Intermec CK3和CK30开发一个使用.NET CF 2.0的应用程序 我在两个版本的应用程序中都使用了最新和相同版本的IntermecDataCollection,在读取条形码时使用了相同的代码 该应用程序在CK3(newst模型)上运行得非常好,但当我尝试使用CK30读取某些内容时,结果是代码与预期的不同 通常,某些字符出现在正确的代码前面,但在某些情况下,结果与原始代码完全不同 已经因成功而沾沾自喜 有人能帮我吗 在CK3上工作而不是在CK30上工作的代码示例: using
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;
}
}
}
}
我想到了几件事 首先,您的
BarcodeReadEventHandler
可能无法保证一次发送所有数据
- 如何处理触发多个事件的
BarcodeReadEventHandler
void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
}
接下来,Trim()
和ToUpper()
可能会弄乱您的数据。您可以尝试删除这些,以查看您的数据是否已清除
您可能希望使用静态缓冲区来存储数据,这样您就可以确定您正在显示发送的所有内容
我没有您的Intermec条形码阅读器控制,因此我无法测试和验证下面的代码是否有效,但这是我建议的方法
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();
}
}
}
private const int BARCODE_BEGIN='\u001C';//我们的设备以带有文件分隔符的条形码开始
private const int BARCODE_END='\u000A';//我们的设备设置为发送线路馈送
私有常量int MAX_BUFFER=1024;//设置为任何你想要的
私有常量int NULL_CHAR='\u0000';
专用静态字节[]缓冲区;
公共条形码阅读器;
公共区域5(内部区域Selecionada、内部tipoOT、long nlenr、内部qtdEtq)
{
初始化组件();
//实例化条形码读取器类。
model.LeitorCodigoDeBarras classeLeitor=新模型.LeitorCodigoDeBarras();
leitor=classeLeitor.LerCodigoDeBarras();
leitor.BarcodeRead+=新的BarcodeReadEventHandler(this.eventoLeitorCodigoDeBarras);
ResetBuffer();
}
私有void ResetBuffer()
{
缓冲区=新字节[最大缓冲区];
对于(int i=0;i
我想到了几件事
首先,您的BarcodeReadEventHandler
可能无法保证一次发送所有数据
- 如何处理触发多个事件的
BarcodeReadEventHandler
void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
tbMaterial.Text = e.strDataBuffer.Trim().ToUpper();
}
接下来,Trim()
和ToUpper()
可能会弄乱您的数据。您可以尝试删除这些,以查看您的数据是否已清除
您可能希望使用静态缓冲区来存储数据,这样您就可以确定您正在显示发送的所有内容
我没有您的Intermec条形码阅读器控制,因此我无法测试和验证下面的代码是否有效,但这是我建议的方法
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();
}
}
}
private const int BARCODE_BEGIN='\u001C';//我们的设备以带有文件分隔符的条形码开始
private const int BARCODE_END='\u000A';//我们的设备设置为发送线路馈送
私有常量int MAX_BUFFER=1024;//设置为任何你想要的
私有常量int NULL_CHAR='\u0000';
专用静态字节[]缓冲区;
公共条形码阅读器;
公共区域5(内部区域Selecionada、内部tipoOT、long nlenr、内部qtdEtq)
{
初始化组件();
//实例化条形码读取器类。
model.LeitorCodigoDeBarras classeLeitor=新模型.LeitorCodigoDeBarras();
leitor=classeLeitor.LerCodigoDeBarras();
leitor.BarcodeRead+=新的BarcodeReadEventHandler(this.eventoLeitorCodigoDeBarras);
ResetBuffer();
}
私有void ResetBuffer()
{
缓冲区=新字节[最大缓冲区];
对于(int i=0;i
Plus许多读卡器可以配置为在硬件级别插入前缀和后缀,因此读卡器的配置可能不同。对于每个条形码,barcoderead事件始终只触发一次。如果缓冲区(4096)太小,则到达事件的条形码数据被截断。CK30和CK3的内部条形码读取器配置可能不同。例如,一个配置为使用AIM条形码类型ID,另一个配置为不使用。条形码ID(AIM)以“^”开头,您会看到哪些特殊字符?intermec条形码阅读器参数还提供DataBuffer中的二进制数据和BytesInBuffer中的一段缓冲区。如果您阅读EAN128条形码,它们可能包含控制字符as(也称为FNC1)。还有一个提示:请在设备上张贴您看到的条形码图像和样本数据。可能有一种模式我们知道。提示2:当您在m中使用条形码阅读器时