Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
3.20/5 (5 votes)
See more:
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" };
        
        //Connection to WMI object
        public static ConnectionOptions oConn = new ConnectionOptions();
        
        //ManagementScope oMs = new ManagementScope("\\\\localhost",oConn);
        public static ManagementScope oMs = new ManagementScope("\\\\EDREN-THINK\\root\\cimv2", oConn);
            

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            oMs.Connect();

            //Query statement
            ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_Printer WHERE Name =\"EPSON EU-T300 Receipt\"");
            //ObjectQuery oQuery = new ObjectQuery("SELECT PrinterStatus FROM Win32_Printer WHERE Name =\"HP psc 2500 Series\"");

            //Execute
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);

            //Get Results
            ManagementObjectCollection oReturnCollection = oSearcher.Get();
                
            //Loop Through
            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?
Posted
Updated 16-Jan-12 1:36am
v3
Comments
Manfred Rudolf Bihy 16-Jan-12 7:36am    
Moved non-solution to OP's question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900