This repository was archived by the owner on Mar 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ font = ImageFont.truetype("FreeSans.ttf", SIZE)
3737Text(font, pad_right = 50 )
3838```
3939
40+ To use a Bluetooth connection:
41+ 1 . pair your device
42+ 2 . specify the serial device node when instantiating the printer:
43+
44+ ```
45+ printer = P700(BTSerialBackend.auto(devPath='/dev/ttyS8'))
46+ ```
47+
4048The Following printers are currently supported:
4149
4250 * Brother P-Touch PT-700 (aka P700)
@@ -50,6 +58,7 @@ but have not been tested (please tell us if they do!):
5058The following backends are currently supported:
5159
5260 * USB Printer Device Class via PyUSB
61+ * Bluetooth Serial connection via PySerial
5362
5463The official source of this repository is at https://git.scc.kit.edu/scc-net/labelprinterkit .
5564Pull requests and issues are also accepted on github at https://github.com/notafile/labelprinterkit .
Original file line number Diff line number Diff line change 11import usb .core
22import usb .util
33import threading
4+ import serial
45
56def is_usb_printer (dev ):
67 if dev .bDeviceClass == 7 :
@@ -27,3 +28,30 @@ def write(self, data: bytes):
2728
2829 def read (self , count : int ) -> bytes :
2930 return self .dev .read (0x81 , count )
31+
32+ class BTSerialBackend ():
33+ def __init__ (self , dev ):
34+ self .dev = dev
35+ self .lock = threading .Lock ()
36+
37+ @classmethod
38+ def auto (cls , devPath : str ):
39+ dev = serial .Serial (
40+ devPath ,
41+ baudrate = 9600 ,
42+ stopbits = serial .STOPBITS_ONE ,
43+ parity = serial .PARITY_NONE ,
44+ bytesize = 8 ,
45+ dsrdtr = False ,
46+ timeout = 1
47+ )
48+ if dev is None :
49+ raise OSError ('Device not found' )
50+ return cls (dev )
51+
52+ def write (self , data : bytes ):
53+ self .dev .write (data )
54+
55+ def read (self , count : int ) -> bytes :
56+ data = self .dev .read (count )
57+ return data
Original file line number Diff line number Diff line change 2424 'pillow' ,
2525 'pyusb' ,
2626 'packbits' ,
27+ 'pyserial'
2728 ],
2829 setup_requires = [
2930 'setuptools_scm'
You can’t perform that action at this time.
0 commit comments