Reputation: 760
I am trying to get the printer status for CUSTOM VKP80II printer. 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);
}
}
Upvotes: 1
Views: 2806
Reputation: 760
Solved by installing STATUS MONITOR plugin from CUSTOM https://www.custom4u.it/pages/product/index.php.
(CePrnStatusMonitor - Status monitor plugin to get printer status from Windows "PRINTER_INFO" structure)
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:
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
Upvotes: 1