ESC/POS Raw Printing

256 views
Skip to first unread message

Wai-Sun Chia

unread,
Oct 16, 2019, 10:43:38 AM10/16/19
to qz-print
I finally managed to send some data to the printer via ESC/POS. But the code is not being executed. It is coming out as code.
Here's the log. Does it look correct?



2019-10-16 22:08:28,947 [DEBUG] Message: {"call":"print","promise":{},"params":{"printer":{"name":"POS-80"},"options":{"colorType":"color","copies":1,"density":0,"duplex":false,"fallbackDensity":null,"interpolation":"bicubic","jobName":null,"legacy":false,"margins":0,"orientation":null,"paperThickness":null,"printerTray":null,"rasterize":true,"rotation":0,"scaleContent":true,"size":null,"units":"in","altPrinting":false,"encoding":null,"endOfDoc":null,"perSpool":1},"data":["'\\x1B' + '\\x40',          // init\n   '\\x1B' + '\\x61' + '\\x31', // center align\n   'United Marvel' + '\\x0A',\n   '\\x0A',                   // line break\n   '\\x1B' + '\\x61' + '\\x31', // center align\n   Business Reg: 233312 (SST No:55553)' + '\\x0A',\n   '\\x0A',                   // line break\n   '------------------------------------------' + '\\x0A',\n\n\t'Description' +  'Qty' + 'Total' + '\\x0A',\n\t\t\t'Lay&#039;s Classic' + '1' + '12.50' + '\\x0A',\n\t\t\t'Cappucino' + '1' + '6.50' + '\\x0A',\n\t\t\t'烧鸭 Roast Duck' + '1' + '7.50' + '\\x0A',\n\t\t'\\x0A',\n\t'Item Amount' + 'MYR' + '26.50' + '\\x0A',\n\t'\\x0A',\n   '------------------------------------------' + '\\x0A',\n\n\t'Service Tax 6%' + 'MYR' + '1.59' + '\\x0A',\n\n\t'Service Charge 0%' + 'MYR' + '0.00' + '\\x0A',\n\n\t'Rounding' + 'MYR' + '0.01' + '\\x0A',\n\n\t'Total' + 'MYR' + '28.10' + '\\x0A',\n\t\n\t'More Payment - 0.00' + '\\x0A',\n\t'Points - Pts 0.00' + '\\x0A',\n\n\t'Cash Received - MYR\n\t\t\t0.00' + '\\x0A',\n\n\t'Credit Card - MYR' + '0.00' + '\\x0A',\n\n\t'Change MYR' + '0.00' + '\\x0A',\n\n\t'Credit Card No.\tXXXX-XXXX-XXXX-' + '\\x0A',\n\t'\\x0A',\n   \t'------------------------------------------' + '\\x0A',\n\t'\\x0A',\n\n\t<!-- This is for hardcopy instance of the receipt -->\n\t'Terminal ID 1050000000047' + '\\x0A',\n\t'Staff Name Tan' + '\\x0A',\n\t'Staff ID 1020000000077' +'\\x0A',\n\t'Date 16Oct19 22:08:28' +'\\x0A',\n\t\t\t'Take Away No. 003' + '\\x0A',\n\t\t'Pax 1' + '\\x0A',\n\n\t'\\x0A',\n   \t'------------------------------------------' + '\\x0A',\n\t'\\x0A',\n   '\\x1B' + '\\x61' + '\\x31', // center align\n\t'1060000450000000003' +'\\x0A',\n   '\\x1B' + '\\x61' + '\\x31', // center align\n\t'Thank You!' + '\\x0A',\n"]},"timestamp":1571234908937,"uid":"lqtusw","position":{"x":960,"y":540}}

Tres Finocchiaro

unread,
Oct 16, 2019, 11:34:34 AM10/16/19
to Wai-Sun Chia, qz-print
Your data shouldn't be wrapped in double quotes AND single quotes... 

