reorganise project

This commit is contained in:
Nikolay Khabarov
2017-05-13 03:52:36 +03:00
parent 82d0f5f016
commit 1391b03724
17 changed files with 69 additions and 34 deletions
Executable
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env python
import sys
import readline
import logging
logging.basicConfig(level=logging.CRITICAL,
format='[%(levelname)s] %(message)s')
from gcode import GCode, GCodeException
from gmachine import GMachine, GMachineException
try: # python3 compatibility
type(raw_input)
except NameError:
raw_input = input
machine = GMachine()
def do_line(line):
try:
g = GCode.parse_line(line)
machine.do_command(g)
except (GCodeException, GMachineException) as e:
print('ERROR ' + str(e))
return False
print('OK')
return True
def main():
try:
if len(sys.argv) > 1:
# Read file with gcode
with open(sys.argv[1], 'r') as f:
for line in f:
line = line.strip()
print('> ' + line)
if not do_line(line):
break
else:
# Main loop for interactive shell
# Use stdin/stdout, additional interfaces like
# UART, Socket or any other can be added.
print("*************** Welcome to PyCNC! ***************")
while True:
line = raw_input('> ')
if line == 'quit' or line == 'exit':
break
do_line(line)
except KeyboardInterrupt:
pass
print("\r\nExiting...")
machine.release()
if __name__ == "__main__":
main()