Hi there I recently posted a post asking some help on requiring the status of a printer and managed to get that right. Although my next step is to find out if the printer is low on paper/out of paper. It is a POS printer, Epson EU-T300 Receipt.
The following code is what i currently have due to quite a bit of research but the detectederrorstate - which is the one that should say low/no paper, simply just returns a 0 which is "unknown". The printerstatus and extendedprinterstatus seem to be working fine.
My question is, what am i doing wrong that I cant get the detectederrorstate to change, or show me when there is no paper even when i take the paper out of the POS printer. Should i rather be using the POS framework?
Thanks
public partial class Form1 : Form
{
public int x = 0;
public string myString;
public int pStatus, dStatus, eStatus;
public string[] printerStatus = { "", "Other", "Unknown", "Idle", "Printing", "Warming Up", "Stopped Printing", "Offline" };
public string[] detectedErrorState = { "Unknown", "Other", "No Error", "Low Paper", "No Paper", "Low Toner", "No Toner", "Door Open", "Jammed", "Offline", "Service Requested", "Output Bin Full" };
public string[] extendedPrinterStatus = { "", "Other", "Unknown", "Idle", "Printing", "Warming Up", "Stopped Printing", "Offline", "Paused", "Error", "Busy", "Not Available", "Waiting", "Processing", "Initializing", "Power Save", "Pending Deletion", "I/O Active", "Manual Feed" };
public static ConnectionOptions oConn = new ConnectionOptions();
public static ManagementScope oMs = new ManagementScope("\\\\EDREN-THINK\\root\\cimv2", oConn);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
oMs.Connect();
ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_Printer WHERE Name =\"EPSON EU-T300 Receipt\"");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
lblCName.Text = oReturn["Name"].ToString();
lblPName.Text = oReturn["SystemName"].ToString();
lblPort.Text = oReturn["PortName"].ToString();
myString = oReturn["PrinterStatus"].ToString();
pStatus = Convert.ToInt32(myString);
lblPrinterStatus.Text = printerStatus[pStatus];
myString = oReturn["DetectedErrorState"].ToString();
dStatus = Convert.ToInt32(myString);
lblDetectedErrorState.Text = detectedErrorState[dStatus];
myString = oReturn["ExtendedPrinterStatus"].ToString();
eStatus = Convert.ToInt32(myString);
lblExtendedPrinterStatus.Text = extendedPrinterStatus[eStatus];
}
}
Just to add to this, I now know that this info is only retrieving from the printer driver. The problem is, the printer I have has a sensor that shows when it has no paper. When this sensor goes off I can't seem to get my program to acknowledge that this has happened. My program only realises that there is no paper left when it's physically impossible to print. This sensor goes off just before that happens. I'm not sure if the above code is the best option for me, I may have to use POS.net
Any comments?