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();
}
}
}