Click here to Skip to main content
14,325,129 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to check printer status using cpcl commands in c#.

below my code.

public static string PrinterStatus(string printerIp)
    IPAddress ip = IPAddress.Parse(printerIp)
    System.Net.Sockets.TcpClient client = new                   System.Net.Sockets.TcpClient();
    client.Connect(printerIp, 6101);
     byte[] bt = new byte[] { (byte)27, (byte)104 };  //esc(27) h(104)
     NetworkStream netStream = client.GetStream();
    netStream.Write(bt, 0, bt.Length);
    byte[] bytesToRead = new byte[client.ReceiveBufferSize];
    client.SendTimeout = 2000;
        int bytesRead = netStream.Read(bytesToRead, 0,   client.ReceiveBufferSize);
     if(bytesToRead[0] == 16)
     return "Printer Ready";
     else if (bytesToRead[0] == 17)
      return "Printer Busy";
     else if (bytesToRead[0] == 18)
     return "Paper Out";
      else if (bytesToRead[0] == 5 || bytesToRead[0] == 20)
      return "Head Open & Paper out";

What I have tried:

i am trying to pass esc h to toshiba network label printer to check printer status. printer is on or off,cover open, head open, paper out, low battery and etc.

I am not getting any status. bytesToRead should return some value to give printer status. but it is always returning zero only. 

help me.
Updated 22-Aug-17 19:43pm
Michael_Davies 23-Aug-17 1:42am
Have you opened the cover or removed the paper to create a state other than okay then tried reading the status?
Member 8235434 23-Aug-17 1:47am
yes i just opened the cover and i tested the code. but no status ..
Karthik_Mahalingam 28-Aug-17 1:17am
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100