'Scanner misread with SerialPort class
time to time scanner are misreading barcodes. barcodes are in AN 8 standard. after scanning barcode it showing not the exact one but some from already scanned in the past. check sum is enabled. Reader service is up on linux
var serialPort = sender as SerialPort;
var barcode = serialPort.ReadExisting();
var lastBarcode = barcode.Split(Environment.NewLine, StringSplitOptions.TrimEntries).LastOrDefault();
this way i get lastScanned barcode and queuing the results
Solution 1:[1]
Serial port communication is non-procedural communication in units of one character (usually byte) and does not correspond to the specifications of the barcode scanner.
One barcode notification may be divided into multiple reads, one read may notify multiple barcodes, and one read data may not match the beginning and end of the barcode format.
As commented, you need to check all the data you receive, determine if it follows the format notified by the barcode scanner and cut it out.
And if you decide to discard the data that does not follow the format, or if you decide that you have not received all the data yet, you need to save it in a buffer, concatenate it with the next notified data, and then check it again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kunif |
