0
votes

I have a USB to RS232 adapter and I was using it to get a long input (28 chars) from a barcode reader. Everything works fine in my computer.

I installed my c# application on other computer that has RS232 Serial Port connected to its PCI-E and when I'm receiving the input from the barcode reader, it splits it into two parts!

How do I know that? Because I have an event handler for DataReceived on my c# application, and it's being called 2 times, and each time I get a part of the input.

The RS232 PCI-E ports are manufacturer by Oxford Semiconductor Inc.

OS is Windows 7.

I'm assuming it's a hardware issue and not a problem in my application.. Maybe some settings to change, a buffer size or something like that but I could't find something like that.

Thanks in advanced!

1

1 Answers

3
votes

No, it is your application. You shouldn't expect all of the data to be immediately available; you were getting lucky on the first machine. You need to call Read() until you get everything you expect.

Differences in the UARTs, drivers, etc. can cause windows to raise that event multiple times, depending on timing and other factors.

Something along these lines:

char buf[28];
int offset = 0;
int nread;
while (offset < buf.Length) {
    nread = comPort.Read(buf, offset, buf.Length - offset);
    offset += nread;
}