2015-02-08 58 views
0

我正在为热敏收据打印机(ARP-990KE)进行项目打印,但代码为GetDevice()给我错误Value can not是null.Parameter名称:设备PosExplorer.GetDevice()在C#.net Windows窗体中返回总是为空应用

 PosExplorer posExplorer = new PosExplorer(this); 

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

回答

1

的似乎的getDevice被混淆的"Generic/Text Only"你传递它。

PosExplorer.GetDevice(String)方法(即接受单个参数的方法)返回给定设备类的默认设备。设备类应该是DeviceType类(您的情况为DeviceType.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