Structured Text?

darnbar

Member
Join Date
Feb 2015
Location
Australia
Posts
6
Hi guys,

I'm doing a project, which involves using codesys and I was wondering could someone give me any pointers on where to get started learning about structured text? I have read the manuals accompanying the hardware but they don't seem to be very helpful.Is there anything out there similar to Codeacademy where I could learn?

I have been reading IEC 61131-3: Programming Industrial Systems by Karl-Heinz John and Michael Tiegelkamp but it gives a general outline what ST is.I have also watched some youtube tutorials on it but is there anywhere that is there anywhere there would be a more detailed tutorial for ST?

Many thanks in advance
 
Try AB samples

If you use RSLogix5000 or Studio5000 you can get help from RA site and download samples.

But the fact is that you need to understand C to do structured text. Not hard , depends on your abilities. If you never dealt with C I suggest some C for dummies books first. IEC spec might be little hard to swallow.
 
Do not look to Rockwell ST as a resource for learning ST for Codesys. Rockwell ST is so far removed (in a bad way) from where everyone else is that it would be mostly pointless.

The best thing to do would be to learn/practice any text based language since they all use the same basic constructs (IF, FOR, WHILE, CASE/SWITCH, etc) to familiarize yourself with text based programming. ANSI C is actually pretty close to ST, so it is a good choice with loads of learning resources. I only recommend that because there is a noticeable lack of learning resources for ST directly.

Here is a list of fairly standard keywords:
ACCESS
Defines dynamic access. See also "Dynamic variables".
BIT_CLR
A = BIT_CLR(IN, POS)
A contains the value IN after the bit at position POS is deleted. However, the IN operand remains unchanged.
BIT_SET
A = BIT_SET(IN, POS)
A contains the value IN after the bit at position POS is set. However, the IN operand remains unchanged.
BIT_TST
Determines the value of a bit: A := BIT_TST(IN, POS)
A contains the value of the bit at position POS of operand IN.
BY See FOR statement.
CASE See CASE statement.
DO See WHILE statement.
EDGE
Detects positive and negative edges.
A frequent application error is skipping an expression with EDGE (i.e. with an IF statement).
EDGENEG
Detects negative edges.
A frequent application error is skipping an expression with EDGENEG (i.e. with an IF statement).
EDGEPOS
Detects positive edges.
A frequent application error is skipping an expression with EDGEPOS (i.e. with an IF statement).
ELSE See IF statement.
ELSIF See IF statement.
END_CASE See CASE statement.
END_FOR See FOR statement.
END_IF See IF statement.
END_REPEAT See REPEAT statement.
END_WHILE See WHILE statement.
EXIT See EXIT statement.
FOR See FOR statement.
IF See IF statement.
OF See CASE statement.
REPEAT See REPEAT statement.
RETURN See RETURN statement.
THEN See IF statement.
TO See FOR statement.
UNTIL See REPEAT statement.
WHILE See WHILE statement.

Operators:
ABS
Returns the absolute value of a number. ABS(-2) returns 2.
ACOS
Returns the arc cosine (inverse function of cosine) of a number.
adr
Returns a variable's address.
ADRINST Can only be called from within a function block and returns the instance address of the current function block
AND
Logical AND operation by bit.
ASIN
Returns the arc sine of a number (inverse function of sine).
ASR
Mathematically shifts an operand to the right: A := ASR (IN, N);
Shifts IN to the right by N bits and fills in the left with the sign bit.
ATAN
Returns the arc tangent of a number (inverse function of tangent).
COS
Returns the cosine of a number.
EXP
Exponential function: A := EXP (IN).
EXPT
One operand raised to the power of another operand: A := EXPT (IN1, IN2).
LIMIT
Limitation: A := LIMIT (MIN, IN, MAX);
MIN is the lower limit, MAX is the upper limit for the result. If IN is less than MIN, then the MIN result is returned. If IN is greater than MAX, then the MAX result is returned. Otherwise, the IN result is returned.
LN
Returns the natural logarithm of a number.
LOG
Returns the base-10 logarithm of a number.
MAX
Returns the largest value as the result.
MIN
Returns the smallest value as the result.
MOD Modulo division of a USINT, SINT, INT, UINT, UDINT, DINT type variable by another variable of one of these types.
MOVE The contents of the input variable are copied to the output variable. The := symbol is used as the assignment operator.

"A := B;" is the same as "A := MOVE (B);"
MUX
Selection: A = MUX (CHOICE, IN1, IN2, ... INX);
CHOICE specifies which of the operators IN1, IN2, ... INX is returned as a result.
NOT Negation of a bit operand by bit.
OR
Logical OR operation by bit.
ROL
Left bit rotation of an operand: A := ROL (IN, N);
IN is shifted N times to the left one bit position at a time, the far left bit being pushed in again from the right.
ROR
Right bit rotation of an operand: A := ROR (IN, N);
IN is shifted N times to the right one bit position at a time, the far right bit being pushed in again from the left.
SEL
Binary selection: A := SEL (WAHL, IN1, IN2)
CHOICE must be of type BOOL. If CHOICE is FALSE, then IN1 is returned. Otherwise, IN2 is returned.
SHL
Left bit shift of an operand: A := SHL (IN, N);
IN is shifted left by N bits and filled from the right with zeros.
SHR
Right bit shift of an operand: A := SHR (IN, N);
IN is shifted right by N bits and filled from the left with zeros.
SIN
Returns the sine of a number.
sizeof
If a variable is specified as the operand, then SIZEOF returns the number of bytes needed by the specified variable.
If a type name is specified as the operand, then SIZEOF returns the number of bytes needed by the specified type.
SQRT
Returns the square root of a number.
TAN
Returns the tangent of a number.
TRUNC
Returns the integer part of a number.
XOR
Logical EXCLUSIVE OR operation by bit.

