Created
April 26, 2019 08:52
-
-
Save gnif/d8b9889929e835b85a6fc521295874fe to your computer and use it in GitHub Desktop.
Direct spool HPGL to a Roland DXY-1100 (Likely works with other models too)
This file contains 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
#!/usr/bin/python3 | |
# spool.py - HPGL Spooler for Serial attached Roland DXY-1100 | |
# Copyright (C) 2019 Geoffrey McRae <[email protected]> | |
# https://hostfission.com | |
# | |
# This program is free software; you can redistribute it and/or modify it under | |
# the terms of the GNU General Public License as published by the Free Software | |
# Foundation; either version 2 of the License, or (at your option) any later | |
# version. | |
# This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
# PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License along with | |
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
# Place, Suite 330, Boston, MA 02111-1307 USA | |
import signal | |
import sys | |
import serial | |
import fileinput | |
import time | |
def main(): | |
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=10) | |
running = True | |
def rl(): | |
line = bytearray() | |
while True: | |
c = ser.read(1) | |
if c: | |
if c == b'\r': | |
break | |
line += c | |
else: | |
break | |
return bytes(line) | |
def get_avail(): | |
ser.write(b'\x1b.B') | |
return int(rl()) | |
def send_line(line): | |
if len(line) == 0: | |
return | |
line += '\n' | |
while running and len(line) > 0: | |
# leave some space for control commands | |
avail = get_avail() - 32 | |
if (avail <= 0): | |
time.sleep(0.1) | |
continue | |
if avail >= len(line): | |
send = line | |
line = '' | |
else: | |
send = line[:avail] | |
line = line[avail:] | |
ser.write(bytearray(send, 'utf-8')) | |
def get_input(): | |
line = "" | |
while running: | |
c = sys.stdin.read(1) | |
if c: | |
if c == '\r' or c == '\n' or c == ';': | |
break | |
line += c | |
else: | |
return False | |
return line | |
def signal_handler(sig, frame): | |
nonlocal running | |
running = False | |
first = True | |
while running: | |
line = get_input() | |
if not line: | |
break | |
if not running: | |
break | |
if first: | |
signal.signal(signal.SIGINT, signal_handler) | |
send_line('SP 1;') | |
first = False | |
send_line(line) | |
if not running: | |
ser.write(b'\x1b.K') | |
if not first: | |
running = True | |
send_line('PU;SP;') | |
ser.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage is simple:
cat file.hpgl | ./spool.py