If a barcode contains binary data, how would I be able to read the data using the Scanner's DataEvent?
When I read from ScanDataLabel, I get extra 0s between data bytes in some parts of the array while the others seem to be untouched. I have tried encoding them to ASCII and Unicode to no avail.
I am using a Honeywell 1900 handheld barcode scanner for this application.
Below is the code that I attempted:
static void Main(string[] args)
{
var explore = new PosExplorer();
var devices = explore.GetDevices(DeviceType.Scanner);
var device = explore.GetDevice(DeviceType.Scanner, "POSScanner");
var scan = (Scanner)explore.CreateInstance(device);
scan.Open();
scan.Claim(500);
scan.DeviceEnabled = true;
scan.DataEventEnabled = true;
scan.DecodeData = true;
scan.DataEvent += delegate (object sender, DataEventArgs e){
var data = scan.ScanDataLabel;
var type = scan.ScanDataType.ToString();
var encoder = Encoding.Unicode;
var dataString = encoder.GetString(data);
var rawData = Encoding.ASCII.GetBytes(dataString);
};
Console.ReadLine();
scan.DeviceEnabled = false;
scan.Release();
scan.Close();
}
The data should be, for example
{220,3 ...
but instead contains
{220,0,3,0 ...
and the attempted code above has the below, which is incorrect
{120,...
It's probably because you're using Lagacy COM Interop
to run OPOS service objects.
POS for .NET Architecture (POS for .NET v1.12 SDK Documentation)
Integration of Legacy Service Objects (POS for .NET v1.12 SDK Documentation)
The ILegacyControlObject.BinaryConversion
setting described in this article is relevant.
PosPrinter PrintMemoryBitmap throws illegal exception
You may want to set ILegacyControlObject.BinaryConversion
to Nibble
or Decimal
before reading the ScanData
or ScanDataLabel
properties of the scanner, and set it to None
after reading.
However, it is assumed that Honeywell's OPOS service object supports the BinaryConversion
specification.
And the read data is binary data of byte[]
, you can handle it as it is, and you do not need to Encoding.GetBytes
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.