Join us today!
Structuring ST Code in TwinCAT - Creating Regions
You can structure your Structured Text program to separate your block of your code. It would help you to identify what you have coded in that specific region and enable you to navigate easier.
Method 1 using commenting:
//////////////////////////////////////////////////////// //Initialize the values (*your code here*) //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// //Start the machine (*your code here*) ////////////////////////////////////////////////////////
After collapsing the descriptions, the code looks like this:
Method 2 using pragma:
{region "Description"} // code {endregion} {region "Initialize the values"} // your code here {endregion} {region "Start the machine"} // your code here {endregion}
"region" pragma allows you to create regions in your code.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
Maybe this is a nice feature for auto generated code, I would not use it for normal code. If you see the need to use regions, then your methods are just too long/complicated.
My blog: https://cookncode.com/twincat
My code: https://github.com/roald87
@rruiter That's right! Ideally, your methods/code should be self explanatory that you don't even need to use comments. However, in reality that's not the case unfortunately. I've seen many interesting PLC programs that I wish they had used at least regions in the code.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
- 17 Forums
- 267 Topics
- 924 Posts
- 1 Online
- 737 Members