#!/usr/bin/env python
#
# Download Gcode from a Cincinnati Milacron CNC lathe
# Copyright 2016 Tommy Johnson
# http://www.bobdbob.com/~tjohnson/lathe/ 

import serial

ser=serial.Serial("/dev/cuaU0",9600, bytesize=7, parity='E', stopbits=2);

while(True):
	print "waiting..."
	c=ord(ser.read(1));
	print "0x%x"%(c)
	if (c==0x12):		# 0x12 == DC2
		break;

print "Got 0x12"
ser.write(chr(0x11));	# Xon?

p=""
while(True):
	c=ser.read();

	p+=c
	print "%c 0x%x"%(c,ord(c))

	if (ord(c)==0x14):   # 0x14 == DC4 == EOF
		break;

print p
