3
votes

I am making a program that talks to an Epson TM-T88IV printer using ESC/POS commands through a socket in C#. When I send an DLE EOT n command with the cover closed and the paper full it returns the correct code immediately in a byte array. However, when I open the cover or take the paper out to try to emulate an error no DLE EOT commands (1, 2, 3, or 4) will return anything. The socket.receive method just hangs until it times out. I am able to print to this printer and do line feeds, cuts, etc.

Here is my code:

public class clsPrinter
{
  TcpListener server;
  MemoryStream ms = new MemoryStream();
  BinaryWriter bw;
  Socket clientSock = new Socket(AddressFamily.InterNetwork,
                                 SocketType.Stream, 
                                 ProtocolType.Tcp);
  string printerIP;
  Encoding enc = Encoding.ASCII;


  public clsPrinter(string printerIP)
  {
    this.printerIP = printerIP;
    bw = new BinaryWriter(ms);
    clientSock.NoDelay = true;
    clientSock = new Socket(AddressFamily.InterNetwork,
                            SocketType.Stream, 
                            ProtocolType.Tcp);
    IPAddress ip = IPAddress.Parse(printerIP);
    IPEndPoint remoteEP = new IPEndPoint(ip, 9100);
    clientSock.Connect(remoteEP);
  }

  public void getPrinterStatus()
  {
    try
    {
      byte[] byData = new byte[] { 16, 4, 1 }; // DLE EOT 1
      sendToPrinter(byData);

      byte[] bytes = new byte[1024];
      int bytesReceived = clientSock.Receive(bytes);
    }
    catch (Exception ex)
    {
    }

  }

  public void sendToPrinter(byte[] byteStream)
  {
    clientSock.Send(byteStream);
  }

Any ideas?

3

3 Answers

2
votes

The printer is in out of ready state as a cover opened or paper out. I think the method(or printer driver) just can't send DLE EOT X to the printer which has no ready state.

2
votes

Printer will only reply to DLE EOT if it is online unless you are using an old serial interface.

I could not find such information in Epson's online documents, though, but you can read about it in the document available at w3m Escpos Guide, slide 414.

Please see also mike42 commented on 2 Aug 2015:

I think DLE EOT has limited usefulness: It returned objects characters containing all the correct status flags if the printer had just been rebooted (and not yet printed any output). For a printer that had been printing, it worked properly only if the printer was in an online state. Otherwise, responses hung until the printer came online (ie, the user closed the cover or replaced the paper).

If you are using a modern interface like Ethernet or USB, you can give ASB a try.


NOTE:

I know this question is somewhat old but since I faced the same problem and Google told me that several other people also, I think it is worth sharing what I've learnt.

1
votes

Copied from this comment:

Regarding DLE EOT (real-time status): on the TM-T20II (though I am sure this works for many Epsons), if you turn on memory switch 1-3 (which sets "BUSY condition" to "receive buffer full" from "receive buffer full or offline"), the printer will respond to DLE EOT at all times, including when the cover is open or it's out of paper.

According to the manual, the printer goes into "offline" mode in the following cases:

  • During power on until the printer is ready
  • During the self-test
  • While roll paper is fed using the Feed button
  • When the roll paper cover is open
  • When the printer stops printing due to a paper end
  • During a macro execution standby state
  • When an error has occurred

So the setting change above makes it "not BUSY" when in these states.