@tsplc/build 0.4.2 → 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 +10 -3
- 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
|
|
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):
|