【问题标题】:POS for .NET Scanner: Handling Binary Data.NET 扫描仪的 POS:处理二进制数据
【发布时间】:2022-02-20 11:25:35
【问题描述】:

如果条形码包含二进制数据,我将如何使用 Scanner 的 DataEvent 读取数据?

当我从 ScanDataLabel 读取数据时,我在数组的某些部分的数据字节之间得到了额外的 0,而其他部分似乎没有受到影响。我尝试将它们编码为 ASCII 和 Unicode,但无济于事。

我正在为此应用程序使用 Honeywell 1900 手持式条码扫描器。

下面是我尝试的代码:

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

数据应该是,例如

{220,3 ...

但包含

{220,0,3,0 ...

上面尝试的代码有以下,这是不正确的

{120,...

【问题讨论】:

  • 如果没有看到您的原始代码,我们将不知道如何对您现有的代码库进行更改。请发minimal reproducible example,并详细说明需要修改的地方。
  • 已添加代码来解释我试图做什么。

标签: c# .net pos pos-for-.net honeywell


【解决方案1】:

这可能是因为您使用Lagacy COM Interop 来运行OPOS 服务对象。
POS for .NET Architecture (POS for .NET v1.12 SDK Documentation)
Integration of Legacy Service Objects (POS for .NET v1.12 SDK Documentation)

本文中描述的ILegacyControlObject.BinaryConversion 设置是相关的。
PosPrinter PrintMemoryBitmap throws illegal exception

您可能希望在读取扫描仪的ScanDataScanDataLabel 属性之前将ILegacyControlObject.BinaryConversion 设置为NibbleDecimal,并在读取后将其设置为None

但是,假设霍尼韦尔的 OPOS 服务对象支持BinaryConversion 规范。

而读取的数据是byte[]的二进制数据,可以直接处理,不需要Encoding.GetBytes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-01
    • 2010-11-23
    • 2012-08-24
    • 2019-06-12
    • 2011-07-12
    • 2020-09-05
    • 2017-05-30
    • 2019-05-05
    相关资源
    最近更新 更多