react-native-sunmi-inner-printer
react-native-sunmi-inner-printer copied to clipboard
Printing very slowly
Issue
After around 3-4 relatively quick print jobs, the printer slows down to around 1 line of text every 2 seconds. Every await SunmiInnerPrinter.printOriginalText(...)
takes between 2-3 seconds to return.
This applies no matter what text is being sent, whether it is a short string or very long one.
Device Sunmi V2
Print Code
import SunmiInnerPrinter from "react-native-sunmi-inner-printer";
import { btoa } from "../utils/base64";
function BufferToBase64(buf) {
const binstr = Array.prototype.map
.call(buf, function(ch) {
return String.fromCharCode(ch);
})
.join("");
return btoa(binstr);
}
const printBold = async text => {
const bold = [0x1b, 0x45, 0x1];
const boldUint8 = new Uint8Array(bold);
const boldBase64 = BufferToBase64(boldUint8);
await SunmiInnerPrinter.sendRAWData(boldBase64);
// Print the bold text
await SunmiInnerPrinter.printOriginalText(text);
const unbold = [0x1b, 0x45, 0x0];
const unboldUint8 = new Uint8Array(unbold);
const unboldBase64 = BufferToBase64(unboldUint8);
await SunmiInnerPrinter.sendRAWData(unboldBase64);
};
export const printOrder = async ({ order, categories, restaurant }) => {
try {
await SunmiInnerPrinter.clearBuffer();
await SunmiInnerPrinter.setAlignment(1);
await SunmiInnerPrinter.setFontSize(50);
await printBold("ecoeats\n");
await SunmiInnerPrinter.setFontSize(30);
await SunmiInnerPrinter.printOriginalText(`${restaurant.name}\n`);
await SunmiInnerPrinter.setFontSize(80);
await SunmiInnerPrinter.printOriginalText(`#${order.number}\n`);
await SunmiInnerPrinter.setFontSize(30);
await printBold(
`Pickup Time: ${new Date(order.pickupAt)
.toLocaleTimeString()
.split(":")
.slice(0, 2)
.join(":")}\n`
);
await SunmiInnerPrinter.setAlignment(0);
await SunmiInnerPrinter.setFontSize(30);
await SunmiInnerPrinter.printOriginalText(`------------------------\n`);
await SunmiInnerPrinter.setFontSize(24);
await printBold(`Customer: ${order.customer.name}\n`);
await printBold(`Placed: ${new Date(order.placedAt).toDateString()}\n`);
await SunmiInnerPrinter.setFontSize(30);
await SunmiInnerPrinter.printOriginalText(`------------------------\n`);
if (order.allergyInformation) {
await printBold(`Allergy Info\n`);
await SunmiInnerPrinter.printOriginalText(order.allergyInformation);
await SunmiInnerPrinter.setFontSize(30);
await SunmiInnerPrinter.printOriginalText(`------------------------\n`);
}
for (const category of categories) {
await SunmiInnerPrinter.setFontSize(32);
await printBold(`${category.title}\n`);
for (const item of category.items) {
await SunmiInnerPrinter.setFontSize(32);
await SunmiInnerPrinter.printOriginalText(
`${item.quantity}x ${item.name}\n`
);
for (const modifier of item.modifierItems) {
await SunmiInnerPrinter.setFontSize(28);
await SunmiInnerPrinter.printOriginalText(
` ${modifier.quantity}x ${modifier.name}\n`
);
}
}
}
await SunmiInnerPrinter.setFontSize(30);
const price = `£${(order.basket.subtotal / 100).toFixed(2)}`;
await SunmiInnerPrinter.printOriginalText(`Total: ${price}\n`);
await SunmiInnerPrinter.printOriginalText("\n\n\n");
} catch (e) {
console.log(e);
alert("print error." + e.message);
}
};
There are some utility functions there, but printing without them results in the same issue.
Profiling Memory usage for the app in development mode is nothing unusual, around 200MB. CPU usage is also consistent, around 12-25% regardless of if it's printing or not.
just wrapped the official lib to the RN plugin simply, if you wanna quarry about the device questions, plz go with the official way.
发自我的iPhone
在 2020年3月12日,下午9:09,Stewart McGown [email protected] 写道:
Issue After around 3-4 relatively quick print jobs, the printer slows down to around 1 line of text every 2 seconds. Every await SunmiInnerPrinter.printOriginalText(...) takes between 2-3 seconds to return.
This applies no matter what text is being sent, whether it is a short string or very long one.
Device Sunmi V2
Print Code
import SunmiInnerPrinter from "react-native-sunmi-inner-printer"; import { btoa } from "../utils/base64";
function BufferToBase64(buf) { const binstr = Array.prototype.map .call(buf, function(ch) { return String.fromCharCode(ch); }) .join(""); return btoa(binstr); }
const printBold = async text => { const bold = [0x1b, 0x45, 0x1]; const boldUint8 = new Uint8Array(bold); const boldBase64 = BufferToBase64(boldUint8); await SunmiInnerPrinter.sendRAWData(boldBase64);
// Print the bold text await SunmiInnerPrinter.printOriginalText(text);
const unbold = [0x1b, 0x45, 0x0]; const unboldUint8 = new Uint8Array(unbold); const unboldBase64 = BufferToBase64(unboldUint8); await SunmiInnerPrinter.sendRAWData(unboldBase64); };
export const printOrder = async ({ order, categories, restaurant }) => { try { await SunmiInnerPrinter.clearBuffer();
await SunmiInnerPrinter.setAlignment(1); await SunmiInnerPrinter.setFontSize(50); await printBold("ecoeats\n"); await SunmiInnerPrinter.setFontSize(30); await SunmiInnerPrinter.printOriginalText(`${restaurant.name}\n`); await SunmiInnerPrinter.setFontSize(80); await SunmiInnerPrinter.printOriginalText(`#${order.number}\n`); await SunmiInnerPrinter.setFontSize(30); await printBold( `Pickup Time: ${new Date(order.pickupAt) .toLocaleTimeString() .split(":") .slice(0, 2) .join(":")}\n` ); await SunmiInnerPrinter.setAlignment(0); await SunmiInnerPrinter.setFontSize(30); await SunmiInnerPrinter.printOriginalText(`------------------------\n`); await SunmiInnerPrinter.setFontSize(24); await printBold(`Customer: ${order.customer.name}\n`); await printBold(`Placed: ${new Date(order.placedAt).toDateString()}\n`); await SunmiInnerPrinter.setFontSize(30); await SunmiInnerPrinter.printOriginalText(`------------------------\n`); if (order.allergyInformation) { await printBold(`Allergy Info\n`); await SunmiInnerPrinter.printOriginalText(order.allergyInformation); await SunmiInnerPrinter.setFontSize(30); await SunmiInnerPrinter.printOriginalText(`------------------------\n`); } for (const category of categories) { await SunmiInnerPrinter.setFontSize(32); await printBold(`${category.title}\n`); for (const item of category.items) { await SunmiInnerPrinter.setFontSize(32); await SunmiInnerPrinter.printOriginalText( `${item.quantity}x ${item.name}\n` ); for (const modifier of item.modifierItems) { await SunmiInnerPrinter.setFontSize(28); await SunmiInnerPrinter.printOriginalText( ` ${modifier.quantity}x ${modifier.name}\n` ); } } } await SunmiInnerPrinter.setFontSize(30); const price = `£${(order.basket.subtotal / 100).toFixed(2)}`; await SunmiInnerPrinter.printOriginalText(`Total: ${price}\n`); await SunmiInnerPrinter.printOriginalText("\n\n\n");
} catch (e) { console.log(e); alert("print error." + e.message); } }; There are some utility functions there, but printing without them results in the same issue.
Profiling Memory usage for the app in development mode is nothing unusual, around 200MB. CPU usage is also consistent, around 12-25% regardless of if it's printing or not.
Video
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Yes, I know. Thank you for creating it! I was more curious to see if anyone who has used this library specifically has encountered a similar issue and whether it's due to how I call the wrapper functions.
Was this problem solved? I’m experiencing the same issue on the D2 mini, with an specific ROM version. The older ROM prints fast, but the newer ROM prints slow using this lib. I know it is the lib because doing a print test with the sunmi app prints super fast.
+1