2

你好可爱的社区!

我正在使用带有 HP RP 7800 零售系统的 HP 2x20 集成显示器,并决定使用它并编写一些小程序让它学习编码。

SDK 提供的示例工具可以完美运行。

首先,我使用 Microsoft.IO.Ports 和简单的函数编写了一个简单的程序,如下所示:

SerialPort COM3 = new SerialPort("COM3", 9600, Parity.None, 8);
COM3.Open();
COM3.Write(Clear); // string Clear = "\x1B\x40" - hex value of a control character for the display
COM3.Write("Hello community");

它实际上工作正常,但我没有设法应用 HP 手册中提供的一些控制字符,因此我决定继续使用 .NET 的 POS。

所以现在直奔主题。我编写了一个具有基本功能和按钮的 C# 程序。

using Microsoft.PointOfService;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        LineDisplay lineDisplay;
        PosExplorer explorer;
        public Form1()

        {
            InitializeComponent();

            try
            {
                explorer = new PosExplorer(this);
                DeviceCollection devColl = explorer.GetDevices(DeviceType.LineDisplay); // is this line the problem?
                //DeviceCollection devColl = explorer.GetDevice("LineDisplay", "HPLCM220Display"); // this one shows errors so I couldnt use it instead of the line above
                if (devColl == null || devColl.Count <= 0)
                {
                    MessageBox.Show("Device not found");
                    return;
                }
                lineDisplay = (LineDisplay)explorer.CreateInstance(devColl[0]);
                lineDisplay.Open();
                lineDisplay.Claim(10000);
                lineDisplay.DeviceEnabled = true;
                lineDisplay.DisplayText("Hello World.!");
                lineDisplay.DisplayTextAt(1, 0, "Hey MSDN");


            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        private void btn_Clear_Click(object sender, EventArgs e)
        {
            lineDisplay.ClearText();
        }

        private void btn_SendText_Click(object sender, EventArgs e)
        {
            lineDisplay.DisplayText(textBox1.Text);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //this.textBox1.TextChanged -= textBox1_TextChanged;
        }
    }
}

当我启动它时,它会显示一个 LineDisplay Simulator,可以清除它并且可以更改文本,但真正的显示甚至不显示任何内容或被清除。 在此处输入图像描述

所以问题是:如何让我的应用程序在我的显示器而不是模拟器上显示文本。调试并没有真正帮助我。我注意到的是,在 AUTOS 中它在 LineDisplay Value 中显示 Microsoft.PointOfService.DeviceSimulators.LineDisplaySimulator 所以它以某种方式使用了 DeviceSimulators 但我不知道如何以及为什么.. 在此处输入图像描述

我将 POS 用于 .net 文档,但遗憾的是没有成功 https://msdn.microsoft.com/en-us/library/microsoft.pointofservice.linedisplay(v=winembedded.11).aspx

我认为它以某种方式存在 - 设备收集线

DeviceCollection devColl = explorer.GetDevices(DeviceType.LineDisplay);
//DeviceCollection devColl = explorer.GetDevice("LineDisplay", "HPLCM220Display");

但是如果我使用注释行而不是第一个 une 它会显示错误:

Error    CS0029    Cannot implicitly convert type 'Microsoft.PointOfService.DeviceInfo' to 'Microsoft.PointOfService.DeviceCollection'    WindowsFormsApplication14    C:\Users\admin\Documents\Visual Studio 2015\Projects\WindowsFormsApplication14\WindowsFormsApplication14\Form1.cs    27    Active

我试图寻找 CS0029 的解决方案,但不幸的是我未能找到与我的问题的任何联系。

我从来没有编程过任何东西,所以我是一个新手,代码很糟糕,但我正在努力学习,所以如果有人这么好心地阐明这个问题,我将非常感激:)

4

1 回答 1

2

您的机器可能连接了许多销售点设备(行显示器、POS 打印机、条形码扫描仪等)。所有这些设备都被分组为所谓的类(即 LineDisplay、PosPrinter、Scanner 等)。一个系统可能有多个属于一个类的设备。例如,在普通 POS 站上安装两个条码扫描仪是很常见的——一个用于扫描普通物品的平板扫描仪和一个用于扫描超大物品的手持式扫描仪。

该类PosExplorer允许您枚举所有已安装的 POS 设备并实例化选定的设备。

explorer.GetDevices(DeviceType.LineDisplay)系统上安装的所有行显示器的返回描述符。描述符在 type 的集合中返回DeviceCollection。此集合中的每个项目都有DeviceInfo类型。您可以遍历此集合,检查项目属性并选择一些以进行进一步操作。

explorer.GetDevice("LineDisplay", "HPLCM220Display")按类和名称返回确切设备的描述符(在"HPLCM220Display"您的情况下为行显示)。返回的描述符类型为DeviceInfo。这就是您遇到编译错误的原因 - 如果您使用正确的类,您将不会遇到它

DeviceInfo devInfo = explorer.GetDevice("LineDisplay", "HPLCM220Display");

请注意,第二个参数必须GetDevice()是设备的逻辑名称或别名。您可以通过以下命令列出这些名称:

"%ProgramFiles%\Microsoft Point Of Service\posdm.exe" ListNames /type:LineDisplay

或(在 x64 系统上):

"%ProgramFiles(x86)%\Microsoft Point Of Service\posdm.exe" ListNames /type:LineDisplay

找到DeviceInfo所需设备的描述符 ( ) 后,您可以使用它来实例化设备对象,该对象为您提供控制设备的实际接口:

lineDisplay = (LineDisplay)explorer.CreateInstance(devInfo);

因此,您的代码可能如下所示:

// ...
explorer = new PosExplorer(this);
DeviceInfo devInfo = explorer.GetDevice(DeviceType.LineDisplay, "HPLCM220Display");
if (devInfo == null)
{
    MessageBox.Show("Device not found");
    return;
}
lineDisplay = (LineDisplay)explorer.CreateInstance(devInfo);
lineDisplay.Open();
// ...

在您的评论中回答devColl[0]和回答问题:devColl[2]

您的系统显然至少安装了三行显示器。第一个是安装了 POS for .NET SDK 的虚拟显示设备。您通过devColl[0]. 不能说第二个。第三个是您使用devColl[2]描述符访问的真正的 HP 2x20 集成显示器。posdm您可以使用上面显示的命令列出所有设备。

于 2016-08-18T06:59:38.817 回答