Reputation: 5673
I am working on this ionic app, and I am printing receipts using a Bluetooth thermal printer using this library.
https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer
I want to cut the paper after printing, because my printer has this feature.
BTPrinter.printPOSCommand(function(data){
console.log("Success");
console.log(data)
},function(err){
console.log("Error");
console.log(err)
}, "1D")
I have tried 0x1d and "0x1d v 1" but it just doesn't work.
Upvotes: 0
Views: 2164
Reputation: 469
How exactly have you tried to send that command? Try:
BTPrinter.printPOSCommand(function(data){
console.log("Success");
console.log(data)
},function(err){
console.log("Error");
console.log(err)
}, "0x1d")
If this doesn't work you can try to edit the plugin itself to add the method but thats a bit more complicated.
In the Bluetoothprint.java file in pluginfolder/src/android try the following:
got to the following method:
boolean printPOSCommand(CallbackContext callbackContext, byte[] buffer) throws IOException {
try {
//mmOutputStream.write(("Inam").getBytes());
//mmOutputStream.write((((char)0x0A) + "10 Rehan").getBytes());
mmOutputStream.write(buffer);
//mmOutputStream.write(0x0A);
// tell the user data were sent
Log.d(LOG_TAG, "Data Sent");
callbackContext.success("Data Sent");
return true;
} catch (Exception e) {
String errMsg = e.getMessage();
Log.e(LOG_TAG, errMsg);
e.printStackTrace();
callbackContext.error(errMsg);
}
return false;
}
change the method attribute byte[] buffer to string buffer and change the line
mmOutputStream.write(buffer);
to:
mmOutputStream.write(buffer.getBytes());
Also just to make sure your printer suppports that method you can try to directly put:
mmOutputStream.write(0x1d);
just to test if it works.
EDIT:
Try this byteArray i found:
public static byte[] FEED_PAPER_AND_CUT = {0x1D, 0x56, 66, 0x00};
BTPrinter.printPOSCommand(function(data){
console.log("Success");
console.log(data)
},function(err){
console.log("Error");
console.log(err)
}, FEED_PAPER_AND_CUT)
Upvotes: 1