0

我正在为项目开发热敏收据打印机(ARP-990KE),我尝试使用以下代码打印发票,但在代码中GetDevice()给我错误值不能为空。参数名称:设备

       PosExplorer posExplorer = new PosExplorer(this);

       DeviceInfo receiptPrinterDevice = posExplorer.GetDevice("Generic/Text Only"); 
       return (PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice);  //  Here it gives me null 
4

1 回答 1

1

GetDevice 似乎对"Generic/Text Only"您传递它感到困惑。

PosExplorer.GetDevice(String)方法(即接受单个参数的方法)返回给定设备类的默认设备。设备类应该是类中的常量之一DeviceTypeDeviceType.PosPrinter在您的情况下)。这是GetDevice(String)期望的参数:

DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter);

请注意,如果您要使用此方法,请确保您已将打印机设置为默认值(或没有其他此类设备)。

您可能希望考虑使用更通用的替代方法。PosExplorer.GetDevice(String, String)在其第二个参数中接受设备名称,因此您不会仅绑定到默认设备:

DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter, <device name>);

<device name>可以 使用

"C:\Program Files (x86)\Microsoft Point Of Service\posdm.exe" listdevices /type:PosPrinter
于 2015-04-02T07:53:46.727 回答