Expressions:
Pentheses (Expression)
Function call FunctionName(parameter list);
Negate -
NOT
Raise to the power **
Multiply *
Divide /
Modulo MOD
Add +
Subtract -
Comparisons <,>,<=,>=
Equal to =
Not equal to <>
Bitwise AND operation AND
Bitwise EXCLUSIVE OR operation XOR
Bitwise OR operation OR

EDIT: The three lists are copy/past from Automation Studio help, but should be more or less the same for whatever flavor of Codesys you are using.
 
Last edited:
Just some advice. I rarely use ST in CoDeSys. I find that the other styles are better suited for most programming functions. ST is best for a few things, and you should learn it, but don't force yourself to use it.
 
I find myself using more and more ST in my programming. Especially with CoDeSys 3 it is the fastest (maybe not always the best) way for me to code.

But, I have had a lot of other programming in my past starting way back when with BASIC on a TI-99/4A. Then some generic BASIC on a CP/M machine in high school, FORTRAN in college then some self taught C and C++.

I have found the hardest thing for people to grasp when learning ST programming is that you never want to stop the program flow. You still have to keep the idea of a PLC scan in mind when programming in ST.
 
Many thanks for the varied and informative replies guys it's very much appreciated.

Hi darnbar, and welcome to the forum!

You don't mention if you use V2 or V3.

Here's the manual for V2.
I took the time to go through the whole manual when I started with Codesys.

http://www.wago.com/wagoweb/documentation/759/eng_manu/333/m07590333_00000000_1en.pdf

Kalle

Thanks for the welcome,it's Codesys V3 I'm using but I will take a look at the manual as it seems to be more detailed than what I have been looking at cheers for that.

I find myself using more and more ST in my programming. Especially with CoDeSys 3 it is the fastest (maybe not always the best) way for me to code.

But, I have had a lot of other programming in my past starting way back when with BASIC on a TI-99/4A. Then some generic BASIC on a CP/M machine in high school, FORTRAN in college then some self taught C and C++.

I have found the hardest thing for people to grasp when learning ST programming is that you never want to stop the program flow. You still have to keep the idea of a PLC scan in mind when programming in ST.

The best thing to do would be to learn/practice any text based language since they all use the same basic constructs (IF, FOR, WHILE, CASE/SWITCH, etc) to familiarize yourself with text based programming. ANSI C is actually pretty close to ST, so it is a good choice with loads of learning resources. I only recommend that because there is a noticeable lack of learning resources for ST directly.

Thanks for the suggestions guys.That's my biggest problem I have no prior programming experience.You're right CapinWinky there is a lack of resources available online (maybe they're keen for people to sign up to their training seminars rather than have the information readily available online).
I'll check to see if there is any tutorials on BASIC and ANSI C that might give me a better understanding of it.

Just some advice. I rarely use ST in CoDeSys. I find that the other styles are better suited for most programming functions. ST is best for a few things, and you should learn it, but don't force yourself to use it.

For my project I will have to create function blocks as the Codesys library is limited, so a general knowledge of ST is needed.
 
and what type of PLC is used.

i see there are more fans of oscat hihi kalle
darnbar what do you need for functions, as most of them are made already in libraries like util.lib etc.
 
and what type of PLC is used.

i see there are more fans of oscat hihi kalle
darnbar what do you need for functions, as most of them are made already in libraries like util.lib etc.

Number 1 for me is SCALE_R()

In Allen Bradley Land this is SCP (Scale with Parameters) and worth twice its weight in Raspberries.
 
Here's a link to a quite assorted library. It seem to be quite popular in Europe.

http://www.oscat.de/component/jdownloads/category/2-oscat-basic.html?Itemid=0

The pdf's contains descriptions of functions.
The zip's contains libraries for div. progr. environments.
The text file contains the ST source code (!)


You might have to click some ack's to get to the download page.

Kalle

Many thanks for the link Kalle I found it to be very helpful.

and what type of PLC is used.

i see there are more fans of oscat hihi kalle
darnbar what do you need for functions, as most of them are made already in libraries like util.lib etc.

Hi shooter,

I think you answered one of my queries on another site. I'm trying to use the DLOG_STORE_FILE_CSV file from codesys_network_121_hf1. But when I copy it over to my base project which is on Codesys V3.5.I'm running into errors with it even when I copy the accompanying DUTs.

I added the OSCAT libraries to my project and seen there is a demo of it available.Is there anyway to extract the demo and associated DUTs and POUs to a blank codesys file so I could go online with it and test it on the hardware?
 

Similar Topics

I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
379
Good evening. I display the step number of a SFC on a display. Sometimes, on a trip, it goes quickly through many steps and I need to prove to...
Replies
1
Views
125
I am trying to set up a piece of equipment with a Horner HE-X4R. I'd like to use structured text and so far I'm just trying to get a basic On/off...
Replies
0
Views
70
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,356
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
485
Back
Top Bottom