你好可爱的社区!
我正在使用带有 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 手册中提供的一些控制字符,因此我决定转向 POS for .NET。
现在进入正题。我编写了一个具有基本功能和按钮的 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 的解决方案,但不幸的是我未能找到与我的问题的任何联系。
我从来没有编写过任何东西,所以我是一个新手,代码很糟糕,但我正在努力学习,所以如果有人愿意阐明这个问题,我将非常感激:)
最佳答案
您的机器可能连接有许多销售点设备(行显示器、POS 打印机、条形码扫描仪等)。所有这些设备都被分为所谓的类别(即,LineDisplay、PosPrinter、扫描仪等)。一个系统可能连接有同一类别的多个设备。例如,常规 POS 站上配备两台条形码扫描仪是很常见的 - 一台平板扫描仪用于扫描普通元素,手持式扫描仪用于扫描超大元素。
PosExplorer
类允许您枚举所有已安装的 POS 设备并实例化选定的设备。
explorer.GetDevices(DeviceType.LineDisplay)
返回系统上安装的所有线路显示的描述符。描述符以 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
)后,您可以使用它来实例化设备对象,该对象为您提供控制设备的实际接口(interface):
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]
访问它。对于第二个就不能说什么了。第三个是您真正的 HP 2x20 集成显示器,您可以使用 devColl[2]
描述符访问它。您可以使用 posdm
命令列出所有设备,如我上面所示。
关于c# - POS for .NET - 我的 C# 程序显示 "Microsoft LineDisplay Simulator"中的文本,而不是实际显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975642/