forked from GatCode/SMTCut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file2graphtec
executable file
·60 lines (47 loc) · 1.01 KB
/
file2graphtec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
#
# file2graphtec
#
# Send a file to a Graphtec vinyl cutter using libusb
#
# Copyright (c) 2013 Peter Monta <[email protected]>
#
import sys
import usb1
#
# open a graphtec vinyl cutter from a list of recognized devices
#
device_list = [
(0x0b4d, 0x1121), # Silhouette Cameo
(0x0b4d, 0x1123), # Silhouette Portrait
(0x0b4d, 0x1132) # Silhouette Portrait 2
]
def open_graphtec_device(ctx):
for (vendor_id,product_id) in device_list:
dev = ctx.openByVendorIDAndProductID(vendor_id, product_id)
if dev:
return dev
return None
#
# main program
#
if len(sys.argv)==2:
f = open(sys.argv[1], 'rb')
elif len(sys.argv)==1:
f = sys.stdin
else:
print('usage: file2graphtec [filename]')
sys.exit(1)
endpoint = 1
ctx = usb1.USBContext()
dev = open_graphtec_device(ctx)
if not dev:
sys.stderr.write('no graphtec device found\n')
sys.exit(1)
dev.claimInterface(0)
while True:
data = f.read(8)
if not data:
break
dev.bulkWrite(endpoint, data)
f.close()