简体   繁体   English

C#CUSTOM VKP80获取打印机状态

[英]C# CUSTOM VKP80 get printer status

I am trying to get the printer status for CUSTOM VKP80II printer. 我正在尝试获取CUSTOM VKP80II打印机的打印机状态。 But the value of each property stays the same as the initial state even when their is no paper or the cap is opened. 但是,即使它们没有纸或没有打开盖子,每个属性的值仍保持与初始状态相同。 How to make this code work to get the printer status? 如何使此代码起作用以获取打印机状态?

PrintDialog pd = new PrintDialog();
PrintQueue queue = new PrintServer().GetPrintQueue("CUSTOM VKP80 II");
pd.PrintQueue = queue;
...
// transform window to ticket format
...
pd.PrintVisual(ticket, "print");


    string printerName = "CUSTOM VKP80 II";
    string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName);

        using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
        using (ManagementObjectCollection coll = searcher.Get())
        {
            try
            {
                foreach (ManagementObject printer in coll)
                {
                    foreach (PropertyData property in printer.Properties)
                    {
                        Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
                    }
                }
            }
            catch (ManagementException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

Solved by installing STATUS MONITOR plugin from CUSTOM https://www.custom4u.it/pages/product/index.php . 通过从CUSTOM https://www.custom4u.it/pages/product/index.php安装STATUS MONITOR插件来解决。

(CePrnStatusMonitor - Status monitor plugin to get printer status from Windows "PRINTER_INFO" structure) (CePrnStatusMonitor-状态监视器插件,用于从Windows“ PRINTER_INFO”结构获取打印机状态)

So to check if printer almost out of paper: 因此,检查打印机是否几乎没纸了:

Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
if(proprty.Name == "DetectedErrorState")
    if(property.Value == 3)
        Console.WriteLine("Printer almost out of paper");

DetectedErrorState values: DetectedErrorState值:

Unknown (0)
Other (1)
No Error (2)
Low Paper (3)
No Paper (4)
Low Toner (5)
No Toner (6)
Door Open (7)
Jammed (8)
Offline (9)
Service Requested (10)
Output Bin Full (11)

https://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/library/aa394363(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM