PosExplorer()。getDevices在.Net应用程序中返回null

时间:2014-09-20 09:59:43

标签: c# asp.net printing pos-for-.net

我正在使用.Net开发结算应用。我需要使用EPSON TM-T81打印收据。我已经安装了所有必需的驱动程序和MS POS v1.12。我可以通过CheckHealth Utility成功打印样本内容。所以看起来在PosPrinter配置中没有问题。但仍然PosExplorer()。getDevices返回null值。我在Windows和ASP.Net应用程序中都尝试了但仍然是同样的问题。 码: PosPrinter m_Printer = null;

        //<<<step1>>>--Start
        //Use a Logical Device Name which has been set on the SetupPOS.
        string strLogicalName = "PosPrinter";
        try
        {
            //Create PosExplorer
            PosExplorer posExplorer = new PosExplorer();

            DeviceInfo deviceInfo = null;

            try
            {
                deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter,strLogicalName);
                m_Printer =(PosPrinter)posExplorer.CreateInstance(deviceInfo);
            }
            catch(Exception)
            {
                ChangeButtonStatus();
                return;
            }

            //Open the device
            m_Printer.Open();

            //Get the exclusive control right for the opened device.
            //Then the device is disable from other application.
            m_Printer.Claim(1000);

            //Enable the device.
            m_Printer.DeviceEnabled = true;
        }
        catch(PosControlException)
        {
            ChangeButtonStatus();
        }
        //<<<step1>>>--End

1 个答案:

答案 0 :(得分:0)

如果这正是您尝试运行的代码,那么问题是strLogicalName不包含有效的SO或逻辑设备名称。 “PosPrinter”只是代码示例中的一个放置器(除非您明确设置了这样的逻辑名称)。

要查找系统中可用的SO名称/逻辑设备名称,请使用以下命令:

"C:\Program Files (x86)\Microsoft Point Of Service\posdm.exe" listdevices /type:PosPrinter

"C:\Program Files (x86)\Microsoft Point Of Service\posdm.exe" listnames /type:PosPrinter