Skip to content

Instantly share code, notes, and snippets.

@reginaldojunior
Forked from renatoargh/bematech.js
Created November 26, 2017 15:05
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 reginaldojunior/64b962995fb9ef2b4143784e7b23698b to your computer and use it in GitHub Desktop.
Save reginaldojunior/64b962995fb9ef2b4143784e7b23698b to your computer and use it in GitHub Desktop.
Imprimindo com Bematech MP-4200 com node.js (sem cups nem módulos nativos)
var fs = require('fs');
String.prototype.toBytes = function() {
var arr = []
for (var i=0; i < this.length; i++) {
arr.push(this[i].charCodeAt(0))
}
return arr;
}
var printData = "Hello World!".toBytes().concat([0x01B, 0x64, 10, 0x1d, 0x56, 0x00]);
var wstream = fs.createWriteStream('/dev/ttyACM0', {
encoding: 'utf16le'
});
wstream.write(new Buffer(printData));
wstream.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment