0

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,...
tmccal2
  • 11
  • 3
  • We won't know how to make the changes to your existing code base without seeing your original code. Please post a [mre], and fully explain what needs to be modified. – gunr2171 Feb 20 '22 at 02:12
  • Code has been added to explain what I attempted to do. – tmccal2 Feb 20 '22 at 02:22

1 Answers1

0

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.

kunif
  • 4,060
  • 2
  • 10
  • 30