Hey all, I'm running into an issue that I can't get to the bottom of after many days of troubleshooting. I'm using Flutter Blue Plus to connect to and send write commands to a characteristic on a Phomemo m220 thermal printer. I'm able to connect to the printer but when the print command is triggered, the data transmission takes over 20 seconds (the total size of the data being sent is about 30kb, a small grayscale label with a qr code).
Each packet (size 256) is taking more than 1s to transmit, despite the stated speed of 1mbps.
Below is the code from the Phomemo dart package I'm using:
Future<void> sendData(List<int> data) async {
try {
// Write the data to the characteristic
await characteristic.write(data);
return; // Exit the function if data is successfully written
} catch (e) {
// Log any errors during data write
print('Error writing characteristic: $e');
}
// If the function reaches here, data write failed
print('Failed to write data.');
}
Future<void> printLabel(
List<img.Image?> src,
{required PhomemoPrinter printer,
Size labelSize = const Size(12, double.infinity),
int? spacing,
bool rotate = true
}
) async {
List<int> bits = [];
for (int i = 0; i < src.length; i++) {
if (src[i] != null) {
bits += PhomemoHelper().preprocessImage(src[i]!, rotate, labelSize);
if (spacing != null && PhomemoPrinter.m220 != printer) {
bits += List.filled(spacing * labelSize.width.toInt(), 0x00);
}
}
}
if (bits.isEmpty) return;
await header(labelSize.width.toInt(), bits.length ~/ labelSize.width);
for (int i = 0; i < bits.length / packetSize; i++) {
if (i * packetSize + packetSize < bits.length) {
await send(bits.sublist(i * packetSize, i * packetSize + packetSize));
}
else {
await send(bits.sublist(i * packetSize, bits.length));
}
}
int end = PhomemoPrinter.p12pro == printer ? 0x0E : 0x00;
await send([0x1b, 0x64, end]);
}
/// The start information for the printer
Future<void> header(int width, int bytes) async {
List<int> start = [
0x1b,
0x40,
0x1d,
0x76,
0x30,
0x00,
width % 256,
width ~/ 256,
bytes % 256,
bytes ~/ 256
];
await send(start);
}
}