-
Notifications
You must be signed in to change notification settings - Fork 6
/
st.cmd.template
283 lines (238 loc) · 11.5 KB
/
st.cmd.template
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!{{hashbang}}
################### AUTO-GENERATED DO NOT EDIT ###################
{% set production_ioc = production_ioc | int %}
{%- set project, plc = get_plc_by_name(projects, plc) -%}
{%- set plc_host = plc_hostname_override or plc.target_ip %}
{%- set plc_ams_net_id = plc_ams_net_id_override or plc.ams_id %}
#
# Project: {{ project.filename.name }}
# PLC name: {{ plc.name }} ({{ plc.link_name }})
# Generated using: pytmc {{ pytmc_version}}
# Project version: {{ project.git_info.describe }}
# Project hash: {{ project.git_info.sha }}
{% if plc_hostname_override %}
# PLC IP/host: {{ plc_hostname_override }} (Specified in Makefile; project has: {{ plc.target_ip }})
{% else %}
# PLC IP/host: {{ plc.target_ip}}
{% endif %}
{% if plc_ams_net_id_override %}
# PLC Net ID: {{ plc_ams_net_id_override }} (Specified in Makefile; project has: {{ plc.ams_id }})
{% else %}
# PLC Net ID: {{ plc.ams_id}}
{% endif %}
{% if production_ioc %}
# ** Production mode IOC **
# Using /cds/data/iocData for autosave and archiver settings.
{% else %}
# ** DEVELOPMENT MODE IOC **
# * Using IOC boot directory for autosave.
# * Archiver settings will not be configured.
{% endif %}
#
# Libraries:
#
{% for library, info in get_library_versions(plc) | dictsort %}
{% if "PlaceholderReference" in info and "PlaceholderResolution" in info %}
# {{ library }}: {{ info.PlaceholderReference.version }} -> {{ info.PlaceholderResolution.version }} ({{ info.PlaceholderResolution.vendor }})
{% elif "PlaceholderReference" in info %}
# {{ library }}: {{ info.PlaceholderReference.version }} ({{ info.PlaceholderReference.vendor }})
{% endif %}
{% endfor %}
#
################### AUTO-GENERATED DO NOT EDIT ###################
{%- if plc.tmc %}
{%- set allow_errors = ignore_linter_errors | int %}
{%- set db_filenames, records = generate_records(plc, allow_errors=allow_errors) %}
{%- set num_records = records | length %}
{%- set max_params = num_records + 1000 %}
{%- else %}
{%- set db_filenames = [] %}
{%- set records = {} %}
{%- set num_records = 0 %}
{%- set max_params = 10000 %}
{%- endif %}
< envPaths
epicsEnvSet("ADS_IOC_TOP", "$(TOP)" )
epicsEnvSet("ENGINEER", "{{user}}" )
epicsEnvSet("LOCATION", "{{prefix}}" )
epicsEnvSet("IOCSH_PS1", "$(IOC)> " )
epicsEnvSet("ACF_FILE", "$(ADS_IOC_TOP)/iocBoot/templates/unrestricted.acf")
{% if production_ioc %}
# Run common startup commands for linux soft IOC's
< /reg/d/iocCommon/All/pre_linux.cmd
{% endif %}
# Register all support components
dbLoadDatabase("$(ADS_IOC_TOP)/dbd/adsIoc.dbd")
adsIoc_registerRecordDeviceDriver(pdbbase)
epicsEnvSet("ASYN_PORT", "ASYN_PLC")
epicsEnvSet("IPADDR", "{{ plc_host }}")
epicsEnvSet("AMSID", "{{ plc_ams_net_id }}")
epicsEnvSet("AMS_PORT", "{{ plc.port }}")
epicsEnvSet("ADS_MAX_PARAMS", "{{ max_params }}")
epicsEnvSet("ADS_SAMPLE_MS", "50")
epicsEnvSet("ADS_MAX_DELAY_MS", "100")
epicsEnvSet("ADS_TIMEOUT_MS", "1000")
epicsEnvSet("ADS_TIME_SOURCE", "0")
{% if add_plc_route | int != 0 %}
# Add a route to the PLC automatically:
system("${ADS_IOC_TOP}/scripts/add_route.sh {{ plc_host }} {{ ioc_host_ip_regex }}")
{% endif %}
# adsAsynPortDriverConfigure(portName, ipaddr, amsaddr, amsport,
# asynParamTableSize, priority, noAutoConnect, defaultSampleTimeMS,
# maxDelayTimeMS, adsTimeoutMS, defaultTimeSource)
# portName Asyn port name
# ipAddr IP address of PLC
# amsaddr AMS Address of PLC
# amsport Default AMS port in PLC (851 for first PLC)
# paramTableSize Maximum parameter/variable count. (1000)
# priority Asyn priority (0)
# noAutoConnect Enable auto connect (0=enabled)
# defaultSampleTimeMS Default sample of variable (PLC ams router
# checks if variable changed, if changed then add to send buffer) (50ms)
# maxDelayTimeMS Maximum delay before variable that has changed is sent to client
# (Linux). The variable can also be sent sooner if the ams router
# send buffer is filled (100ms)
# adsTimeoutMS Timeout for adslib commands (1000ms)
# defaultTimeSource Default time stamp source of changed variable (PLC=0):
# PLC=0: The PLC time stamp from when the value was
# changed is used and set as timestamp in the EPICS record
# (if record TSE field is set to -2=enable asyn timestamp).
# This is the preferred setting.
# EPICS=1: The time stamp will be made when the updated data
# arrives in the EPICS client.
adsAsynPortDriverConfigure("$(ASYN_PORT)", "$(IPADDR)", "$(AMSID)", "$(AMS_PORT)", "$(ADS_MAX_PARAMS)", 0, 0, "$(ADS_SAMPLE_MS)", "$(ADS_MAX_DELAY_MS)", "$(ADS_TIMEOUT_MS)", "$(ADS_TIME_SOURCE)")
cd "$(ADS_IOC_TOP)/db"
{% set motors = get_motors(plc) %}
{% if motors %}
{%- set nc = get_nc(project) %}
epicsEnvSet("MOTOR_PORT", "PLC_ADS")
epicsEnvSet("PREFIX", "{{prefix}}{{pv_delimiter}}")
epicsEnvSet("NUMAXES", "{{nc.axis_by_id|max}}")
epicsEnvSet("MOVE_POLL_RATE", "200")
epicsEnvSet("IDLE_POLL_RATE", "1000")
EthercatMCCreateController("$(MOTOR_PORT)", "$(ASYN_PORT)", "$(NUMAXES)", "$(MOVE_POLL_RATE)", "$(IDLE_POLL_RATE)")
#define ASYN_TRACE_ERROR 0x0001
#define ASYN_TRACEIO_DEVICE 0x0002
#define ASYN_TRACEIO_FILTER 0x0004
#define ASYN_TRACEIO_DRIVER 0x0008
#define ASYN_TRACE_FLOW 0x0010
#define ASYN_TRACE_WARNING 0x0020
#define ASYN_TRACE_INFO 0x0040
asynSetTraceMask("$(ASYN_PORT)", -1, 0x41)
#define ASYN_TRACEIO_NODATA 0x0000
#define ASYN_TRACEIO_ASCII 0x0001
#define ASYN_TRACEIO_ESCAPE 0x0002
#define ASYN_TRACEIO_HEX 0x0004
asynSetTraceIOMask("$(ASYN_PORT)", -1, 2)
#define ASYN_TRACEINFO_TIME 0x0001
#define ASYN_TRACEINFO_PORT 0x0002
#define ASYN_TRACEINFO_SOURCE 0x0004
#define ASYN_TRACEINFO_THREAD 0x0008
asynSetTraceInfoMask("$(ASYN_PORT)", -1, 5)
#define AMPLIFIER_ON_FLAG_CREATE_AXIS 1
#define AMPLIFIER_ON_FLAG_WHEN_HOMING 2
#define AMPLIFIER_ON_FLAG_USING_CNEN 4
{% for motor in motors | sort(attribute='nc_axis.axis_number') %}
epicsEnvSet("AXIS_NO", "{{motor.nc_axis.axis_number}}")
epicsEnvSet("MOTOR_PREFIX", "{{motor|epics_prefix}}")
epicsEnvSet("MOTOR_NAME", "{{motor|epics_suffix}}")
epicsEnvSet("DESC", "{{motor.name}} / {{motor.nc_axis.name}}")
epicsEnvSet("EGU", "{{motor.nc_axis.units}}")
epicsEnvSet("PREC", "{{motor|pragma('precision', 3) }}")
epicsEnvSet("AXISCONFIG", "{{motor|pragma('axisconfig', '')}}")
epicsEnvSet("ECAXISFIELDINIT", "{{motor|pragma('additional_fields', '') }}")
epicsEnvSet("AMPLIFIER_FLAGS", "{{motor|pragma('amplifier_flags', '') }}")
EthercatMCCreateAxis("$(MOTOR_PORT)", "$(AXIS_NO)", "$(AMPLIFIER_FLAGS)", "$(AXISCONFIG)")
dbLoadRecords("EthercatMC.template", "PREFIX=$(MOTOR_PREFIX), MOTOR_NAME=$(MOTOR_NAME), R=$(MOTOR_NAME)-, MOTOR_PORT=$(MOTOR_PORT), ASYN_PORT=$(ASYN_PORT), AXIS_NO=$(AXIS_NO), DESC=$(DESC), PREC=$(PREC), EGU=$(EGU) $(ECAXISFIELDINIT)")
dbLoadRecords("EthercatMCreadback.template", "PREFIX=$(MOTOR_PREFIX), MOTOR_NAME=$(MOTOR_NAME), R=$(MOTOR_NAME)-, MOTOR_PORT=$(MOTOR_PORT), ASYN_PORT=$(ASYN_PORT), AXIS_NO=$(AXIS_NO), DESC=$(DESC), PREC=$(PREC) ")
dbLoadRecords("EthercatMCdebug.template", "PREFIX=$(MOTOR_PREFIX), MOTOR_NAME=$(MOTOR_NAME), MOTOR_PORT=$(MOTOR_PORT), AXIS_NO=$(AXIS_NO), PREC=3")
{% endfor %}
{% endif %}
dbLoadRecords("iocSoft.db", "IOC={{prefix}}")
dbLoadRecords("save_restoreStatus.db", "P={{prefix}}{{pv_delimiter}}")
dbLoadRecords("caPutLog.db", "IOC=$(IOC)")
## TwinCAT task, application, and project information databases ##
{% for priority, (_, task) in plc.instance.task_pous.items() %}
dbLoadRecords("TwinCAT_TaskInfo.db", "PORT=$(ASYN_PORT),PREFIX={{prefix}},IDX={{task.array_index}}")
{% endfor %}
dbLoadRecords("TwinCAT_AppInfo.db", "PORT=$(ASYN_PORT), PREFIX={{prefix}}")
{% set git_sha = project.git_info.sha or "" %}
{%- set short_git_sha = git_sha[:7] %}
dbLoadRecords("TwinCAT_Project.db", "PREFIX={{prefix}},PROJECT={{ project.filename.name }},HASH={{ short_git_sha }},VERSION={{ project.git_info.describe }},PYTMC={{ pytmc_version}},PLC_HOST={{ plc_host }}")
{% for library, info in get_library_versions(plc) | dictsort %}
{%- set libraryname = library | replace(" ", "_") %}
{%- if "PlaceholderReference" in info and "PlaceholderResolution" in info %}
# {{ library }}: {{ info.PlaceholderReference.version }} -> {{ info.PlaceholderResolution.version }} ({{ info.PlaceholderResolution.vendor }})
dbLoadRecords("TwinCAT_Dependency.db", "PREFIX={{prefix}},DEPENDENCY={{ libraryname }},VERSION={{ info.PlaceholderResolution.version }},VENDOR={{ info.PlaceholderResolution.vendor }}")
{% elif "PlaceholderReference" in info %}
# {{ library }}: {{ info.PlaceholderReference.version }} ({{ info.PlaceholderReference.vendor }})
dbLoadRecords("TwinCAT_Dependency.db", "PREFIX={{prefix}},DEPENDENCY={{ libraryname }},VERSION={{ info.PlaceholderReference.version }},VENDOR={{ info.PlaceholderReference.vendor }}")
{% endif %}
{%- endfor %}
cd "$(IOC_TOP)"
## PLC Project Database files ##
{% if plc.tmc %}
{% for db in db_filenames %}
dbLoadRecords("{{ db }}", "PORT=$(ASYN_PORT),{{ db_parameters }}")
{% endfor %}
{%- set queue_size_base = queue_size_base | int %}
{%- set queue_size_scale = queue_size_scale | int %}
{%- set callback_queue_size = queue_size_base + queue_size_scale * num_records %}
# Total records: {{ records | length }}
callbackSetQueueSize({{ callback_queue_size }})
{% endif %}
{% if additional_db_files %}
{% for db in additional_db_files.split(" ") %}
# Load user-specified database: {{ db }}
dbLoadRecords("{{ db }}", "PORT=$(ASYN_PORT),{{ db_parameters }}")
{% endfor %}
{% endif %}
# Autosave and archive settings:
save_restoreSet_status_prefix("{{prefix}}{{pv_delimiter}}")
save_restoreSet_IncompleteSetsOk(1)
save_restoreSet_DatedBackupFiles(1)
set_pass0_restoreFile("info_positions.sav")
set_pass1_restoreFile("info_settings.sav")
{% if production_ioc %}
# ** Production IOC Settings **
set_savefile_path("$(IOC_DATA)/$(IOC)/autosave")
set_requestfile_path("$(IOC_DATA)/$(IOC)/autosave")
# Production IOC autosave files go in iocData:
cd "$(IOC_DATA)/$(IOC)/autosave"
# Create info_positions.req and info_settings.req
makeAutosaveFiles()
cd "$(IOC_DATA)/$(IOC)/archive"
# Create $(IOC).archive
makeArchiveFromDbInfo("$(IOC).archive", "archive")
cd "$(IOC_TOP)"
{% else %}
# ** Development IOC Settings **
# Development IOC autosave and archive files go in the IOC top directory:
cd "$(IOC_TOP)"
# (Development mode) Create info_positions.req and info_settings.req
makeAutosaveFiles()
# (Development mode) Create the archiver file
makeArchiveFromDbInfo("$(IOC).archive", "archive")
{% endif %}
# Configure access security: this is required for caPutLog.
asSetFilename("$(ACF_FILE)")
# Initialize the IOC and start processing records
iocInit()
# Enable logging
iocLogInit()
# Configure and start the caPutLogger after iocInit
epicsEnvSet(EPICS_AS_PUT_LOG_PV, "$(IOC):caPutLog:Last")
# caPutLogInit("HOST:PORT", config)
# config options:
# caPutLogNone -1: no logging (disable)
# caPutLogOnChange 0: log only on value change
# caPutLogAll 1: log all puts
# caPutLogAllNoFilter 2: log all puts no filtering on same PV
caPutLogInit("$(EPICS_CAPUTLOG_HOST):$(EPICS_CAPUTLOG_PORT)", 0)
# Start autosave backups
create_monitor_set( "info_positions.req", 10, "" )
create_monitor_set( "info_settings.req", 60, "" )
{% if production_ioc %}
# All IOCs should dump some common info after initial startup.
< /reg/d/iocCommon/All/post_linux.cmd
{% endif %}