PLC Structure Text Generator
Recently I wrote a code generator for rotary index drive based control.
This generator helps generate the label declaration, manual control code, even the simple flow process for each station.
By all these process done, it generated more than half code in a cylinder based control project, all you need to do is to optmize the flow control for each station.
Generate code:
Generate workflow:
It’s all based on cylinders, so if we got a station with 3 cylinders like this:
Name | Type | Group |
---|---|---|
Down | FbCylinder2x1y | St8 |
Forward | FbCylinder2x1y | St8 |
Clamp | FbCylinder0x1y | St8 |
it generate code below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
gSt8Down Bit VAR_GLOBAL | |
gSt8Forward Bit VAR_GLOBAL | |
gSt8Clamp Bit VAR_GLOBAL | |
uiSt8Down Bit VAR_GLOBAL | |
uiSt8Forward Bit VAR_GLOBAL | |
uiSt8Clamp Bit VAR_GLOBAL | |
ySt8Down Bit VAR_GLOBAL | |
ySt8Forward Bit VAR_GLOBAL | |
ySt8Clamp Bit VAR_GLOBAL | |
cySt8Down FbCylinder2x1y VAR_GLOBAL | |
cySt8Forward FbCylinder2x1y VAR_GLOBAL | |
cySt8Clamp FbCylinder0x1y VAR_GLOBAL | |
xSt8DownOrg Bit VAR_GLOBAL | |
xSt8ForwardOrg Bit VAR_GLOBAL | |
xSt8DownAct Bit VAR_GLOBAL | |
xSt8ForwardAct Bit VAR_GLOBAL | |
wSt8DownOnT Word VAR_GLOBAL | |
wSt8ForwardOnT Word VAR_GLOBAL | |
wSt8ClampOnT Word VAR_GLOBAL | |
wSt8DownOffT Word VAR_GLOBAL | |
wSt8ForwardOffT Word VAR_GLOBAL | |
wSt8ClampOffT Word VAR_GLOBAL | |
wSt8DownTO Word VAR_GLOBAL | |
wSt8ForwardTO Word VAR_GLOBAL | |
*) | |
(* | |
uiSt8Cycle Bit VAR_GLOBAL | |
St8Cycle Bit VAR_GLOBAL | |
autoSt8Cycle Bit VAR_GLOBAL | |
wSt8Index Word VAR_GLOBAL | |
uiSt8Reset Bit VAR_GLOBAL | |
St8InOrg Bit VAR_GLOBAL | |
St8CanGoNext Bit VAR_GLOBAL | |
St8GoNext Bit VAR_GLOBAL | |
St8GoNg Bit VAR_GLOBAL | |
*) | |
// ui command | |
IF not St8Cycle THEN | |
ALTP(uiSt8Down, gSt8Down); | |
ALTP(uiSt8Forward, gSt8Forward); | |
ALTP(uiSt8Clamp, gSt8Clamp); | |
END_IF; | |
IF uiSt8Reset THEN | |
gSt8Down := FALSE; | |
gSt8Forward := FALSE; | |
gSt8Clamp := FALSE; | |
uiSt8Reset := FALSE; | |
END_IF; | |
// error handling | |
IF cySt8Down.oErr THEN | |
SET(cySt8Down.oErrId = ErrCyOn, F50); | |
SET(cySt8Down.oErrId = ErrCyOff, F50); | |
SET(cySt8Down.oErrId = ErrCyBoth, F50); | |
END_IF; | |
IF cySt8Forward.oErr THEN | |
SET(cySt8Forward.oErrId = ErrCyOn, F50); | |
SET(cySt8Forward.oErrId = ErrCyOff, F50); | |
SET(cySt8Forward.oErrId = ErrCyBoth, F50); | |
END_IF; | |
(* error messages | |
ST8 "Down" on state abnormal. | |
ST8 "Down" off state abnormal. | |
ST8 "Down" sensor state abnormal. | |
ST8 "Forward" on state abnormal. | |
ST8 "Forward" off state abnormal. | |
ST8 "Forward" sensor state abnormal. | |
error messages *) | |
// cylinder function block control | |
cySt8Down( | |
iAct := gSt8Down, | |
iRst := gResetAlarm, | |
iLimit1 := xSt8DownOrg, | |
iLimit2 := xSt8DownAct, | |
oDevice =>ySt8Down, | |
iOnTO := wSt8DownTO, | |
iOffTO := wSt8DownTO, | |
iOnDelay := wSt8DownOnT, | |
iOffDelay := wSt8DownOffT); | |
cySt8Forward( | |
iAct := gSt8Forward, | |
iRst := gResetAlarm, | |
iLimit1 := xSt8ForwardOrg, | |
iLimit2 := xSt8ForwardAct, | |
oDevice =>ySt8Forward, | |
iOnTO := wSt8ForwardTO, | |
iOffTO := wSt8ForwardTO, | |
iOnDelay := wSt8ForwardOnT, | |
iOffDelay := wSt8ForwardOffT); | |
cySt8Clamp( | |
iAct := gSt8Clamp, | |
oDevice =>ySt8Clamp, | |
iOnDelay := wSt8ClampOnT, | |
iOffDelay := wSt8ClampOffT); | |
IF autoSt8Cycle THEN | |
St8Cycle := TRUE; | |
wSt8Index := START_STEP; | |
autoSt8Cycle := FALSE; | |
END_IF; | |
St8InOrg := | |
cySt8Down.oOff AND | |
cySt8Forward.oOff AND | |
cySt8Clamp.oOff AND | |
SM8000; | |
St8CanGoNext := | |
NOT gSys.HasError AND | |
NOT cySt8Down.oErr AND | |
NOT cySt8Forward.oErr AND | |
NOT cySt8Clamp.oErr AND | |
SM8000; | |
IF St8Cycle THEN | |
IF St8GoNext AND St8CanGoNext THEN | |
wSt8Index := wSt8Index + 10; | |
St8GoNext := FALSE; | |
END_IF; | |
IF St8GoNg THEN | |
wSt8LastIndex := wSt8Index; | |
wSt8Index := NG_STEP; | |
St8GoNg := FALSE; | |
END_IF; | |
END_IF; | |
With flow process like this:
Name | State | Group |
---|---|---|
Down | on | St1 |
Clamp | on | St1 |
Down | off | St1 |
Forward | on | St1 |
Down | on | St1 |
Clamp | off | St1 |
Down | off | St1 |
it generate code below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2021-01-20T02:24:51.486Z","extensionVersion":"v3.4.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"metadata": { | |
"id": "88eb8072-5ab1-457b-9835-6d92196388a3", | |
"publisherId": "almenon.arepl", | |
"publisherDisplayName": "almenon" | |
}, | |
"name": "arepl", | |
"publisher": "almenon", | |
"version": "2.0.1" | |
}, | |
{ | |
"metadata": { | |
"id": "b689fcc8-d494-4dbf-a228-2c694a578afc", | |
"publisherId": "alefragnani.Bookmarks", | |
"publisherDisplayName": "alefragnani" | |
}, | |
"name": "Bookmarks", | |
"publisher": "alefragnani", | |
"version": "12.1.4" | |
}, | |
{ | |
"metadata": { | |
"id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd", | |
"publisherId": "Shan.code-settings-sync", | |
"publisherDisplayName": "Shan" | |
}, | |
"name": "code-settings-sync", | |
"publisher": "Shan", | |
"version": "3.4.3" | |
}, | |
{ | |
"metadata": { | |
"id": "d0bfc4ab-1d3a-4487-8782-7cf6027b4fff", | |
"publisherId": "ms-dotnettools.csharp", | |
"publisherDisplayName": "ms-dotnettools" | |
}, | |
"name": "csharp", | |
"publisher": "ms-dotnettools", | |
"version": "1.23.8" | |
}, | |
{ | |
"metadata": { | |
"id": "336c3908-bcd0-49ef-a675-1ff566c71136", | |
"publisherId": "alekskrnjaic.fanuctplanguage", | |
"publisherDisplayName": "alekskrnjaic" | |
}, | |
"name": "fanuctplanguage", | |
"publisher": "alekskrnjaic", | |
"version": "0.10.0" | |
}, | |
{ | |
"metadata": { | |
"id": "438221f8-1107-4ccd-a6fe-f3b7fe0856b7", | |
"publisherId": "mhutchie.git-graph", | |
"publisherDisplayName": "mhutchie" | |
}, | |
"name": "git-graph", | |
"publisher": "mhutchie", | |
"version": "1.28.0" | |
}, | |
{ | |
"metadata": { | |
"id": "4de763bd-505d-4978-9575-2b7696ecf94e", | |
"publisherId": "eamodio.gitlens", | |
"publisherDisplayName": "eamodio" | |
}, | |
"name": "gitlens", | |
"publisher": "eamodio", | |
"version": "11.1.3" | |
}, | |
{ | |
"metadata": { | |
"id": "6c2f1801-1e7f-45b2-9b5c-7782f1e076e8", | |
"publisherId": "ms-toolsai.jupyter", | |
"publisherDisplayName": "ms-toolsai" | |
}, | |
"name": "jupyter", | |
"publisher": "ms-toolsai", | |
"version": "2020.12.414227025" | |
}, | |
{ | |
"metadata": { | |
"id": "98790d67-10fa-497c-9113-f6c7489207b2", | |
"publisherId": "yzhang.markdown-all-in-one", | |
"publisherDisplayName": "yzhang" | |
}, | |
"name": "markdown-all-in-one", | |
"publisher": "yzhang", | |
"version": "3.4.0" | |
}, | |
{ | |
"metadata": { | |
"id": "d95cb424-7a5a-4e08-9698-107d6fd590cf", | |
"publisherId": "jebbs.plantuml", | |
"publisherDisplayName": "jebbs" | |
}, | |
"name": "plantuml", | |
"publisher": "jebbs", | |
"version": "2.14.1" | |
}, | |
{ | |
"metadata": { | |
"id": "f1f59ae4-9318-4f3c-a9b5-81b2eaa5f8a5", | |
"publisherId": "ms-python.python", | |
"publisherDisplayName": "ms-python" | |
}, | |
"name": "python", | |
"publisher": "ms-python", | |
"version": "2020.12.424452561" | |
}, | |
{ | |
"metadata": { | |
"id": "a5d8b25c-27b8-421d-a8b0-1681827909b9", | |
"publisherId": "medo64.render-crlf", | |
"publisherDisplayName": "medo64" | |
}, | |
"name": "render-crlf", | |
"publisher": "medo64", | |
"version": "1.5.16" | |
}, | |
{ | |
"metadata": { | |
"id": "261cac81-cd7b-4555-bb41-0c2d2bcd3e70", | |
"publisherId": "Gruntfuggly.todo-tree", | |
"publisherDisplayName": "Gruntfuggly" | |
}, | |
"name": "todo-tree", | |
"publisher": "Gruntfuggly", | |
"version": "0.0.193" | |
}, | |
{ | |
"metadata": { | |
"id": "741dbd61-6f2c-4bc4-94a5-b1ce06f50ba6", | |
"publisherId": "Ahern.urscript", | |
"publisherDisplayName": "Ahern" | |
}, | |
"name": "urscript", | |
"publisher": "Ahern", | |
"version": "0.1.7" | |
}, | |
{ | |
"metadata": { | |
"id": "d96e79c6-8b25-4be3-8545-0e0ecefcae03", | |
"publisherId": "vscodevim.vim", | |
"publisherDisplayName": "vscodevim" | |
}, | |
"name": "vim", | |
"publisher": "vscodevim", | |
"version": "1.18.5" | |
}, | |
{ | |
"metadata": { | |
"id": "ef1b801b-e6bd-4bc3-a4c9-ae841ae62116", | |
"publisherId": "cweijan.vscode-autohotkey-plus", | |
"publisherDisplayName": "cweijan" | |
}, | |
"name": "vscode-autohotkey-plus", | |
"publisher": "cweijan", | |
"version": "2.6.2" | |
}, | |
{ | |
"metadata": { | |
"id": "64d05954-748a-433f-ba3e-edba0227e28e", | |
"publisherId": "MS-CEINTL.vscode-language-pack-zh-hant", | |
"publisherDisplayName": "MS-CEINTL" | |
}, | |
"name": "vscode-language-pack-zh-hant", | |
"publisher": "MS-CEINTL", | |
"version": "1.52.2" | |
}, | |
{ | |
"metadata": { | |
"id": "3065eeeb-33bb-47cd-8269-53eec8ceb284", | |
"publisherId": "Serhioromano.vscode-st", | |
"publisherDisplayName": "Serhioromano" | |
}, | |
"name": "vscode-st", | |
"publisher": "Serhioromano", | |
"version": "1.8.3" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"attempts":1,"previous":{"extension":"1.27.0","vscode":"1.45.1"},"current":{"extension":"1.28.0","vscode":"1.45.1"},"apiAvailable":true,"queue":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"window.zoomLevel": 2, | |
"sync.gist": "c9403f21e8365c63819165ca5515b8be", | |
"sync.autoDownload": true, | |
"sync.autoUpload": true, | |
"todo-tree.tree.showScanModeButton": false, | |
"todo-tree.highlights.enabled": true, | |
"editor.renderControlCharacters": false | |
} |
Written with StackEdit.