@tsplc/build 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/python/hardware.py +19 -16
- package/python/worker.py +36 -0
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "git+https://github.com/rip-technologies/tsplc.git",
|
|
16
16
|
"directory": "packages/build"
|
|
17
17
|
},
|
|
18
|
-
"version": "0.4.
|
|
18
|
+
"version": "0.4.3",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"zod": "4.3.6",
|
|
57
|
-
"@tsplc/config": "0.4.
|
|
58
|
-
"@tsplc/typegen": "0.4.
|
|
59
|
-
"@tsplc/iec": "0.4.
|
|
57
|
+
"@tsplc/config": "0.4.3",
|
|
58
|
+
"@tsplc/typegen": "0.4.3",
|
|
59
|
+
"@tsplc/iec": "0.4.3"
|
|
60
60
|
},
|
|
61
61
|
"bin": {
|
|
62
62
|
"tsplc-build": "./dist/cli.js"
|
package/python/hardware.py
CHANGED
|
@@ -129,9 +129,16 @@ def channel_elements(pinned):
|
|
|
129
129
|
elements = dict(pinned)
|
|
130
130
|
for address, channel in pinned.items():
|
|
131
131
|
match = re.match(r"^%([IQ])B(\d+)$", address)
|
|
132
|
-
if match
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
if not match or channel.bit_size != 8:
|
|
133
|
+
continue
|
|
134
|
+
try:
|
|
135
|
+
bits = list(channel)
|
|
136
|
+
except (ValueError, IndexError):
|
|
137
|
+
# A byte with no bit elements, such as a Modbus register's, has no bits to map: CODESYS
|
|
138
|
+
# throws "Index was out of range" instead of ending the iteration.
|
|
139
|
+
continue
|
|
140
|
+
for bit, element in enumerate(bits):
|
|
141
|
+
elements.setdefault("%{0}X{1}.{2}".format(match.group(1), match.group(2), bit), element)
|
|
135
142
|
return elements
|
|
136
143
|
|
|
137
144
|
|
|
@@ -222,10 +229,9 @@ def configure_modbus(engine, project, ethernet, devices):
|
|
|
222
229
|
parameters = host_parameters(server)
|
|
223
230
|
configure_server(parameters, device)
|
|
224
231
|
set_parameter(parameters[MODBUS_PORT], str(device["modbus"]["port"]))
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
for register, channel in channels:
|
|
232
|
+
for register in device["modbus"]["registers"]:
|
|
233
|
+
channel = add_modbus_channel(project, server, register) * MODBUS_CHANNEL
|
|
234
|
+
parameters = host_parameters(server)
|
|
229
235
|
pinned[register["write"]] = parameters[channel + MODBUS_TRIGGER]
|
|
230
236
|
pinned[register["status"]] = parameters[channel + MODBUS_STATUS]
|
|
231
237
|
pinned[register["requests"]] = parameters[channel + MODBUS_REQUESTS]
|
|
@@ -279,13 +285,6 @@ def configure_device_tree(engine, project, tree, root, progress):
|
|
|
279
285
|
set_parameter(parameters[identifier], string_literal(parameters[identifier], value) if key == "interface" else ip_array(value))
|
|
280
286
|
scanner = child_device(ethernet, SCANNER)
|
|
281
287
|
pinned = {}
|
|
282
|
-
registers = [device for device in tree["devices"] if device.get("modbus")]
|
|
283
|
-
if registers:
|
|
284
|
-
# Every write revalidates the whole tree, so the Modbus servers, with few channels, come before
|
|
285
|
-
# the adapters' many. The scanner was added first, so the Modbus client still follows it.
|
|
286
|
-
progress("Generating Modbus TCP devices")
|
|
287
|
-
pinned.update(configure_modbus(engine, project, ethernet, registers))
|
|
288
|
-
progress("Generating EtherNet/IP adapters")
|
|
289
288
|
for device in tree["devices"]:
|
|
290
289
|
identity = import_device_description(engine, device, root)
|
|
291
290
|
adapter = child_device(scanner, (device["name"], identity.type, identity.id, identity.version))
|
|
@@ -295,9 +294,13 @@ def configure_device_tree(engine, project, tree, root, progress):
|
|
|
295
294
|
configure_adapter(parameters, device)
|
|
296
295
|
for address, channel in pin_channels(engine, parameters, device).items():
|
|
297
296
|
if address in pinned:
|
|
298
|
-
raise RuntimeError("{0} overlaps another
|
|
297
|
+
raise RuntimeError("{0} overlaps another adapter".format(address))
|
|
299
298
|
pinned[address] = channel
|
|
300
|
-
|
|
299
|
+
registers = [device for device in tree["devices"] if device.get("modbus")]
|
|
300
|
+
if registers:
|
|
301
|
+
progress("Generating Modbus TCP devices")
|
|
302
|
+
pinned.update(configure_modbus(engine, project, ethernet, registers))
|
|
303
|
+
# Adding a later adapter can reflow earlier automatic addresses.
|
|
301
304
|
settle(pinned)
|
|
302
305
|
map_channels(pinned, tree, project.active_application.get_name())
|
|
303
306
|
return pinned
|
package/python/worker.py
CHANGED
|
@@ -70,6 +70,34 @@ def close_loaded(loaded):
|
|
|
70
70
|
loaded.clear()
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
def held_projects(loaded):
|
|
74
|
+
"""The projects the worker keeps open between commands on purpose."""
|
|
75
|
+
held = [loaded.get("project"), loaded.get("prepared")]
|
|
76
|
+
if loaded.get("finishing") is not None:
|
|
77
|
+
held.append(loaded["finishing"][0])
|
|
78
|
+
if loaded.get("login") is not None:
|
|
79
|
+
held.append(loaded["login"].get("project"))
|
|
80
|
+
return [project for project in held if project is not None]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def close_strays(engine, loaded):
|
|
84
|
+
"""Closes every project open in CODESYS that the worker doesn't hold. A command that fails after
|
|
85
|
+
opening its project, as a download whose device tree CODESYS rejects does, would otherwise leave it
|
|
86
|
+
open as the primary project, and every later command would fail to open its own."""
|
|
87
|
+
projects = getattr(engine, "projects", None)
|
|
88
|
+
if projects is None:
|
|
89
|
+
return
|
|
90
|
+
held = set(os.path.normcase(project.path) for project in held_projects(loaded))
|
|
91
|
+
opened = getattr(projects, "all", None)
|
|
92
|
+
if opened is None:
|
|
93
|
+
primary = getattr(projects, "primary", None)
|
|
94
|
+
opened = [primary] if primary is not None else []
|
|
95
|
+
for project in list(opened):
|
|
96
|
+
if os.path.normcase(project.path) not in held:
|
|
97
|
+
print("Closing {0}, which an earlier command left open".format(project.path))
|
|
98
|
+
project.close()
|
|
99
|
+
|
|
100
|
+
|
|
73
101
|
def serve(engine, directory):
|
|
74
102
|
request_path = os.path.join(directory, "request.json")
|
|
75
103
|
loaded = {}
|
|
@@ -83,6 +111,8 @@ def serve(engine, directory):
|
|
|
83
111
|
os.remove(request_path)
|
|
84
112
|
response = {"id": command["id"], "ok": True}
|
|
85
113
|
try:
|
|
114
|
+
if command["action"] in ("build", "prepare", "online", "login"):
|
|
115
|
+
close_strays(engine, loaded)
|
|
86
116
|
if command["action"] == "build":
|
|
87
117
|
run_build(engine, directory, loaded)
|
|
88
118
|
elif command["action"] == "prepare":
|
|
@@ -106,6 +136,12 @@ def serve(engine, directory):
|
|
|
106
136
|
raise ValueError("Unknown worker action")
|
|
107
137
|
except Exception as error:
|
|
108
138
|
response = {"id": command["id"], "ok": False, "error": traceback.format_exc()}
|
|
139
|
+
# The client reports only the error's last line; the whole traceback stays in codesys.log.
|
|
140
|
+
print(response["error"])
|
|
141
|
+
try:
|
|
142
|
+
close_strays(engine, loaded)
|
|
143
|
+
except Exception:
|
|
144
|
+
print("Closing the failed command's projects failed: {0}".format(traceback.format_exc()))
|
|
109
145
|
if isinstance(error, CompilerError):
|
|
110
146
|
response["diagnostics"] = error.diagnostics
|
|
111
147
|
if getattr(error, "download_required", False):
|