forked from thecooltool/machinekit-configs
/
run.py
executable file
·86 lines (71 loc) · 2.63 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
import sys
import os
import subprocess
import argparse
from time import sleep
from machinekit import launcher
if sys.version_info >= (3, 0):
import configparser
else:
import ConfigParser as configparser
parser = argparse.ArgumentParser(description='starts TheCoolTool configs')
parser.add_argument('-nm', '--no_machinetalk', help='legacy option', action='store_true')
parser.add_argument('-mk', '--mkwrapper', help='enables mkwrapper mode', action='store_true')
parser.add_argument('-m', '--machineface', help='displays the Machineface user interface', action='store_true')
parser.add_argument('-c', '--cetus', help='displays the Cetus user interface', action='store_true')
parser.add_argument('-r', '--robot', help='enables robot interaction', action='store_true')
parser.add_argument('config', nargs=1, help='path to config file')
args = parser.parse_args()
configName = args.config[0]
mtEnabled = args.mkwrapper
robotEnabled = args.robot
machineface = args.machineface
cetus = args.cetus
launcher.register_exit_handler()
#launcher.set_debug_level(5)
os.chdir(os.path.dirname(os.path.realpath(__file__)))
if not os.path.isfile(configName):
sys.stderr.write('Config file %s does not exist' % configName)
exit(1)
startupIniName = 'startup.ini'
sourceIni = open(configName) # open ini
lines = sourceIni.readlines()
sourceIni.close()
if mtEnabled:
lines = lines[:-3] # remove intro graphic
lines.append('DISPLAY = mkwrapper\n')
else:
lines.append('DISPLAY = axis\n')
startupIni = open(startupIniName, 'w')
startupIni.writelines(lines) # copy file contents
startupIni.close()
try:
launcher.check_installation()
launcher.cleanup_session()
if robotEnabled: # consider the special robot case
launcher.load_bbio_file('paralell_cape2_robot.bbio')
else:
launcher.load_bbio_file('paralell_cape2.bbio')
if mtEnabled: # load Machinetalk services
cfg = configparser.ConfigParser({'NAME': ''})
cfg.read(startupIniName)
machineName = cfg.get('EMC', 'NAME')
command = 'configserver'
if machineName is not '':
command += ' -n %s' % machineName
if machineface:
command += ' ~/Machineface'
if cetus:
command += ' ~/Cetus'
launcher.start_process(command)
if os.path.exists('/dev/video0'): # automatically start videoserver
launcher.start_process('videoserver -i video.ini Webcam1')
launcher.start_process('linuxcnc ' + startupIniName)
while True:
launcher.check_processes()
sleep(1)
except subprocess.CalledProcessError:
launcher.end_session()
exit(1)
exit(0)