Notice your data starts with double quote (") and single quote ('). This won't work.

"data":[
    "'\\x1B' + '\\x40',          // init
    '\\x1B' + '\\x61' + '\\x31'// center align
    'United Marvel' + '\\x0A',

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qz-print/8daa58d5-a056-4596-a053-01f285bb9886%40googlegroups.com.
Message has been deleted

Tres Finocchiaro

unread,
Oct 16, 2019, 11:44:20 AM10/16/19
to Wai-Sun Chia, qz-print
Because you have an extra double quote as indicated.  I've already pointed out the problem.  Please remove the extra quotes around your data.



On Wed, Oct 16, 2019 at 11:38 AM Wai-Sun Chia <waisun.in...@gmail.com> wrote:
My output is the ESCPOS code! Seems the code is not being interpreted.
--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.

Wai-Sun Chia

unread,
Oct 16, 2019, 12:01:44 PM10/16/19
to qz-print
I see. But we are storing the entire code in a string variable.

var data = [escposdata];
qz.print(config, data);

So that's how the double quotes came in. How do I do this without incurring the double quote?

On Wednesday, 16 October 2019 23:34:34 UTC+8, Tres Finocchiaro wrote:
Your data shouldn't be wrapped in double quotes AND single quotes... 

Notice your data starts with double quote (") and single quote ('). This won't work.

"data":[
    "'\\x1B' + '\\x40',          // init
    '\\x1B' + '\\x61' + '\\x31'// center align
    'United Marvel' + '\\x0A',
    '\\x0A',


On Wed, Oct 16, 2019 at 10:43 AM Wai-Sun Chia <waisun.i...@gmail.com> wrote:
I finally managed to send some data to the printer via ESC/POS. But the code is not being executed. It is coming out as code.
Here's the log. Does it look correct?



2019-10-16 22:08:28,947 [DEBUG] Message: {"call":"print","promise":{},"params":{"printer":{"name":"POS-80"},"options":{"colorType":"color","copies":1,"density":0,"duplex":false,"fallbackDensity":null,"interpolation":"bicubic","jobName":null,"legacy":false,"margins":0,"orientation":null,"paperThickness":null,"printerTray":null,"rasterize":true,"rotation":0,"scaleContent":true,"size":null,"units":"in","altPrinting":false,"encoding":null,"endOfDoc":null,"perSpool":1},"data":["'\\x1B' + '\\x40',          // init\n   '\\x1B' + '\\x61' + '\\x31', // center align\n   'United Marvel' + '\\x0A',\n   '\\x0A',                   // line break\n   '\\x1B' + '\\x61' + '\\x31', // center align\n   Business Reg: 233312 (SST No:55553)' + '\\x0A',\n   '\\x0A',                   // line break\n   '------------------------------------------' + '\\x0A',\n\n\t'Description' +  'Qty' + 'Total' + '\\x0A',\n\t\t\t'Lay&#039;s Classic' + '1' + '12.50' + '\\x0A',\n\t\t\t'Cappucino' + '1' + '6.50' + '\\x0A',\n\t\t\t'烧鸭 Roast Duck' + '1' + '7.50' + '\\x0A',\n\t\t'\\x0A',\n\t'Item Amount' + 'MYR' + '26.50' + '\\x0A',\n\t'\\x0A',\n   '------------------------------------------' + '\\x0A',\n\n\t'Service Tax 6%' + 'MYR' + '1.59' + '\\x0A',\n\n\t'Service Charge 0%' + 'MYR' + '0.00' + '\\x0A',\n\n\t'Rounding' + 'MYR' + '0.01' + '\\x0A',\n\n\t'Total' + 'MYR' + '28.10' + '\\x0A',\n\t\n\t'More Payment - 0.00' + '\\x0A',\n\t'Points - Pts 0.00' + '\\x0A',\n\n\t'Cash Received - MYR\n\t\t\t0.00' + '\\x0A',\n\n\t'Credit Card - MYR' + '0.00' + '\\x0A',\n\n\t'Change MYR' + '0.00' + '\\x0A',\n\n\t'Credit Card No.\tXXXX-XXXX-XXXX-' + '\\x0A',\n\t'\\x0A',\n   \t'------------------------------------------' + '\\x0A',\n\t'\\x0A',\n\n\t<!-- This is for hardcopy instance of the receipt -->\n\t'Terminal ID 1050000000047' + '\\x0A',\n\t'Staff Name Tan' + '\\x0A',\n\t'Staff ID 1020000000077' +'\\x0A',\n\t'Date 16Oct19 22:08:28' +'\\x0A',\n\t\t\t'Take Away No. 003' + '\\x0A',\n\t\t'Pax 1' + '\\x0A',\n\n\t'\\x0A',\n   \t'------------------------------------------' + '\\x0A',\n\t'\\x0A',\n   '\\x1B' + '\\x61' + '\\x31', // center align\n\t'1060000450000000003' +'\\x0A',\n   '\\x1B' + '\\x61' + '\\x31', // center align\n\t'Thank You!' + '\\x0A',\n"]},"timestamp":1571234908937,"uid":"lqtusw","position":{"x":960,"y":540}}

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-p...@googlegroups.com.

Tres Finocchiaro

unread,
Oct 16, 2019, 12:06:09 PM10/16/19
to Wai-Sun Chia, qz-print
How do I do this without incurring the double quote?

The easiest I can think of is using eval(), assuming you prefer not to store the byte values (the byte values are valid strings, just not human readable)

To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qz-print/a2cff54b-1468-4743-bdf0-c8e1209f2e58%40googlegroups.com.

Tres Finocchiaro

unread,
Oct 16, 2019, 12:09:34 PM10/16/19
to Wai-Sun Chia, qz-print
var tooManyQuotes = "'hello\\nworld'";
var lessQuotes = eval(tooManyQuotes);
console.log(tooManyQuotes);
console.log(lessQuotes);

Reply all
Reply to author
Forward
0 new messages