我正在尝试获取CUSTOM VKP80II打印机的打印机状态。但是,即使它们没有纸或没有打开盖子,每个属性的值仍保持与初始状态相同。如何使此代码起作用以获取打印机状态?
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);
}
}
答案 0 :(得分:0)
通过从CUSTOM https://www.custom4u.it/pages/product/index.php安装STATUS MONITOR插件解决。
(CePrnStatusMonitor-状态监视器插件,用于从Windows“ PRINTER_INFO”结构获取打印机状态)
因此要检查打印机是否几乎没纸了:
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值:
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