Beckhoff#Let’ use ExST in TwinCAT3!

This article describes the syntax of ExST (Extended Structured Text).

The ST editor in TwinCAT3 is used to program POUs in the IEC-61131-3 programming language “Structured Text (ST)” or “Extended Structured Text”. Its Extended Structured Text is also a TwinCAT proprietary specification that provides certain additional features from the standard IEC 61131-3 language.

Let’s enjoy FA!

Implementation

Assignment S=

Variables can be set using this Operator, and even if the variable triggering S= changes from True>False, it will remain unacknowledged as being set with True.

This functionality is similar to the SET instruction in the ladder language.

Example

In this Example, the variable b1 is set to True when b2 becomes True.

VAR
b1,b2,b3,b4:BOOL;
END_VAR

b1 S=b2;

Result

When b2 is True, b1 is also True at the same time.

And even if b2 returns to False, b1 remains True and Keeps.

ExST assignment R=

The Operator here can be used to Reset variables, so that even if the variable triggering R= changes from True>False, it will remain unacknowledged as being set at False.

This functionality is similar to the Reset instruction in the ladder language.

Example

This Example resets variable b1 to False when b3 becomes True.

VAR
b1,b2,b3,b4:BOOL;
END_VAR

b1 R=b3;

Result

When b3 is True, b1 is also False at the same time.

And even if b2 returns to False, b1 remains False and Keeps.

S=,R=?

In fact, if S= and R= execute at the same time, which has priority, Set or Reset? It depends on whether S= is executed first or R= is executed first. As a matter of course, the last instruction executed will be the last state of the variable.

Example S= First

For example, here is a case where S= is executed and then R= is executed.

b1 S=b2;
b1 R=b3;

Result

Naturally, the final result of b1 will be False.

Example R= First

This is the case where R= is executed and then S= is executed.

b1 R=b3;
b1 S=b2;

Result

The final result of b1 will be True.

Multiple Assignment as expression‐1

This is a specification also found in Siemens’ ST language, a grammar that changes the current value of multiple variables to the same number at the same time.

Example

Exmaple here passes the current value of v4 + 5 and the result of that calculation to v1, v2 and v3 in one line.

VAR
b1,b2,b3,b4:BOOL;
v1,v2,v3,v4,v5:INT;
END_VAR


v4:=100;
v1:=v2:=v3:=v4+5;

Result

Done!The current value of v1 v2 v3 is +5 to the current value of v4.

Multiple Assignment as expression2

In fact, variables of different data types can be batch changed to the same number using the previous syntax for the current value.

Example

Same as the previous Example, but it is the real data type variables that have been batch changed.

VAR
b1,b2,b3,b4:BOOL;
v1,v2,v3,v4,v5:INT;
r1,r2,r3,r4,r5:LREAL;
END_VAR

r1:=r2:=r3:=r4:=v1;

Result

Done!The same result is obtained.

Condition Statement

In the ST language, conditional decisions are often made with IF statements. In fact, TwinCAT allows multiple conditions to be judged together and passed to a Bool variable as True or False.

Example

In the Example below, if v5=100, then b4 will be True and b5 will be True. Conversely, if v5 is not 100, b5 will be False.

VAR
b1,b2,b3,b4,b5:BOOL;
v1,v2,v3,v4,v5:INT;
r1,r2,r3,r4,r5:LREAL;
END_VAR
IF b4:=(v5=100) THEN
b5:=TRUE;
ELSE
b5:=FALSE;
END_IF

Result

Done!v5が100ではない場合、b5がFalseになります。

そしてv5が100であれば、v5がTrueになります。

REF=

The last one is REF=. Simply put, REF= is used to obtain the pointer of a variable and access the corresponding variable indirectly.

The difference is that REF= is always the same data type of the variable to be retrieved, as in a JAPAN PLC accessing a different variable, such as Mitsubishi’s D0Z0. That restriction avoids Runtime errors due to invalid Pointer accesses!。

Example

In this Example, a REF variable called rDUT2 is defined and the Pointer is set to myDut2.

Then, in the program, each variable of rDUT2 is accessed and the current value is changed.

It is important to note that you are not accessing myDut2 directly in the program.

TYPE DUT_Test :
STRUCT
Data1,Data2:REAL;
v1,v2:INT;
END_STRUCT
END_TYPE



rDUT2 REF=myDut2;

rDUT2.Data1:=100;
rDUT2.Data2:=200;
rDUT2.v1:=300;
rDUT2.v2:=122;

rDUT2 REF=myDUT3;
rDUT2.Data1:=500;
rDUT2.Data2:=600;
rDUT2.v1:=12345;
rDUT2.v2:=666;

Result

The result is the same current value for myDUT and rDUT2.

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする