-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·97 lines (68 loc) · 2.86 KB
/
plot.py
File metadata and controls
executable file
·97 lines (68 loc) · 2.86 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import serial
from time import sleep
import sys
# rawe 10.12.2015
# script to feed an HPGL file from Inkscape or somewhere on the web via UART to an Roland DXY-990
# tested so far:
# - attached Chaosknoten
# - Autodesk Spaceshutle Columbia
if not ( len(sys.argv) == 5 or len(sys.argv) == 6):
print "this.py input-file scale offsetx offsety plotter-device"
print "this.py drawing.hpgl 3.5 1000 1000 /dev/ttyUSB0"
quit()
infile = file(sys.argv[1])
scale = float(sys.argv[2])
offset = float(sys.argv[3]),float(sys.argv[4])
plotdev = False
if len(sys.argv) == 6:
plotdev = sys.argv[5]
intext = infile.read()
infile.close()
intext = intext.replace("\n",";") # in some HPGL files found there are newlines only, but no ";". Add these to make splitting commands easy.
cmds = intext.split(";")
# pre processor: split multi-point PD into single PDs. Inkscape likes to create these but Roland DXY-990 does not understand these.
outcmds = []
for item in cmds:
if "PD" in item and "," in item and len(item.split(","))>2:
#print "multipd!"
xy = False
singlepoints = item[2:].split(",")
x = 0
for point in singlepoints:
if xy == False:
x = point
else:
outcmds.append("PD"+str(x)+","+str(point))
if xy == False:
xy = True
else:
xy = False
else:
outcmds.append(item)
cmds = outcmds
extreme_coordinates = [False, False, False, False]
if plotdev:
# serial port is opened with rtscts flow control and other setings. Flow control by rtscts allows us to get away
# without escape sequences to check for a full buffer (e.g. "\x28.B").
s = serial.Serial(plotdev,rtscts=1, baudrate=9600, bytesize=serial.SEVENBITS, parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=0.01)
for cmd in cmds:
if "," in cmd: # oh, something to scale
x,y = cmd[2:].split(",")
x,y = int(int(x)*scale+offset[0]),int(int(y)*scale+offset[1])
cmd = cmd[:2]+str(x)+","+str(y)
if extreme_coordinates[0] == False or x < extreme_coordinates[0]:
extreme_coordinates[0] = x
if extreme_coordinates[1] == False or y < extreme_coordinates[1]:
extreme_coordinates[1] = y
if extreme_coordinates[2] == False or x > extreme_coordinates[2]:
extreme_coordinates[2] = x
if extreme_coordinates[3] == False or y > extreme_coordinates[3]:
extreme_coordinates[3] = y
cmd+=";" # every command ends with an ;
print cmd # display on screen
if plotdev:
s.write(cmd)
print "extreme coordinates (x/y in mm) [%f,%f ; %f,%f ] = size (w/h in mm) [%f,%f]"%(extreme_coordinates[0]/40.0, extreme_coordinates[1]/40.0, extreme_coordinates[2]/40.0, extreme_coordinates[3]/40.0, (extreme_coordinates[2]-extreme_coordinates[0])/40.0, (extreme_coordinates[3]-extreme_coordinates[1])/40.0)
if plotdev:
s.close()