80 lines
3.0 KiB
Python
Executable File
80 lines
3.0 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
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def startioc():
|
|
|
|
root_dir = Path(__file__).resolve().parent.parent
|
|
|
|
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("EL734_VERSION", "{config["versions"]["el734"]}")\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("TURBOPMAC1_BUSYPOLL", "{config["controllers"]["turboPmac1"]["busypoll"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("TURBOPMAC1_IDLEPOLL", "{config["controllers"]["turboPmac1"]["idlepoll"]}")\n')
|
|
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_IP", "{config["controllers"]["masterMacs1"]["ip"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_PORT", "{config["controllers"]["masterMacs1"]["port"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_BUSYPOLL", "{config["controllers"]["masterMacs1"]["busypoll"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("MASTERMACS1_IDLEPOLL", "{config["controllers"]["masterMacs1"]["idlepoll"]}")\n')
|
|
|
|
out.write(
|
|
f'epicsEnvSet("EL734_1_IP", "{config["controllers"]["el734_1"]["ip"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("EL734_1_PORT", "{config["controllers"]["el734_1"]["port"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("EL734_1_BUSYPOLL", "{config["controllers"]["el734_1"]["busypoll"]}")\n')
|
|
out.write(
|
|
f'epicsEnvSet("EL734_1_IDLEPOLL", "{config["controllers"]["el734_1"]["idlepoll"]}")\n')
|
|
|
|
# Set environment variables
|
|
os.environ["EPICS_BASE"] = "/usr/local/epics/base-7.0.7"
|
|
os.environ["EPICS_HOST_ARCH"] = "RHEL8-x86_64"
|
|
|
|
# Change working directory so st.cmd can find other .cmd files
|
|
os.chdir(root_dir / 'ioc')
|
|
|
|
# Run the IOC shell script
|
|
try:
|
|
subprocess.run(["/usr/local/bin/iocsh", "st.cmd"], check=True)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to start IOC: {e}", file=sys.stderr)
|
|
sys.exit(e.returncode)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
startioc()
|