【发布时间】:2021-09-27 06:12:42
【问题描述】:
在 Android Flutter 项目中,我需要在 USB POS 打印机上进行打印,并且为了进行测试,我有一台 Epson TM-T20。发送原始字节将是理想的。 flutter_usb_write 包不起作用(write 返回 false)并且它的状态有点令人担忧(还没有健全的 null 安全性,主页是克罗地亚语并且没有问题跟踪器)。
还有其他选择吗?
Future<void> printOnPOS(String text) async {
// text = String.fromCharCodes([27, 64]) + text; // Initialize printer
text += "\r\n";
try {
var flutterUsbWrite = FlutterUsbWrite();
List<UsbDevice> devices = await flutterUsbWrite.listDevices();
print("devices: $devices");
var device = devices[1]; // this picks the printer, checked correct
var port = await flutterUsbWrite.open(
vendorId: device.vid,
productId: device.pid,
);
print("port: $port");
var rw = await flutterUsbWrite.write(Uint8List.fromList(text.codeUnits));
print("rw: $rw");
await flutterUsbWrite.close();
} on PlatformException catch (e) {
print(e.message);
}
}
输出:
I/flutter ( 7763): devices: [UsbDevice: e0f-3 VMware Virtual USB Mouse, VMware null, UsbDevice: 4b8-e03 TM-T20, EPSON 405551460005550000]
I/flutter ( 7763): port: UsbDevice: 4b8-e03 TM-T20, EPSON 405551460005550000
I/flutter ( 7763): rw: false
D/UsbDeviceConnectionJNI( 7763): close
【问题讨论】: