Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06496c6

Browse files
authored
Example for finding device based on USB vendor/product ID
1 parent 607928e commit 06496c6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,34 @@ raster = StarTSPImage.imageToRaster(image, cut=True)
3939
printer = open('/dev/usb/lp0', "wb")
4040
printer.write(raster)
4141
```
42+
43+
Search for Star printer via vendor/product ID, then create a PIL image and print:
44+
```
45+
import StarTSPImage
46+
import usb.core
47+
from PIL import Image, ImageDraw
48+
49+
vendorId = 0x0519 # Star
50+
productId = 0x0003 # TSP143
51+
52+
dev = usb.core.find(idVendor=vendorId, idProduct=productId)
53+
54+
if dev:
55+
56+
print('Found:', usb.util.get_string(dev, dev.iProduct))
57+
58+
# Build PIL image
59+
image = Image.new('RGB', (500, 500), color='White')
60+
draw = ImageDraw.Draw(image)
61+
draw.ellipse((0, 0, 500, 500), fill='Black')
62+
draw.ellipse((10, 10, 490, 490), fill='White')
63+
64+
# Create raster for Star
65+
raster = StarTSPImage.imageToRaster(image, cut=True)
66+
67+
# Send to device using endpoint 2 (OUT)
68+
dev.write(2, raster)
69+
70+
else:
71+
print('Could not find device')
72+
```

0 commit comments

Comments
 (0)