52 lines
1.7 KiB
Python
Executable File
52 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# This script is used to start the test IOC and is usually run as part of a
|
|
# test startup procedure. It autogenerates an IOC shell script from motors.yaml
|
|
# which contains the IP adresses and ports of the motor controllers.
|
|
|
|
import yaml
|
|
import os
|
|
import subprocess
|
|
|
|
|
|
def startioc():
|
|
|
|
root_dir = os.path.dirname(__file__) + '/../'
|
|
|
|
with open(root_dir + "config.yaml", "r") as f:
|
|
config = yaml.safe_load(f)
|
|
|
|
with open(root_dir + 'ioc/config.cmd', "w") as out:
|
|
|
|
# General configuration
|
|
out.write(
|
|
f'epicsEnvSet("PVPREFIX", "{config["pvprefix"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("IOCDIR", "{root_dir + "ioc"}" )\n')
|
|
|
|
# Motor configuration
|
|
out.write(
|
|
f'epicsEnvSet("TURBOPMAC_VERSION", "{config["versions"]["turboPmac"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS_VERSION", "{config["versions"]["masterMacs"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("TURBOPMAC1_IP", "{config["controllers"]["turboPmac1"]["ip"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("TURBOPMAC1_PORT", "{config["controllers"]["turboPmac1"]["port"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_IP", "{config["controllers"]["masterMacs1"]["ip"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_PORT", "{config["controllers"]["masterMacs1"]["port"]}")\n')
|
|
|
|
# Start the IOC itself and keep it running in the background.
|
|
# We need to start a new session so Pytest doesn't kill the process
|
|
proc = subprocess.Popen([root_dir + 'ioc/startioc'], start_new_session=True)
|
|
|
|
print(f"Started IOC with PID {proc.pid}")
|
|
|
|
# Yield control back to the test
|
|
# yield
|
|
|
|
if __name__ == '__main__':
|
|
startioc()
|