~$ pip install -r requirements.txt
~$ python3 printer.py
import asyncio
from luck_printer import LuckPrinter, BluetoothDevice
async def main():
# BLE示例 // run scan.py to get address
device = BluetoothDevice("028EBD80-9CCC-AD10-E727-8715AF47A664")
await device.open()
# 串口示例
# from serial import Serial
# device = Serial("/dev/rfcomm1")
printer = LuckPrinter(device)
try:
await printer.initialize()
await printer.print_text("Hello, World!")
await printer.print_end()
finally:
await printer.close()
if __name__ == "__main__":
asyncio.run(main())
~$ bluetoothctl
[bluetoothctl]# agent on
[bluetoothctl]# discoverable on
[bluetoothctl]# scan on
[bluetoothctl]# trust <address>
[bluetoothctl]# pair <address>
~$ sudo rfcomm connect 1 <address>