首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microsoft C# -获取DeviceInfo中的零值

Microsoft C# -获取DeviceInfo中的零值
EN

Stack Overflow用户
提问于 2015-06-09 16:47:35
回答 1查看 1.3K关注 0票数 0

当尝试初始化并在POS收据打印机上打印时,我的程序抛出一个ArgumentNullExeption,说明“设备”参数不能为null。下面是代码:

代码语言:javascript
复制
PosExplorer posExplorer = new PosExplorer();
DeviceCollection receiptPrinterDevices = posExplorer.GetDevices(DeviceType.PosPrinter);
DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter, "POS58");
PosPrinter printer = (PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice);

printer.Open();
printer.Claim(5000);
printer.DeviceEnabled = true;
printer.PrintNormal(PrinterStation.Receipt, cmds);
printer.DeviceEnabled = false;

有什么解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2015-06-09 16:55:31

假设错误在这一行上:

代码语言:javascript
复制
PosPrinter printer = (PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice);

然后问题是GetDevice返回null。这意味着你所要求的东西对系统是不可用的。

这可能有很多原因。我会查看你的receiptPrinterDevices集合,看看你想要得到的东西是否在里面。如果是的话,你需要弄清楚为什么你没有正确地引用它。例如,请注意,GetDevice的第二个参数(传入"POS58"的地方)需要是设备的逻辑名称,而不是服务名称(从文档中:“在使用GetDevice之前,必须使用PosDm.exe或WMI为设备配置逻辑名称。您不能传递logicalName的服务对象名称”),另一方面,如果设备不在集合中,那么您需要找出原因--没有插入,配置不正确,在只有x86服务对象时运行为x64,等等。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30738167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档