codesysultra 1.0.6 → 1.0.7
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/templates/get_all_tools.py +89 -62
- package/package.json +1 -1
|
@@ -1,44 +1,50 @@
|
|
|
1
|
-
import sys
|
|
1
|
+
import sys
|
|
2
|
+
import scriptengine as script_engine
|
|
3
|
+
import traceback
|
|
4
|
+
import inspect
|
|
2
5
|
|
|
3
6
|
def get_codesys_system_api():
|
|
4
7
|
try:
|
|
5
|
-
print
|
|
8
|
+
print "\\n=== CODESYS Script Engine System API ===\\n"
|
|
6
9
|
|
|
7
|
-
print
|
|
8
|
-
print
|
|
10
|
+
print "=== Script Engine Modules ==="
|
|
11
|
+
print "scriptengine module:"
|
|
9
12
|
for name in dir(script_engine):
|
|
10
13
|
if not name.startswith('_'):
|
|
11
14
|
try:
|
|
12
15
|
obj = getattr(script_engine, name)
|
|
13
16
|
obj_type = type(obj).__name__
|
|
14
|
-
print
|
|
17
|
+
print " %s (%s)" % (name, obj_type)
|
|
15
18
|
|
|
16
19
|
if inspect.isclass(obj):
|
|
17
20
|
try:
|
|
18
|
-
methods = [
|
|
21
|
+
methods = []
|
|
22
|
+
for m in dir(obj):
|
|
23
|
+
if not m.startswith('_') and callable(getattr(obj, m)):
|
|
24
|
+
methods.append(m)
|
|
19
25
|
if methods:
|
|
20
|
-
print
|
|
26
|
+
print " Available methods:"
|
|
21
27
|
for method in sorted(methods)[:20]:
|
|
22
|
-
print
|
|
28
|
+
print " - %s" % method
|
|
23
29
|
if len(methods) > 20:
|
|
24
|
-
print
|
|
30
|
+
print " ... and %d more" % (len(methods) - 20)
|
|
25
31
|
except Exception as e:
|
|
26
|
-
print
|
|
32
|
+
print " Error listing methods: %s" % e
|
|
27
33
|
except Exception as e:
|
|
28
|
-
print
|
|
34
|
+
print " Error: %s" % e
|
|
29
35
|
except Exception as e:
|
|
30
|
-
print
|
|
36
|
+
print " Error: %s" % e
|
|
31
37
|
|
|
32
|
-
print
|
|
38
|
+
print "\\n=== Script Engine Functions ==="
|
|
33
39
|
script_functions = []
|
|
34
40
|
for name in dir(script_engine):
|
|
35
41
|
if not name.startswith('_') and callable(getattr(script_engine, name)):
|
|
36
42
|
script_functions.append(name)
|
|
37
43
|
|
|
38
44
|
for func in sorted(script_functions):
|
|
39
|
-
print
|
|
45
|
+
print " - %s()" % func
|
|
40
46
|
|
|
41
|
-
print
|
|
47
|
+
print "\\n=== Available Enums ==="
|
|
42
48
|
try:
|
|
43
49
|
enums = []
|
|
44
50
|
for name in dir(script_engine):
|
|
@@ -47,96 +53,117 @@ def get_codesys_system_api():
|
|
|
47
53
|
enums.append((name, obj))
|
|
48
54
|
|
|
49
55
|
for enum_name, enum_obj in sorted(enums):
|
|
50
|
-
print
|
|
56
|
+
print "\\n%s:" % enum_name
|
|
51
57
|
try:
|
|
52
|
-
members = [
|
|
53
|
-
for
|
|
54
|
-
|
|
58
|
+
members = []
|
|
59
|
+
for name in dir(enum_obj):
|
|
60
|
+
if not name.startswith('_'):
|
|
61
|
+
members.append(name)
|
|
62
|
+
for member_name in sorted(members):
|
|
63
|
+
try:
|
|
64
|
+
member_value = getattr(enum_obj, member_name)
|
|
65
|
+
print " %s = %s" % (member_name, member_value)
|
|
66
|
+
except Exception as e:
|
|
67
|
+
print " Error: %s" % e
|
|
55
68
|
except Exception as e:
|
|
56
|
-
print
|
|
69
|
+
print " Error: %s" % e
|
|
57
70
|
except Exception as e:
|
|
58
|
-
print
|
|
71
|
+
print " Error: %s" % e
|
|
59
72
|
|
|
60
|
-
print
|
|
61
|
-
print
|
|
73
|
+
print "\\n=== Project Management ==="
|
|
74
|
+
print "script_engine.projects module functions:"
|
|
62
75
|
project_functions = []
|
|
63
76
|
for name in dir(script_engine.projects):
|
|
64
77
|
if not name.startswith('_') and callable(getattr(script_engine.projects, name)):
|
|
65
78
|
project_functions.append(name)
|
|
66
79
|
|
|
67
80
|
for func in sorted(project_functions):
|
|
68
|
-
print
|
|
81
|
+
print " - %s()" % func
|
|
69
82
|
|
|
70
|
-
print
|
|
83
|
+
print "\\n=== POU Types ==="
|
|
71
84
|
try:
|
|
72
85
|
pou_types = []
|
|
73
86
|
for name in dir(script_engine):
|
|
74
87
|
obj = getattr(script_engine, name)
|
|
75
|
-
if
|
|
88
|
+
if 'PouType' in name:
|
|
76
89
|
pou_types.append((name, obj))
|
|
77
90
|
|
|
78
91
|
for type_name, type_obj in pou_types:
|
|
79
|
-
print
|
|
92
|
+
print " %s:" % type_name
|
|
80
93
|
try:
|
|
81
|
-
values = [
|
|
82
|
-
for
|
|
83
|
-
|
|
94
|
+
values = []
|
|
95
|
+
for name in dir(type_obj):
|
|
96
|
+
if not name.startswith('_') and name.isupper():
|
|
97
|
+
values.append(name)
|
|
98
|
+
for value_name in sorted(values):
|
|
99
|
+
try:
|
|
100
|
+
value_value = getattr(type_obj, value_name)
|
|
101
|
+
print " %s = %s" % (value_name, value_value)
|
|
102
|
+
except Exception as e:
|
|
103
|
+
print " Error: %s" % e
|
|
84
104
|
except Exception as e:
|
|
85
|
-
print
|
|
105
|
+
print " Error: %s" % e
|
|
86
106
|
except Exception as e:
|
|
87
|
-
print
|
|
107
|
+
print " Error: %s" % e
|
|
88
108
|
|
|
89
|
-
print
|
|
109
|
+
print "\\n=== Implementation Languages ==="
|
|
90
110
|
try:
|
|
91
111
|
impl_langs = []
|
|
92
112
|
for name in dir(script_engine):
|
|
93
113
|
obj = getattr(script_engine, name)
|
|
94
|
-
if
|
|
114
|
+
if 'ImplementationLanguage' in name:
|
|
95
115
|
impl_langs.append((name, obj))
|
|
96
116
|
|
|
97
117
|
for lang_name, lang_obj in impl_langs:
|
|
98
|
-
print
|
|
118
|
+
print " %s:" % lang_name
|
|
99
119
|
try:
|
|
100
|
-
values = [
|
|
101
|
-
for
|
|
102
|
-
|
|
120
|
+
values = []
|
|
121
|
+
for name in dir(lang_obj):
|
|
122
|
+
if not name.startswith('_') and name.isupper():
|
|
123
|
+
values.append(name)
|
|
124
|
+
for value_name in sorted(values):
|
|
125
|
+
try:
|
|
126
|
+
value_value = getattr(lang_obj, value_name)
|
|
127
|
+
print " %s = %s" % (value_name, value_value)
|
|
128
|
+
except Exception as e:
|
|
129
|
+
print " Error: %s" % e
|
|
103
130
|
except Exception as e:
|
|
104
|
-
print
|
|
131
|
+
print " Error: %s" % e
|
|
105
132
|
except Exception as e:
|
|
106
|
-
print
|
|
133
|
+
print " Error: %s" % e
|
|
107
134
|
|
|
108
|
-
print
|
|
135
|
+
print "\\n=== Version Info ==="
|
|
109
136
|
try:
|
|
110
137
|
version = getattr(script_engine, '__version__', 'Unknown')
|
|
111
|
-
print
|
|
138
|
+
print " Script Engine Version: %s" % version
|
|
112
139
|
except Exception as e:
|
|
113
|
-
print
|
|
140
|
+
print " Error getting version: %s" % e
|
|
114
141
|
|
|
115
|
-
print
|
|
116
|
-
print
|
|
117
|
-
print
|
|
118
|
-
print
|
|
119
|
-
print
|
|
120
|
-
print
|
|
121
|
-
print
|
|
122
|
-
print
|
|
123
|
-
print
|
|
124
|
-
print
|
|
125
|
-
print
|
|
126
|
-
print
|
|
127
|
-
print
|
|
128
|
-
print
|
|
129
|
-
print
|
|
142
|
+
print "\\n=== API Usage Examples ==="
|
|
143
|
+
print "Example 1: Open a project"
|
|
144
|
+
print " project = script_engine.projects.open('C:/Projects/MyProject.project')"
|
|
145
|
+
print ""
|
|
146
|
+
print "Example 2: Create a POU"
|
|
147
|
+
print " parent = project.get_children()[0]"
|
|
148
|
+
print " pou = parent.create_pou(name='MyPOU', type=script_engine.PouType.Program)"
|
|
149
|
+
print ""
|
|
150
|
+
print "Example 3: Get project structure"
|
|
151
|
+
print " def analyze(obj, indent=0):"
|
|
152
|
+
print " print ' ' * indent + obj.get_name()"
|
|
153
|
+
print " if hasattr(obj, 'get_children'):"
|
|
154
|
+
print " for child in obj.get_children():"
|
|
155
|
+
print " analyze(child, indent+1)"
|
|
156
|
+
print " analyze(project)"
|
|
130
157
|
|
|
131
|
-
print
|
|
132
|
-
print
|
|
158
|
+
print "\\n=== Analysis Complete ==="
|
|
159
|
+
print "SCRIPT_SUCCESS: CODESYS system API retrieved successfully."
|
|
133
160
|
sys.exit(0)
|
|
134
161
|
|
|
135
162
|
except Exception as e:
|
|
136
163
|
detailed_error = traceback.format_exc()
|
|
137
164
|
error_message = "Error retrieving CODESYS system API: %s\\n%s" % (e, detailed_error)
|
|
138
|
-
print
|
|
139
|
-
print
|
|
165
|
+
print error_message
|
|
166
|
+
print "SCRIPT_ERROR: %s" % error_message
|
|
140
167
|
sys.exit(1)
|
|
141
168
|
|
|
142
169
|
if __name__ == "__main__":
|