-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_sim.py
executable file
·71 lines (60 loc) · 2.1 KB
/
run_sim.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
#!/usr/bin/python
import sys
import os
import subprocess
import argparse
from time import *
from machinekit import launcher
from machinekit import config
if sys.version_info >= (3, 0):
import configparser
else:
import ConfigParser as configparser
parser = argparse.ArgumentParser(description='starts the Uni-Print-3D confgurations')
parser.add_argument('-e', '--num_extruders', help='number of extruders', nargs='?', type=int, default=1)
parser.add_argument('-a', '--with_abp', help='enable a automated build platform', action='store_true')
parser.add_argument('config', nargs=1, help='path to config file')
args = parser.parse_args()
configName = args.config[0]
numExtruders = args.num_extruders
withAbp = args.with_abp
launcher.register_exit_handler()
#launcher.set_debug_level(5)
os.chdir(os.path.dirname(os.path.realpath(__file__)))
launcher.set_machinekit_ini(config.MACHINEKIT_INI)
if not os.path.isfile(configName):
sys.stderr.write('Config file %s does not exist' % configName)
sys.exit(1)
startupIniName = 'startup.ini'
sourceIni = open(configName) # open ini
lines = sourceIni.readlines()
sourceIni.close()
lines.append('NUM_EXTRUDERS = %i\n' % numExtruders)
lines.append('NUM_FANS = %i\n' % numExtruders)
lines = [l.replace('uni_print_3d.py', 'sim.py') for l in lines]
if withAbp:
lines.append('ABP = 1\n')
startupIni = open(startupIniName, 'w')
startupIni.writelines(lines) # copy file contents
startupIni.close()
try:
launcher.check_installation()
launcher.cleanup_session()
#launcher.load_bbio_file('paralell_cape3.bbio')
launcher.install_comp('thermistor_check.icomp')
cfg = configparser.ConfigParser({'NAME': ''})
cfg.read(startupIniName)
machineName = cfg.get('EMC', 'NAME')
command = 'configserver'
if machineName is not '':
command += ' -n %s' % machineName
command += ' ~/projects/Machineface'
launcher.start_process(command)
launcher.start_process('linuxcnc %s' % startupIniName)
while True:
launcher.check_processes()
sleep(1)
except subprocess.CalledProcessError:
launcher.end_session()
sys.exit(1)
sys.exit(0)