C# 使用收据打印机

C# 使用收据打印机,c#,winforms,printing,C#,Winforms,Printing,我正在开发一个应用程序,其中一个模块是收据打印。 我已经为打印机编写了代码,但是当我执行程序时,我的一个方法出现了异常。这是我得到异常的代码 打印机:PMX热敏收据打印机 型号:PMX 80220 private PosPrinter GetReceiptPrinter() { PosExplorer posExplorer = new PosExplorer(this); DeviceInfo receiptPrinterDevice = po

我正在开发一个应用程序,其中一个模块是收据打印。 我已经为打印机编写了代码,但是当我执行程序时,我的一个方法出现了异常。这是我得到异常的代码

打印机:PMX热敏收据打印机 型号:PMX 80220

private PosPrinter GetReceiptPrinter()
{
    PosExplorer posExplorer = new PosExplorer(this);                 
    DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter, "MYPRINTER");
    return (PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice); //Here I am getting an exception "ArgumentNullException"        
}

这里好像是这一行
DeviceInfo-receiptPrinterDevice=posExplorer.GetDevice(DeviceType.PosPrinter,“MYPRINTER”)返回空值。确保他的行实际返回DeviceInfo。

进行测试以查看receiptPrinterDevice==null,它可能无法使用posExplorer获取设备。GetDevice确保“MYPRINTER”是“设备和打印机”中安装的打印机的实际名称