Created
August 12, 2020 04:37
-
-
Save rfb/48c1df8ade85a6b0dc19451c55f1c115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# roland_plotter_flowcontrol.py | |
# | |
# chunks hpgl commands into 256 bytes. feeds plotters new chunks | |
# when there is available space. | |
# | |
# expects plotter at /dev/ttyUSB0 9600 8N1 | |
# | |
# tested with a roland dxy-885 | |
# | |
# usage: | |
# | |
# python roland_plotter_flowcontrol.py < plot.hpgl | |
# | |
# say hi! github.com/rfb [email protected] | |
# | |
import serial | |
import sys | |
contents = sys.stdin.read() | |
chunkSize = 256 | |
chunks = [contents[i:i+chunkSize] for i in range(0, len(contents), chunkSize)] | |
def currentBufferSize(ser): | |
ser.write(b"\x1b.B") # hey plotter, how much buffer is remaining? | |
size = int(ser.read_until(b"\x0d").decode().strip()) | |
print("currentBufferSize:",size) | |
return size | |
with serial.Serial('/dev/ttyUSB0', 9600) as ser: | |
ser.write(b"\x1b.M100;;;13:") # plotter, terminate responses with chr 13! | |
for chunk in chunks: | |
while currentBufferSize(ser) < chunkSize: | |
print("holding..") | |
print("sending", chunk) | |
ser.write(chunk.encode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment