@tsplc/build 0.2.17 → 0.2.18
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/cli.js +628 -352
- package/dist/cli.js.map +30 -28
- package/dist/index.js +548 -387
- package/dist/index.js.map +27 -25
- package/dist/libraries.js +68 -27
- package/dist/libraries.js.map +3 -3
- package/docker/Dockerfile +2 -0
- package/docker/Dockerfile.dockerignore +4 -1
- package/docker/Dockerfile.source +3 -0
- package/docker/config.ts +10 -5
- package/docker/runner.ts +140 -127
- package/package.json +54 -53
- package/python/build.py +183 -124
- package/python/codesys_online.py +44 -45
- package/python/hardware.py +9 -9
- package/python/test_build.py +3 -3
- package/python/test_codesys_online.py +18 -12
- package/python/test_installer_packages.py +1 -0
- package/python/worker.py +11 -7
- package/src/artifacts.ts +82 -60
- package/src/build.ts +71 -62
- package/src/cli.ts +109 -100
- package/src/controller-online.ts +400 -425
- package/src/controller-protocol.ts +140 -0
- package/src/controller-session.ts +466 -397
- package/src/device-tree.ts +19 -15
- package/src/diagnostics.ts +59 -49
- package/src/docker-build.ts +217 -156
- package/src/docker-context.ts +49 -27
- package/src/docker-run.ts +137 -111
- package/src/engineering-settings.ts +42 -0
- package/src/host/codesys-command.ts +35 -34
- package/src/host/codesys-host.ts +157 -129
- package/src/host/codesys-worker.ts +318 -301
- package/src/host/windows-path.ts +63 -59
- package/src/import-request.ts +24 -0
- package/src/index.ts +37 -31
- package/src/io.ts +152 -116
- package/src/libraries.ts +214 -146
- package/src/package-path.ts +3 -1
- package/src/run.ts +132 -108
- package/src/runtime-status.ts +25 -19
- package/src/sources.ts +264 -225
- package/src/st/declarations.ts +181 -193
- package/src/st/lexer.ts +102 -118
- package/src/st/parse.ts +193 -171
- package/src/st/reader.ts +47 -42
- package/src/__tests__/fixtures/xml/fb-simple.xml +0 -40
- package/src/__tests__/fixtures/xml/fb-state-machine.xml +0 -86
- package/src/__tests__/fixtures/xml/prg-cyclic.xml +0 -44
- package/src/config.ts +0 -12
package/src/st/parse.ts
CHANGED
|
@@ -1,202 +1,224 @@
|
|
|
1
1
|
import { basename } from "node:path";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
globalSections,
|
|
4
|
+
identifierPattern,
|
|
5
|
+
qualifiers,
|
|
6
|
+
variableSections,
|
|
7
|
+
} from "@tsplc/iec/st";
|
|
8
|
+
import {
|
|
9
|
+
declarationKeywords,
|
|
10
|
+
objectKinds,
|
|
11
|
+
readDeclarationPragmas,
|
|
12
|
+
readDeclarationSections,
|
|
13
|
+
readDeclarationSemicolon,
|
|
14
|
+
readIdentifier,
|
|
15
|
+
readModifiers,
|
|
16
|
+
readType,
|
|
17
|
+
readVariableSection,
|
|
14
18
|
} from "./declarations";
|
|
15
19
|
import type { Token } from "./lexer";
|
|
16
20
|
import { createTokenReader, type TokenReader } from "./reader";
|
|
17
21
|
|
|
18
22
|
export type ObjectKind =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
| (typeof objectKinds)[keyof typeof objectKinds]
|
|
24
|
+
| "dut"
|
|
25
|
+
| "gvl"
|
|
26
|
+
| "action"
|
|
27
|
+
| "get"
|
|
28
|
+
| "set";
|
|
29
|
+
export interface ParsedSource {
|
|
30
|
+
kind: ObjectKind;
|
|
31
|
+
name: string;
|
|
32
|
+
declaration: string;
|
|
33
|
+
implementation?: string;
|
|
34
|
+
returnType?: string;
|
|
35
|
+
dutType?: "structure" | "enumeration" | "union" | "alias";
|
|
36
|
+
persistent?: boolean;
|
|
37
|
+
}
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
39
|
+
interface ParseOptions {
|
|
40
|
+
filename?: string;
|
|
41
|
+
declarationOnly?: boolean;
|
|
42
|
+
name?: string;
|
|
43
|
+
}
|
|
35
44
|
|
|
36
45
|
const dutTypes: Record<string, NonNullable<ParsedSource["dutType"]>> = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
STRUCT: "structure",
|
|
47
|
+
UNION: "union",
|
|
48
|
+
"(": "enumeration",
|
|
40
49
|
};
|
|
41
50
|
|
|
42
51
|
const parseDut = (reader: TokenReader): ParsedSource => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
reader.expect("TYPE");
|
|
53
|
+
readModifiers(reader);
|
|
54
|
+
const name = readIdentifier(reader);
|
|
55
|
+
if (reader.consume("EXTENDS")) {
|
|
56
|
+
readType(reader);
|
|
57
|
+
}
|
|
58
|
+
reader.expect(":");
|
|
59
|
+
readDeclarationPragmas(reader);
|
|
60
|
+
const dutType = dutTypes[reader.peek()?.value ?? ""] ?? "alias";
|
|
61
|
+
while (reader.peek()?.value !== "END_TYPE") {
|
|
62
|
+
if (reader.peek()?.value === "TYPE") {
|
|
63
|
+
reader.fail("Only one TYPE declaration is allowed per file");
|
|
64
|
+
}
|
|
65
|
+
reader.take();
|
|
66
|
+
}
|
|
67
|
+
reader.take();
|
|
68
|
+
reader.consume(";");
|
|
69
|
+
if (reader.peek()) {
|
|
70
|
+
reader.fail("Unexpected content after END_TYPE");
|
|
71
|
+
}
|
|
72
|
+
return { kind: "dut", name, declaration: reader.source, dutType };
|
|
64
73
|
};
|
|
65
74
|
|
|
66
|
-
const parseGlobals = (
|
|
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
|
-
|
|
75
|
+
const parseGlobals = (
|
|
76
|
+
reader: TokenReader,
|
|
77
|
+
options: ParseOptions,
|
|
78
|
+
): ParsedSource => {
|
|
79
|
+
const header = reader.peek();
|
|
80
|
+
let persistent = false;
|
|
81
|
+
while (reader.peek()) {
|
|
82
|
+
readDeclarationPragmas(reader);
|
|
83
|
+
if (!reader.peek()) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (!globalSections.has(reader.peek()?.value ?? "")) {
|
|
87
|
+
reader.fail("Expected a global variable section");
|
|
88
|
+
}
|
|
89
|
+
const start = reader.index;
|
|
90
|
+
readVariableSection(reader);
|
|
91
|
+
// Only the section modifiers select the CODESYS persistent-list object.
|
|
92
|
+
// Comments, pragma strings, and variable names cannot select this role.
|
|
93
|
+
for (const token of reader.tokens.slice(start + 1, reader.index)) {
|
|
94
|
+
if (token.kind !== "word" || !qualifiers.has(token.value)) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
persistent ||= token.value === "PERSISTENT";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const name = options.name ?? basename(reader.filename, ".st");
|
|
101
|
+
if (!identifierPattern.test(name)) {
|
|
102
|
+
reader.fail(
|
|
103
|
+
"Global list requires an IEC filename or an explicit name",
|
|
104
|
+
header,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
kind: "gvl",
|
|
109
|
+
name,
|
|
110
|
+
declaration: reader.source,
|
|
111
|
+
...(persistent && { persistent: true }),
|
|
112
|
+
};
|
|
101
113
|
};
|
|
102
114
|
|
|
103
115
|
const validateImplementation = (reader: TokenReader, tokens: Token[]) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
for (const token of tokens) {
|
|
117
|
+
if (token.kind !== "word") {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (variableSections.has(token.value) || token.value === "END_VAR") {
|
|
121
|
+
reader.fail(
|
|
122
|
+
"Variable declaration outside the declaration section; conditional declaration envelopes are not supported",
|
|
123
|
+
token,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (declarationKeywords.has(token.value)) {
|
|
127
|
+
reader.fail(
|
|
128
|
+
"Nested objects must be separate child files, or the object terminator is mismatched",
|
|
129
|
+
token,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
121
133
|
};
|
|
122
134
|
|
|
123
135
|
const splitObject = (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
reader: TokenReader,
|
|
137
|
+
header: Token,
|
|
138
|
+
kind: ObjectKind,
|
|
139
|
+
options: ParseOptions,
|
|
128
140
|
): Pick<ParsedSource, "declaration" | "implementation"> => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
const terminator =
|
|
142
|
+
header.value === "FUNCTIONBLOCK"
|
|
143
|
+
? "END_FUNCTION_BLOCK"
|
|
144
|
+
: `END_${header.value}`;
|
|
145
|
+
const remaining = reader.tokens.slice(reader.index);
|
|
146
|
+
const terminatorIndex = remaining.findIndex(
|
|
147
|
+
(token) => token.kind === "word" && token.value === terminator,
|
|
148
|
+
);
|
|
149
|
+
// Even interfaces and properties need END_* in combined files. Only an explicit
|
|
150
|
+
// declaration-only input (e.g. a paired declaration.st) may omit it.
|
|
151
|
+
if (terminatorIndex < 0 && !options.declarationOnly) {
|
|
152
|
+
reader.fail(`Missing ${terminator}`);
|
|
153
|
+
}
|
|
154
|
+
const bodyTokens =
|
|
155
|
+
terminatorIndex < 0 ? remaining : remaining.slice(0, terminatorIndex);
|
|
156
|
+
const [endToken, next, afterSemicolon] =
|
|
157
|
+
terminatorIndex < 0 ? [] : remaining.slice(terminatorIndex);
|
|
158
|
+
const semicolon = next?.value === ";" ? next : undefined;
|
|
159
|
+
const unexpected = semicolon ? afterSemicolon : next;
|
|
160
|
+
if (unexpected) {
|
|
161
|
+
reader.fail(`Unexpected content after ${terminator}`, unexpected);
|
|
162
|
+
}
|
|
163
|
+
validateImplementation(reader, bodyTokens);
|
|
149
164
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
const declarationOnly =
|
|
166
|
+
options.declarationOnly || kind === "interface" || kind === "property";
|
|
167
|
+
if (declarationOnly && bodyTokens.length) {
|
|
168
|
+
reader.fail(
|
|
169
|
+
"Unexpected implementation in a declaration-only object",
|
|
170
|
+
bodyTokens[0],
|
|
171
|
+
);
|
|
172
|
+
}
|
|
154
173
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
const declaration = reader.source.slice(0, reader.end);
|
|
175
|
+
// Remove only END_* and its optional semicolon. Keep whitespace and trailing
|
|
176
|
+
// comments in the body, or in the declaration for objects without a body.
|
|
177
|
+
const body =
|
|
178
|
+
reader.source.slice(reader.end, endToken?.start) +
|
|
179
|
+
(endToken ? reader.source.slice((semicolon ?? endToken).end) : "");
|
|
180
|
+
if (declarationOnly) {
|
|
181
|
+
return { declaration: declaration + body };
|
|
182
|
+
}
|
|
183
|
+
return { declaration, implementation: body };
|
|
165
184
|
};
|
|
166
185
|
|
|
167
186
|
const parsePou = (reader: TokenReader, options: ParseOptions): ParsedSource => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
const header = reader.take();
|
|
188
|
+
if (!(header.value in objectKinds)) {
|
|
189
|
+
reader.fail(`Unsupported object header ${header.value}`, header);
|
|
190
|
+
}
|
|
191
|
+
const kind = objectKinds[header.value as keyof typeof objectKinds];
|
|
192
|
+
readModifiers(reader);
|
|
193
|
+
const name = readIdentifier(reader);
|
|
194
|
+
const returnType = reader.consume(":") ? readType(reader) : undefined;
|
|
195
|
+
if (returnType === undefined && kind === "property") {
|
|
196
|
+
reader.fail(`${header.value} requires a return type`);
|
|
197
|
+
}
|
|
198
|
+
// Exported declarations may terminate the header itself with a semicolon.
|
|
199
|
+
readDeclarationSemicolon(reader);
|
|
200
|
+
readDeclarationSections(reader);
|
|
201
|
+
return {
|
|
202
|
+
kind,
|
|
203
|
+
name,
|
|
204
|
+
...(returnType === undefined ? {} : { returnType }),
|
|
205
|
+
...splitObject(reader, header, kind, options),
|
|
206
|
+
};
|
|
188
207
|
};
|
|
189
208
|
|
|
190
209
|
/** Parse only the object envelope and declarations. CODESYS validates executable ST. */
|
|
191
|
-
export const parseSource = (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
210
|
+
export const parseSource = (
|
|
211
|
+
source: string,
|
|
212
|
+
options: ParseOptions = {},
|
|
213
|
+
): ParsedSource => {
|
|
214
|
+
const reader = createTokenReader(source, options.filename ?? "<source>");
|
|
215
|
+
readDeclarationPragmas(reader);
|
|
216
|
+
const header = reader.peek();
|
|
217
|
+
if (header?.value === "TYPE") {
|
|
218
|
+
return parseDut(reader);
|
|
219
|
+
}
|
|
220
|
+
if (header && globalSections.has(header.value)) {
|
|
221
|
+
return parseGlobals(reader, options);
|
|
222
|
+
}
|
|
223
|
+
return parsePou(reader, options);
|
|
202
224
|
};
|
package/src/st/reader.ts
CHANGED
|
@@ -2,49 +2,54 @@ import { StSyntaxError, type Token, tokenize } from "./lexer";
|
|
|
2
2
|
|
|
3
3
|
/** Traverse tokens without losing the source offsets needed for an exact split. */
|
|
4
4
|
export const createTokenReader = (source: string, filename: string) => {
|
|
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
|
-
|
|
5
|
+
const tokens = tokenize(source, filename);
|
|
6
|
+
let index = 0;
|
|
7
|
+
const peek = (ahead = 0) => tokens[index + ahead];
|
|
8
|
+
const fail = (message: string, token = peek()): never => {
|
|
9
|
+
throw new StSyntaxError(
|
|
10
|
+
source,
|
|
11
|
+
token?.start ?? source.length,
|
|
12
|
+
filename,
|
|
13
|
+
message,
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
const take = (): Token => {
|
|
17
|
+
const token = peek();
|
|
18
|
+
if (!token) {
|
|
19
|
+
return fail("Unexpected end of declaration");
|
|
20
|
+
}
|
|
21
|
+
index++;
|
|
22
|
+
return token;
|
|
23
|
+
};
|
|
24
|
+
const expect = (value: string) => {
|
|
25
|
+
if (peek()?.value !== value) {
|
|
26
|
+
fail(`Expected ${value}`);
|
|
27
|
+
}
|
|
28
|
+
return take();
|
|
29
|
+
};
|
|
30
|
+
const consume = (value: string) => {
|
|
31
|
+
if (peek()?.value === value) {
|
|
32
|
+
return take();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
return {
|
|
37
|
+
source,
|
|
38
|
+
filename,
|
|
39
|
+
tokens,
|
|
40
|
+
peek,
|
|
41
|
+
take,
|
|
42
|
+
expect,
|
|
43
|
+
consume,
|
|
44
|
+
fail,
|
|
45
|
+
get index() {
|
|
46
|
+
return index;
|
|
47
|
+
},
|
|
48
|
+
// The declaration ends at the last consumed token, before any body whitespace.
|
|
49
|
+
get end() {
|
|
50
|
+
return tokens[index - 1]?.end ?? 0;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
export type TokenReader = ReturnType<typeof createTokenReader>;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<project xmlns="http://www.plcopen.org/xml/tc6_0200" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
3
|
-
<fileHeader companyName="" productName="CODESYS" productVersion="CODESYS V3.5 SP21" creationDateTime="<NORMALIZED>" />
|
|
4
|
-
<contentHeader name="FB_Simple" modificationDateTime="<NORMALIZED>">
|
|
5
|
-
<coordinateInfo>
|
|
6
|
-
<fbd><scaling x="1" y="1" /></fbd>
|
|
7
|
-
<ld><scaling x="1" y="1" /></ld>
|
|
8
|
-
<sfc><scaling x="1" y="1" /></sfc>
|
|
9
|
-
</coordinateInfo>
|
|
10
|
-
</contentHeader>
|
|
11
|
-
<types>
|
|
12
|
-
<dataTypes />
|
|
13
|
-
<pous>
|
|
14
|
-
<pou name="FB_Simple" pouType="functionBlock">
|
|
15
|
-
<interface>
|
|
16
|
-
<inputVars>
|
|
17
|
-
<variable name="bEnable">
|
|
18
|
-
<type><BOOL /></type>
|
|
19
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Enable command</xhtml></documentation>
|
|
20
|
-
</variable>
|
|
21
|
-
</inputVars>
|
|
22
|
-
<outputVars>
|
|
23
|
-
<variable name="bDone">
|
|
24
|
-
<type><BOOL /></type>
|
|
25
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Done flag</xhtml></documentation>
|
|
26
|
-
</variable>
|
|
27
|
-
</outputVars>
|
|
28
|
-
</interface>
|
|
29
|
-
<body>
|
|
30
|
-
<ST>
|
|
31
|
-
<xhtml xmlns="http://www.w3.org/1999/xhtml"><![CDATA[bDone := bEnable;]]></xhtml>
|
|
32
|
-
</ST>
|
|
33
|
-
</body>
|
|
34
|
-
</pou>
|
|
35
|
-
</pous>
|
|
36
|
-
</types>
|
|
37
|
-
<instances>
|
|
38
|
-
<configurations />
|
|
39
|
-
</instances>
|
|
40
|
-
</project>
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<project xmlns="http://www.plcopen.org/xml/tc6_0200" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
3
|
-
<fileHeader companyName="" productName="CODESYS" productVersion="CODESYS V3.5 SP21" creationDateTime="<NORMALIZED>" />
|
|
4
|
-
<contentHeader name="FB_StateMachine" modificationDateTime="<NORMALIZED>">
|
|
5
|
-
<coordinateInfo>
|
|
6
|
-
<fbd><scaling x="1" y="1" /></fbd>
|
|
7
|
-
<ld><scaling x="1" y="1" /></ld>
|
|
8
|
-
<sfc><scaling x="1" y="1" /></sfc>
|
|
9
|
-
</coordinateInfo>
|
|
10
|
-
</contentHeader>
|
|
11
|
-
<types>
|
|
12
|
-
<dataTypes />
|
|
13
|
-
<pous>
|
|
14
|
-
<pou name="FB_StateMachine" pouType="functionBlock">
|
|
15
|
-
<interface>
|
|
16
|
-
<inputVars>
|
|
17
|
-
<variable name="bExecute">
|
|
18
|
-
<type><BOOL /></type>
|
|
19
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Rising edge starts cycle</xhtml></documentation>
|
|
20
|
-
</variable>
|
|
21
|
-
<variable name="tTimeout">
|
|
22
|
-
<type><TIME /></type>
|
|
23
|
-
<initialValue><simpleValue value="T#5s" /></initialValue>
|
|
24
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Operation timeout</xhtml></documentation>
|
|
25
|
-
</variable>
|
|
26
|
-
</inputVars>
|
|
27
|
-
<outputVars>
|
|
28
|
-
<variable name="bDone">
|
|
29
|
-
<type><BOOL /></type>
|
|
30
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Cycle complete</xhtml></documentation>
|
|
31
|
-
</variable>
|
|
32
|
-
<variable name="bBusy">
|
|
33
|
-
<type><BOOL /></type>
|
|
34
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Cycle in progress</xhtml></documentation>
|
|
35
|
-
</variable>
|
|
36
|
-
<variable name="bErr">
|
|
37
|
-
<type><BOOL /></type>
|
|
38
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Cycle errored</xhtml></documentation>
|
|
39
|
-
</variable>
|
|
40
|
-
<variable name="nErrId">
|
|
41
|
-
<type><INT /></type>
|
|
42
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Error ID</xhtml></documentation>
|
|
43
|
-
</variable>
|
|
44
|
-
</outputVars>
|
|
45
|
-
<localVars>
|
|
46
|
-
<variable name="nState">
|
|
47
|
-
<type><INT /></type>
|
|
48
|
-
<initialValue><simpleValue value="0" /></initialValue>
|
|
49
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">State machine pointer</xhtml></documentation>
|
|
50
|
-
</variable>
|
|
51
|
-
<variable name="fbTimer">
|
|
52
|
-
<type><derived name="TON" /></type>
|
|
53
|
-
<documentation><xhtml xmlns="http://www.w3.org/1999/xhtml">Timeout watchdog</xhtml></documentation>
|
|
54
|
-
</variable>
|
|
55
|
-
</localVars>
|
|
56
|
-
</interface>
|
|
57
|
-
<body>
|
|
58
|
-
<ST>
|
|
59
|
-
<xhtml xmlns="http://www.w3.org/1999/xhtml"><![CDATA[CASE nState OF
|
|
60
|
-
0: (* IDLE *)
|
|
61
|
-
IF bExecute THEN
|
|
62
|
-
nState := 10;
|
|
63
|
-
END_IF
|
|
64
|
-
10: (* WORKING *)
|
|
65
|
-
bBusy := TRUE;
|
|
66
|
-
fbTimer(IN := TRUE, PT := tTimeout);
|
|
67
|
-
IF fbTimer.Q THEN
|
|
68
|
-
nState := 99;
|
|
69
|
-
nErrId := 100;
|
|
70
|
-
END_IF
|
|
71
|
-
90: (* DONE *)
|
|
72
|
-
bDone := TRUE;
|
|
73
|
-
bBusy := FALSE;
|
|
74
|
-
99: (* ERROR *)
|
|
75
|
-
bErr := TRUE;
|
|
76
|
-
bBusy := FALSE;
|
|
77
|
-
END_CASE]]></xhtml>
|
|
78
|
-
</ST>
|
|
79
|
-
</body>
|
|
80
|
-
</pou>
|
|
81
|
-
</pous>
|
|
82
|
-
</types>
|
|
83
|
-
<instances>
|
|
84
|
-
<configurations />
|
|
85
|
-
</instances>
|
|
86
|
-
</project>
|