Printing directly to a thermal printer using ESC/POS Commands executed in C# with an interface of TCP/IP

后端 未结 1 552
迷失自我
迷失自我 2020-12-29 14:21

I was working on implementing ESC/POS(Epson Standard Code for Point of Sale) on a Kitchen printer(Aclas KP71M).
I have a user interface the the POS user enters its str

相关标签:
1条回答
  • 2020-12-29 15:00

    Answering this question in case anyone else comes along with the same q. This is what worked for me:

    Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    clientSock.NoDelay = true;
    IPAddress ip = IPAddress.Parse("192.168.0.18");
    IPEndPoint remoteEP = new IPEndPoint(ip, 9100);
    clientSock.Connect(remoteEP);
    Encoding enc = Encoding.ASCII;
    
    // Line feed hexadecimal values
    byte[] bEsc = new byte[4];
    bEsc[0] = 0x0A;
    bEsc[1] = 0x0A;
    bEsc[2] = 0x0A;
    bEsc[3] = 0x0A;
    
    // Send the bytes over 
    clientSock.Send(bEsc);
    
    // Sends an ESC/POS command to the printer to cut the paper
    string output = Convert.ToChar(29) + "V" + Convert.ToChar(65) + Convert.ToChar(0);
    char[] array = output.ToCharArray();
    byte[] byData = enc.GetBytes(array);
    clientSock.Send(byData);
    clientSock.Close();
    
    0 讨论(0)
提交回复
热议问题