Skip to content

Instantly share code, notes, and snippets.

@hiepxanh
Created June 27, 2020 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiepxanh/25578459423f5ac40d2a3e6ef8ea2e8f to your computer and use it in GitHub Desktop.
Save hiepxanh/25578459423f5ac40d2a3e6ef8ea2e8f to your computer and use it in GitHub Desktop.
receipt cho bill.xml
<epos-print xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print">
<text>Hello world &#10;</text>
<text>Hello&#10;</text>
<text>Hello&#10;</text>
<text>Hello&#10;</text>
<feed line="3"/>
<feed line="3"/>
<cut type="feed"/>
</epos-print>
var canvas = document.getElementById('canvas');
var printer = null;
var ePosDev = new epson.ePOSDevice();
ePosDev.connect('192.168.26.111', 8008, cbConnect);
function cbConnect(data) {
if(data == 'OK' || data == 'SSL_CONNECT_OK') {
ePosDev.createDevice('local_printer', ePosDev.DEVICE_TYPE_PRINTER,
{'crypto':false, 'buffer':false}, cbCreateDevice_printer);
} else {
alert(data);
}
}
function cbCreateDevice_printer(devobj, retcode) {
if( retcode == 'OK' ) {
printer = devobj;
printer.timeout = 60000;
printer.onreceive = function (res) { alert(res.success); };
printer.oncoveropen = function () { alert('coveropen'); };
print();
} else {
alert(retcode);
}
}
function print() {
printer.addText('Hello world \n');
printer.addText('Hello\n');
printer.addText('Hello\n');
printer.addText('Hello\n');
printer.addFeedLine(3);
printer.addFeedLine(3);
printer.addCut(printer.CUT_FEED);
printer.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment