javac#printingthermal-printerprinter-control-language

Toshiba thermal Printer(B-EP4DL) command code, issue in JAVA


I have been stuck on this print command code related to Toshiba printer, here based on the previous C# code im trying to write the same in Java, where I'm unable to figure out where I'm doing wrong where the Toshiba printer is giving me an error

"??AY;-00,1"

.

If I try to change the ESC sequence format then it will print the all data as a Text(not as expected).

Kindly help me with this query, I'm stuck with this Printer related command code.

Printer Model : Toshiba thermal printer B-EP4DL

Document reffered :

https://www.toshibaprinters.com/technical_information/programmermanuals/B415%20programmers%20guide%205th.pdf

Other reference : https://www.toshibaprinters.com/technical_information/programmermanuals/B415%20programmers%20guide%205th.pdf

https://www.manualslib.com/manual/579619/Toshiba-B-Sx4t-Series.html?page=103#manual

Decimal value for byte[n] = https://bournetocode.com/projects/GCSE_Computing_Fundamentals/pages/3-3-5-ascii.html

DataOutputStream outToPrt = new DataOutputStream(prtSocket.getOutputStream());


        outToPrt.writeUTF("\u001bD1780,0140,1600\n\u0000");
        outToPrt.writeUTF("\u001bAY;+20,1\n\u0000");
        outToPrt.writeUTF("\u001bC\n\u0000");

        outToPrt.writeUTF("\u001bD0715,1040,0635\n\u0000");
        outToPrt.writeUTF("\u001bAY;-00,1\n\u0000");
        outToPrt.writeUTF("\u001bAX;+012\n\u0000");
        outputStreamWriter.write("\u001bC\n\u0000");


        // send printer formatting sequence
        outToPrt.writeUTF("\u001bPC00;0030,0015,1,1,G,00,B,00,1,0\n\u0000");             // Blank
        outToPrt.writeUTF("\u001bPC01;0010,0145,3,3,S,00,B,00,1,0\n\u0000");                // Scan Date & Time


        outToPrt.writeUTF("\u001bPV03;0010,0390,0130,0210,B,00,B,00,1,0\n\u0000");      

        outToPrt.writeUTF("\u001bPV04;0365,0360,0175,0275,B,00,B,00,1,0\n\u0000");      

        outToPrt.writeUTF("\u001bPV05;0450,0440,0070,0080,B,00,W,00,1,0\n\u0000");     

        outToPrt.writeUTF("\u001bXB07;0055,0460,9,3,03,0,0060,000,0,00,1,0\n\u0000");   // Barcode (Code 128)

        outToPrt.writeUTF("\u001bPC06;0010,0575,2,2,S,00,B,00,1,0\n\u0000");                

        outToPrt.writeUTF("\u001bPC08;0800,0575,2,2,S,00,B,00,1,0\n\u0000");                


        //tell printer end of formatting sequence
        outToPrt.writeUTF("\u001bXP\n\u0000");

        // send the remote machine name

        outToPrt.writeUTF(String.format("\u001b\u0058\u0000\u0000\u0001%1$s\n%2$s\n%3$s\n%4$s\n%5$s\n%6$s\n%7$s\n%8$s - %9$s - %10$s\n%11$s\n\u0000",
                "",                   // Blank  {0}
                "26Apr22 11:40",           
                "023 Data",        
                "ABC",            
                "AB-06",               
                "Print-Mode",        // Mode
                "1234567890",        // barcode
                "319241",     
                "HAP2211461",      
                "3.0.1",   
                "aprday0329c"));
//         flush all writes
        outToPrt.flush();

C# Code for reference :

private void toshibaPrinterCodes(StreamWriter sw, LabelData labelData){

            // send label and format

            sw.Write("\x1bD0715,1040,0635\n\x00");
            sw.Write("\x1bAY;-00,1\n\x00");

            sw.Write("\x1bAX;+012\n\x00");
            // send printer formatting sequence
            sw.Write("\x1bPC00;0030,0015,1,1,G,00,B,00,1,0\n\x00");         

            sw.Write("\x1bPC01;0010,0145,3,3,S,00,B,00,1,0\n\x00");                   

            sw.Write("\x1bPV03;0010,0390,0130,0210,B,00,B,00,1,0\n\x00");          

            sw.Write("\x1bPV04;0365,0360,0175,0275,B,00,B,00,1,0\n\x00");     

            sw.Write("\x1bPV05;0450,0440,0070,0080,B,00,W,00,1,0\n\x00");          

            sw.Write("\x1bXB07;0055,0460,9,3,03,0,0060,000,0,00,1,0\n\x00");

            sw.Write("\x1bPC06;0010,0575,2,2,S,00,B,00,1,0\n\x00");                    

            sw.Write("\x1bPC08;0800,0575,2,2,S,00,B,00,1,0\n\x00");             

            //tell printer end of formatting sequence

            sw.Write("\x1bXP\n\00");

            // send the remote machine name

            sw.Write(string.Format("\x1b\x58\x00\x00\x01{0}\x0a{1}\x0a{2}\x0a{3}\x0a{4}\x0a{5}\x0a{6}\x0a{7} - {8} - {9}\x0a{10}\x0a\00",

                "",                                 // Blank  {0}

                labelData.getDataXXX(),           

                labelData. getDataXXX (),         

                labelData. getDataX (),           

                labelData. getDataX (),             

                labelData. getDataX (),       

                labelData. getDataX (),           

                labelData. getDataX (),     

                labelData. getDataX (),         

                labelData. getDataX (),     

                labelData. getDataX ()));         

               

            // flush all writes

 

            sw.Flush();

Solution

  • settings on the printer need to be set to "Label mode"