codesysultra 1.0.5 → 1.0.6
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/dist/handlers/tools.js +2 -2
- package/dist/templates/get_all_tools.py +124 -70
- package/package.json +1 -1
package/dist/handlers/tools.js
CHANGED
|
@@ -329,9 +329,9 @@ function registerTools(server, config) {
|
|
|
329
329
|
}
|
|
330
330
|
}));
|
|
331
331
|
server.tool("get_all_tools", // Tool Name
|
|
332
|
-
"Retrieves all available
|
|
332
|
+
"Retrieves all available CODESYS script engine APIs, modules, POU types, and implementation languages.", // Tool Description
|
|
333
333
|
{
|
|
334
|
-
projectFilePath: zod_1.z.string().describe("Path to
|
|
334
|
+
projectFilePath: zod_1.z.string().describe("Path to a CODESYS project file (e.g., 'C:/Projects/MyPLC.project'). Used for context, but the tool retrieves system APIs regardless of specific project.")
|
|
335
335
|
}, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
336
336
|
const { projectFilePath } = args;
|
|
337
337
|
let absPath = path.normalize(path.isAbsolute(projectFilePath) ? projectFilePath : path.join(WORKSPACE_DIR, projectFilePath));
|
|
@@ -1,89 +1,143 @@
|
|
|
1
|
-
import sys, scriptengine as script_engine, os, traceback, inspect
|
|
1
|
+
import sys, scriptengine as script_engine, os, traceback, inspect, pkgutil
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def get_all_tools_and_methods():
|
|
3
|
+
def get_codesys_system_api():
|
|
6
4
|
try:
|
|
7
|
-
|
|
5
|
+
print("\\n=== CODESYS Script Engine System API ===\\n")
|
|
8
6
|
|
|
9
|
-
print("
|
|
7
|
+
print("=== Script Engine Modules ===")
|
|
8
|
+
print("scriptengine module:")
|
|
9
|
+
for name in dir(script_engine):
|
|
10
|
+
if not name.startswith('_'):
|
|
11
|
+
try:
|
|
12
|
+
obj = getattr(script_engine, name)
|
|
13
|
+
obj_type = type(obj).__name__
|
|
14
|
+
print(" %s (%s)" % (name, obj_type))
|
|
15
|
+
|
|
16
|
+
if inspect.isclass(obj):
|
|
17
|
+
try:
|
|
18
|
+
methods = [m for m in dir(obj) if not m.startswith('_') and callable(getattr(obj, m))]
|
|
19
|
+
if methods:
|
|
20
|
+
print(" Available methods:")
|
|
21
|
+
for method in sorted(methods)[:20]:
|
|
22
|
+
print(" - %s" % method)
|
|
23
|
+
if len(methods) > 20:
|
|
24
|
+
print(" ... and %d more" % (len(methods) - 20))
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(" Error listing methods: %s" % e)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(" Error: %s" % e)
|
|
29
|
+
except Exception as e:
|
|
30
|
+
print(" Error: %s" % e)
|
|
10
31
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
print("\\n=== Script Engine Functions ===")
|
|
33
|
+
script_functions = []
|
|
34
|
+
for name in dir(script_engine):
|
|
35
|
+
if not name.startswith('_') and callable(getattr(script_engine, name)):
|
|
36
|
+
script_functions.append(name)
|
|
37
|
+
|
|
38
|
+
for func in sorted(script_functions):
|
|
39
|
+
print(" - %s()" % func)
|
|
40
|
+
|
|
41
|
+
print("\\n=== Available Enums ===")
|
|
42
|
+
try:
|
|
43
|
+
enums = []
|
|
44
|
+
for name in dir(script_engine):
|
|
45
|
+
obj = getattr(script_engine, name)
|
|
46
|
+
if inspect.isclass(obj) and issubclass(obj, int):
|
|
47
|
+
enums.append((name, obj))
|
|
27
48
|
|
|
28
|
-
|
|
49
|
+
for enum_name, enum_obj in sorted(enums):
|
|
50
|
+
print("\\n%s:" % enum_name)
|
|
51
|
+
try:
|
|
52
|
+
members = [(name, value) for name, value in enum_obj.__dict__.items() if not name.startswith('_')]
|
|
53
|
+
for member_name, member_value in sorted(members, key=lambda x: x[0]):
|
|
54
|
+
print(" %s = %s" % (member_name, member_value))
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print(" Error: %s" % e)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
print(" Error listing enums: %s" % e)
|
|
59
|
+
|
|
60
|
+
print("\\n=== Project Management ===")
|
|
61
|
+
print("script_engine.projects module functions:")
|
|
62
|
+
project_functions = []
|
|
63
|
+
for name in dir(script_engine.projects):
|
|
64
|
+
if not name.startswith('_') and callable(getattr(script_engine.projects, name)):
|
|
65
|
+
project_functions.append(name)
|
|
66
|
+
|
|
67
|
+
for func in sorted(project_functions):
|
|
68
|
+
print(" - %s()" % func)
|
|
69
|
+
|
|
70
|
+
print("\\n=== POU Types ===")
|
|
71
|
+
try:
|
|
72
|
+
pou_types = []
|
|
73
|
+
for name in dir(script_engine):
|
|
74
|
+
obj = getattr(script_engine, name)
|
|
75
|
+
if inspect.isclass(obj) and 'PouType' in name:
|
|
76
|
+
pou_types.append((name, obj))
|
|
29
77
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
properties.append(" %s%s: %s" % (indent_str, member_name, type(val).__name__))
|
|
49
|
-
except:
|
|
50
|
-
pass
|
|
51
|
-
|
|
52
|
-
if methods:
|
|
53
|
-
print("%s Methods:" % indent_str)
|
|
54
|
-
for method in methods:
|
|
55
|
-
print(method)
|
|
56
|
-
|
|
57
|
-
if properties:
|
|
58
|
-
print("%s Properties:" % indent_str)
|
|
59
|
-
for prop in properties:
|
|
60
|
-
print(prop)
|
|
61
|
-
|
|
62
|
-
except Exception as e:
|
|
63
|
-
print("%s Error analyzing object: %s" % (indent_str, str(e)))
|
|
78
|
+
for type_name, type_obj in pou_types:
|
|
79
|
+
print(" %s:" % type_name)
|
|
80
|
+
try:
|
|
81
|
+
values = [(name, getattr(type_obj, name)) for name in dir(type_obj) if not name.startswith('_') and name.isupper()]
|
|
82
|
+
for value_name, value_value in values:
|
|
83
|
+
print(" %s = %s" % (value_name, value_value))
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(" Error: %s" % e)
|
|
86
|
+
except Exception as e:
|
|
87
|
+
print(" Error: %s" % e)
|
|
88
|
+
|
|
89
|
+
print("\\n=== Implementation Languages ===")
|
|
90
|
+
try:
|
|
91
|
+
impl_langs = []
|
|
92
|
+
for name in dir(script_engine):
|
|
93
|
+
obj = getattr(script_engine, name)
|
|
94
|
+
if inspect.isclass(obj) and 'ImplementationLanguage' in name:
|
|
95
|
+
impl_langs.append((name, obj))
|
|
64
96
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
for lang_name, lang_obj in impl_langs:
|
|
98
|
+
print(" %s:" % lang_name)
|
|
99
|
+
try:
|
|
100
|
+
values = [(name, getattr(lang_obj, name)) for name in dir(lang_obj) if not name.startswith('_') and name.isupper()]
|
|
101
|
+
for value_name, value_value in values:
|
|
102
|
+
print(" %s = %s" % (value_name, value_value))
|
|
103
|
+
except Exception as e:
|
|
104
|
+
print(" Error: %s" % e)
|
|
105
|
+
except Exception as e:
|
|
106
|
+
print(" Error: %s" % e)
|
|
107
|
+
|
|
108
|
+
print("\\n=== Version Info ===")
|
|
109
|
+
try:
|
|
110
|
+
version = getattr(script_engine, '__version__', 'Unknown')
|
|
111
|
+
print(" Script Engine Version: %s" % version)
|
|
112
|
+
except Exception as e:
|
|
113
|
+
print(" Error getting version: %s" % e)
|
|
74
114
|
|
|
75
|
-
|
|
115
|
+
print("\\n=== API Usage Examples ===")
|
|
116
|
+
print("Example 1: Open a project")
|
|
117
|
+
print(" project = script_engine.projects.open('C:/Projects/MyProject.project')")
|
|
118
|
+
print("")
|
|
119
|
+
print("Example 2: Create a POU")
|
|
120
|
+
print(" parent = project.get_children()[0]")
|
|
121
|
+
print(" pou = parent.create_pou(name='MyPOU', type=script_engine.PouType.Program)")
|
|
122
|
+
print("")
|
|
123
|
+
print("Example 3: Get project structure")
|
|
124
|
+
print(" def analyze(obj, indent=0):")
|
|
125
|
+
print(" print(' ' * indent + obj.get_name())")
|
|
126
|
+
print(" if hasattr(obj, 'get_children'):")
|
|
127
|
+
print(" for child in obj.get_children():")
|
|
128
|
+
print(" analyze(child, indent+1)")
|
|
129
|
+
print(" analyze(project)")
|
|
76
130
|
|
|
77
131
|
print("\\n=== Analysis Complete ===")
|
|
78
|
-
print("SCRIPT_SUCCESS:
|
|
132
|
+
print("SCRIPT_SUCCESS: CODESYS system API retrieved successfully.")
|
|
79
133
|
sys.exit(0)
|
|
80
134
|
|
|
81
135
|
except Exception as e:
|
|
82
136
|
detailed_error = traceback.format_exc()
|
|
83
|
-
error_message = "Error
|
|
137
|
+
error_message = "Error retrieving CODESYS system API: %s\\n%s" % (e, detailed_error)
|
|
84
138
|
print(error_message)
|
|
85
139
|
print("SCRIPT_ERROR: %s" % error_message)
|
|
86
140
|
sys.exit(1)
|
|
87
141
|
|
|
88
142
|
if __name__ == "__main__":
|
|
89
|
-
|
|
143
|
+
get_codesys_system_api()
|