/* * spool.c - Send a file to a Roland MDX series CNC mill * * Written 2009, 2010, 2012 by Werner Almesberger * Copyright 2009, 2010, 2012 Werner Almesberger * * 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. */ #include #include #include #include "serial.h" #define DEFAULT_PORT "/dev/ttyS0" #define BUF_SIZE 8192 static void usage(const char *name) { fprintf(stderr, "usage: %s [file]\n", name); exit(1); } int main(int argc, const char **argv) { FILE *file; char buf[BUF_SIZE+1]; size_t n; char *port; switch (argc) { case 1: file = stdin; break; case 2: file = fopen(argv[1], "r"); if (!file) { perror(argv[1]); exit(1); } break; default: usage(*argv); } port = getenv("PORT"); serial_open(port ? port : DEFAULT_PORT); while (1) { n = fread(buf, 1, BUF_SIZE, file); if (!n) break; buf[n] = 0; serial_printf("%s", buf); } sleep(3600); serial_close(); return 0; }