Ladies and gentlemen welcome on board 2
current chapter 24 3
Programming with structure text 4
Let's switch back to our lecture notes 5
Yep simotion programming SITRAIN notes 6
Here at this chapter you will learn about 7
contents 8
Integration of structure text 9
st source 10
specify st source 11
Settings for working with editor 12
Identifiers and syntax coloring in St editor 13
Structure of a ST source file 14
Components of the interface section components of the implementation section 15
Declerations in the interface and implementation Parts decleration 16
part of A program 17
validity and Initializing and variable 18
Overview of simotion data types 19
Elementary data types For siemotion 20
Arrays string structure technology object 21
datatypes 22
And so... 23
Continue next page 24
control statements is if Case for while loops 25
Exit and return key wrods usage 26
Access to individual bits with permit language extension option 27
before wait Go lable condition statement 28
Comment controlling compilation with preprocessor 29
Testing program 30
operationg mode change for program testing in debug mode 31
monitoring variables symbol browser and watch table 32
New functions in St editor as of version 4.2 33
Setting the breakpoint 34
Specify the debug test group of useful other things and so on 35
Let's talk or first page of this chapter 36
Integration of St in Scout 37
You see here in symbol browser compile menu program status 38
st editor is opened under ST1 unit that are several different 39
1 + 2 +3 + 4 40
Three and four Programs located description in interface section 41
there is an implementation section 42
So also an external editor can be used in integrated in 43
simotion workbench if you want 44
To generate an st source for just double click to insert St source for 45
write The name of your source 46
Names are not case sensitive 47
You may use letters numbers or _ 48
and name 49
Contains up to 128 characters 50
you will see here how do specified St Source file compile settings we have already done 51
If you want you can ask someone or read the detail 52
settings for working with St editor 53
You'll see here font-time font size format settings for display 54
I'll see you see here the ccommand library on the left side and project window 55
Identifiers and syntax coloring in the ST editor 56
User-defined name is colored as black 57
Favorite color is blue and contant color as pink 58
comments as color as green color 59
There are some restrictions 60
There is no umlaut 61
That means a double quotation 62
not case sensetive 63
must not start with a digit 64
Names identifiers 65
Should not start with an underscore because it's reserved for siemens 66
And identifiers must not be same as key words 67
Yep 68
So reserved keywords if as program and so on 69
Next page 70
And you see here the structure of an ST source 71
for connection 72
Two other units and execution system unit to describe your 73
Functional interface section of unit 74
and implementation section later on 75
Define and write your own program for function 76
returns a value as 77
You describe 78
at this acse long-real type 64-bits 79
Function block and program 80
So components of interface section 81
Is use package 82
This is the technology package Cam 83
path 84
TCONTROL 85
Possibilities 86
Use Library 87
created Library name 88
uses keywords for 89
Make a connection to other unit 90
Public variables and other types described with type 91
here are the color red yellow blue 92
it is an enumeration 93
Red means zero yellow means one blue means 2 94
This is a type 95
volatile Global variables set an actual as long real the time and 96
It's not initialized this case 97
For specification of public blocks 98
here interface section program name 99
And function name 100
So 101
implementation section 102
The program code for display 103
next thing is components of the implementation section here 104
on this page an Unit example implementation private and unit global 105
variables and datatypes is the similar description type 106
Global variables 107
Not retain 108
Implementation of public and private blocks 109
Program function and function blocks 110
Also 111
We will see in detail later on in next pages that are some decleration party 112
parts inside the function 113
And program and function block 114
so... 115
next page 116
Declerations in the interface and implementation parts 117
global constant decleration 118
Example 119
Real 120
constant as pink color 121
type 122
Real motor 123
Structure 124
There are several different kind of variables inside this motor structure 125
we just Define here are types 126
And later on we will create a new user defined variables 127
of This ttype 128
so one type 129
Maybe consist of 130
One structured one variable or several different type of variables 131
If you already use a different data types in classical Works in simatic 132
you are familiar Description 133
There are some Elementary data types 134
Like Real or long and so on 135
There are other Drive 136
types structures in enumerators 137
Just like this 138
And structure like that 139
and technology object or system data types already described in our 140
CPUs 141
So 142
Global variables for global global constant and var global retain 143
Decleration part of a program you see here 144
In implementation and the program declaration type 145
Local variables 146
And temporary variables 147
As local or local constants 148
here is the Declaration section 149
here Is the program section really 150
so validity of variables unit left and unit right 151
Two examples here 152
you see here with different colors 153
Global device variables here 154
Is accessible from all of the other units 155
Readable and writable 156
You'll see here and the background some simotion device available 157
on the unit left There's interface section and Global variables 158
It's accessible by other units right 159
The same way or vice versa 160
If you are describing 161
local variable Your program test and is has and what it is of usage of this variable 162
If you're using a global variable in your implementation section 163
And validity 164
Is accessible from 165
Program test 1 and program to test 2 166
From inside out 167
Global variables can we declerate in the interface or implementation part of the units 168
local variables can only be used in exercise program in which they wrote declerated 169
Like this 170
These variables can either be monitored in symbol browser 171
nor Accessed from 172
Operator control and monitor devices 173
Like HMI devices or OPC XML server 174
locals Are the private property of the corresponding 175
POU as it were 176
So... 177
If I want to use privates betable I have to do it here as locally 178
next page initializing variables interface and 179
Implementation section 180
initialization on overrall resed or downloads 181
Is possible with retain variables 182
for Non retain or volatile variables initialization on 183
power on and overall reset 184
from stop mode to run mode as version 185
from 4.2 is always done 186
For retain it depends on your choice 187
It's possible to do 188
in download 189
Or with overall reset 190
Next thing 191
For implementation section 192
Initialization on overall reset and download possible for retained Global variables 193
What is the same way for 194
Other Global variables in implementation section what about the program insight? 195
So 196
For static program or function block 197
local variables 198
Initialization 199
Will be done on start of tasks 200
For example switch to stop to run 201
and Temporary variables initialization on program called or function block call 202
That's why the the variables are temporary 203
Normally 204
Inside the program section 205
These are static variables 206
they only reset to initial value is Task is running 207
restarted 208
Yeah 209
in FB this variables are part of instance data 210
Initialization depends upon variable type 211
global retain or volatile which instance 212
If I want to preserve my parameter or online data 213
During CPU runtime 214
Then I have to choose 215
This global global retainer area 216
when i 217
want to choose to use static variable inside my programs or function blocks 218
After task restart or CPU stopped run 219
Even the data 220
is static will be initialized that's an important 221
Overview of the simotion data types are Elementary and 222
Compounds or derived types 223
As you can see 224
So what kind of Elementary data types do we have 225
keywords... 226
bool byte word Integer and double integer types you will see here on the right 227
Column... 228
Real a long real as possible special we use 229
For Action position value or parameters Long real 230
Are memory is quite good enough 231
Yep 232
So array data type 233
here type description 234
A Is all right 235
one dimentional 236
1 to 6 of real time 237
6 columns 238
Matrix is an example type 239
Consist of A 240
That means array inside array and so we will describe two dimensional array 241
and six columns here 242
This is just for tpye description 243
That's it I'm going to create a user variable 244
Static variable here 245
A on the score one B on the score 1 and on the score one 246
Type of A that means 247
A1 is variable of 1 dimentional array data type 248
so We are using 249
elementary data types or combine data types to create new data types 250
And 251
Define deliverables 252
So that way 253
character strings in structure text 254
data type with a maximum length of 255
254 characters 256
Variable declaration is here 257
If you don't use 258
This option the maximum length with be 80 characters as default 259
You can set a maximum length under 260
For example 120 characters is possible 261
An example assignments you see here as his name equals 262
Transporter 263
So with string 264
Characters and variables 265
It's possible to use compression operations like greater or 266
Let's equal and so on string functions 267
located in Library as character streams 268
Concat 269
delete find replace len 270
These are the universal keyboards 271
I guess your familiar already 272
An assignment to byte 273
Bit variables is possible by 274
Of course 20 275
Which connected here 276
You can get the ASCII codes of the character as bytes 277
Or vice versa 278
Conversion from or to 279
So integer real long real is possible 280
Yep 281
there are some notes 282
You should read later on 283
Another data type is structure 284
For example in there is an electrical motor 285
Grouping of components of different data types in the structure is possible 286
here see an example 287
UDT definition as type 288
we will 289
Describe our structure 290
isside type definition motor 291
Consists of set point speed actual speed enable and fault if this case 292
After that is second step we will use this user-defined data type 293
Motor 1 is a motor 294
and we can access subtitles like this 295
Moto R1. 296
setpoint speed 100.0 297
for write 298
data of structure and so on... 299
Yep 300
data type enumerator is limited number of identifier 301
Declaration of axis 302
For instance. Describe a situation or state graph of a guards 303
1 means opening 2 mins open 3 Means closing + 0 means it is closed 304
At this case 305
Type definition is like this grass States 306
Coolest - 1 opening 307
Is 2 308
Open is 0 309
Closing is 310
1 perhaps 311
lets try 312
you can read.... 313
Technology object data types structure and function provided by simotion 314
cam type drive axis... 315
It's like a class structure 316
You can use your own variable 317
Here 318
Define as pos axis 319
Make an 320
You know Arrangements 321
Long as you're my axis variable equals axis one 322
You can use later on in your program available 323
So... 324
TOs structure and functions provided by individual technology 325
packages 326
Yep simotion provides as the following TOs Drive access 327
pos axes following axes 328
measuring input-output system encoder temperature controller 329
And an object. 330
This convert for example 331
Position axis 332
To following axis in our program 333
As an input 334
Statement part of a program see here 335
The statement that program code 336
Equal length * width blah blah blah 337
This isn't right axis here the east branch controls 338
and so on... 339
Types of a statement is value assigment control statement and subroutine execution 340
Or system function calls looks like this 341
ST 342
You'll see here the expressions and operators and Operands in structure text 343
mathemathical or relational operators 344
variables 345
... 346
assigment will be looks like in structure text 347
structure Assignment 348
It's right to assignment entire structure assignment is possible 349
Or component assignment is possible entire array assignment is possible 350
There's no need to use another function like block move 351
or array copy in simatic world 352
So that's why it's sometimes harder to convert your program from simotion 353
to simatic 354
Access IOs and process images you see here that's an identifier 355
it is possible in program 356
but Normally view of Define are symbols in table 357
There's some input image table and there is an output image table 358
And there's another small table 359
named Process image input 360
Process image Inputs or user defined process images 361
Normally this small tables refreshed by System 362
At the beginning of the cycle 363
for inputs at the end of the cycle for outputs 364
So if you want to get the news 365
Level or logic step of an input 366
You should use 367
Process image byte instead of 368
This 369
Deceleration 370
So 371
Logical address space for simotion Drive based system 372
That's quite good enough 373
For other Hardware platforms it's limited weeks 374
4 kilobytes 375
Access to individual bits with the permit language extension compile option 376
But now we see how do we use this function in our program 377
we will described here my results my anybit 378
And make it definition 379
After that if I want to get a bit from 380
a byte 381
Any bits but I will answer here the bit no as 5 382
This is one way to do that 383
without language Extinction you will see here 384
easily byte variable dot 5 385
Results a bit status with language Extension 386
Is possible 387
and for setting bit use this function or language extension here 388
That is also toggle bit functions 389
Is possible to do with xor gate 390
as scout 4.1 391
It is possible to use user-friendly 392
Axis 393
of Individual bits of advice or words of double word is possible 394
next page 395
See the control statement if else case 396
it Looks like this in our user program 397
else fi and this and Case commission is similar to Pascal 398
Programming language so it's look like in MCC 399
This is the same thing in structure text 400
Control statements for vwhile repeats here example 401
usage 402
What's the difference between while and repeat? 403
In while loop program interpolator is running from up to down 404
If the condition is not met that you skip the statements here then your 405
commands 406
For example set the alarm bit is not executed 407
It's a repeat Loop 408
It was see here some statements 409
commands will be Executives here after that the condition will be checked 410
If the condition is not met 411
The program to continue to Next Step 412
At least once your output is set here 413
Because you check the condition after your statement 414
control statements exit and return 415
we will used this statement in or Loops for example 416
If input 1.1 is through the exit Loop 417
This is the endless loop 418
User return in functions 419
is true then return from function to 420
Points or line were it called 421
we will not execute next steps in this function 422
Next page 423
Go to and wait for conditional statement 424
with go to 425
we Create several labels in different places in our program 426
After that 427
It's possible to use go to keyword for jump 428
wait for condition 429
we will call with an expression 430
if Expression is true 431
We will execute some statement 432
So comments 433
Breaking news line come with double / or we may use block commands 434
With that way 435
contorl the compilation with preprocessor 436
Replace the names in ST source 437
Yeah we change is defined and undefined identifiers 438
for compilation 439
It's another useful feature 440
you see 441
And example of use preprocessor 442
An example program code you see here function block definition interface Global variable 443
After that your Define my Define 444
global var 445
At the implementation section there's a function function block 446
So 447
Define assignment var 448
And it's called the 449
my define 450
afterf the preposition 451
Or assignment to f g 1 + 1 452
Not replaced here 453
So I special cases it reduces time 454
but as 455
an Disadvantage your program will be 456
little bit complicated for read 457
soTesting testing programs program status symbol browser for monitoring and 458
Controlling monitor watch table 459
trace tool 460
How do you do that? 461
So I'm Target system or right-click to CPU operating mode 462
It's just switch between modes 463
For test program and switch on the program status on St sides it looks like this 464
There's a program status 465
looks like some 466
Glasses 467
And there isn't stop monitoring 468
Button 469
Is possible to force an update variables 470
This is the monitoring screen divided as vertically on the right 471
side see status of wearables 472
If else ase 473
You'll see your counter variable is 474
Less of 500 that's why 475
You see this site and as condition is not met 476
You'll see here 477
The question marks 478
That's the reason 479
Normal structure text we will use symbol browser to monitor variables 480
Together 481
It's also possible to add to watch table at monitor 482
The group up or user variables 483
There are some new functions in ST editor as of firmware version 484
4.2 485
Context menu with comments for copy and paste lights 486
Changing the view 487
Go to bookmarks startup block 488
and so on... 489
Support for Split windows 490
possible to open 491
Two different page St units 492
Sequence generator 493
Autocomplete with control + space 494
Yeah you're a useful function you said it 495
Index of an array 496
click 497
Or you just enter 498
You 499
alt key Press Ctrl shift on S7 buttons than you see it's automatically arranged 500
You can do it on the other side 501
For instance 502
Set column by column width of alt key and mouse 503
After you press Ctrl + shift key and 504
Function 7 together you see on the right side 505
value are arranged 506
Setting breakpoints structure text is can only be used in program 507
Function block and function 508
And for procedure 509
You have to set up debug mode 510
And specify debug set breakpoints specified equipment 511
Activate breakpoints 512
At last it use variable status to monitor contents of local variables 513
So you can set breakpoints within a program source 514
It's this ST source whatever 515
The preconditions are here 516
already read 517
so see debug task group 518
Yeah 519
First unit to right click and change operating mode to debug mode 520
accept safety notes 521
Okay program source is inconsistent has been changed 522
Okay 523
we changed something yes 524
Let's save and compile 525
You're offline and online program must be 526
Same for debug your program and use the brakepoints 527
When I click right 528
It's now activated about test group and debug table 529
For debug test group assign some of my tasks 530
Which task of CPU should be stopped? 531
When did break point? 532
Is reached 533
I'm going to use motion task one for instance. 534
You can Define your debug table 535
It's manage your break points 536
I will group open my motion test motion program one 537
You'll see here some basic programs 538
And if the toolbar 539
there are some ready to use buttons 540
set Remove brake lines at this case I want at the breakpoint 541
just 1 click 542
If I click again it would be removed and next thing activate deactivate is breakpoint 543
Maybe there are a lot of break points but you don't want to activate 544
Next cycle or next try 545
when I click this 546
It's activated with filled with red 547
When I go 548
Yeah program statistics and monitor the variables 549
And I double Click 550
Here 551
It's activated by the debug mode is working and break point reached 552
at the mean time maybe you want to 553
go device diagnostics at See on task manager 554
You'll see here task is running but there's and Brake active 555
If I could it again 556
Breakpoint will be deactivated 557
It's possible to edit the call path 558
Which property is used for that preference 559
I called this program from more than one but for function blocks you 560
You have to describe it here to monitor 561
Current points is important 562
Activate all breakpoints 563
Of the active POU you if there are five or six breakpoints and when you do 564
Don't want to waste your time and activate all it's possible 565
And that activates 566
delete all breakpoints 567
debug table 568
here 569
You'll see all of the breakpoints in your table you can just like activate deactivate or delete 570
Display the call stack 571
You can debug your call stack here breakpoint is activated everyone 572
you can select 573
Maybe every time or maybe ever 574
20 run 575
is possible 576
then Our program is broken 577
If you want to continue 578
You have to keep the continiue button 579
So 580
In that case 581
Its now running 582
Executing our comments 583
Basically 584
So let's continue with notes 585
Yep 586
If you said it's your old tasks note that all outputs will be deactivated 587
when break point is reached 588
Be careful if you are energizing some contractors or 589
Your outputs connected to 590
Some valves you need to be careful 591
during debug 592
Next page setting breakpoints in St source file 593
Actually is the same way you just said it to your online and use the 594
Same buttons located in your toolbar 595
then you specify the call path 596
Then you can activate deactivate or delete your breakpoints 597
You can use keyboard shortcuts 598
So it's available status 599
Below the screen 600
You can status your variable 601
After program stops 602
You can use breakpoint and program status together 603
to see current 604
values 605
You can record with Device trace or your firmware 606
if is higher than 607
4.2 record variables with system trace 608
here you see device trace and system Trace 609
Unlimited isochron endless trace Servo Factor 2 610
Then you should 611
Use maybe the ring buffer okay 612
Let's add some variable here 613
Some technology objects variable 614
or... 615
Or positioning States 616
yes... 617
It's possible to add until 128 618
i need downloads 619
Parameterization available 620
System trace cannot be used as only device simultaneously okay alright 621
Yes 622
System Trace parameterization 623
Is that start 624
Stop 625
You can change your the active curve standtstill monitoring 626
For the face of position monitoring 627
It's possible to select the other values 628
here with 629
This way 630
Okay 631
a system trace is support data used to report up 128 632
From multiple simotion controllers 633
Together with profinet IRT 634
At the same trigger criteria as for 635
Individual device Trace are available or shooting of a specific volume 636
and so on... 637
Corporate system such as printing process with multiple motor controllers and 638
sync Operation across all devices this is signefficiently reduces 639
Commission also service requirements 640
So the systems trace is in advance 641
Next page 642
Diagnostics with the to trace 643
you will see here technology object trace we're already used to set up 644
Debug our technology objects comments or configuration data change 645
Or system readable change it is also possible 646
Actually the firmware version 4.2 it's was 647
Radical game changer 648
Version and there are a lot of usable features 649
Just like this 650
That's why 651
a lot of Details about this version added 652
later on so... 653
now we have completed our lecture notes for programming with structure 654
I will switch back to 655
simotion projects 656
you will see here or 657
Empty almost empty ST you can Define here some types 658
Structures you can Define your programs here 659
For instance i say empty program 1 that means I will call this program 660
From motion task i will Define here in interface 661
Exportable 662
back program on me so I recorded for background 663
IPO programming means 664
i will call this program from IPO task 665
And I have to Define my program and write some code 666
Implementation section 667
Here it should be 668
Like this 669
end program 670
Yep. 671
This is our empty program 672
This is an empty program 673
This is an empty program let's use preprocessor 674
no error no warning 675
Let's add some variables and 676
variable 677
variable temp 678
Available 679
static so... 680
function block definition is similar 681
Let's see 682
If the test 1 683
Yo 684
FB test 1 685
were 686
input 687
varible 688
outputs 689
varible in out 690
Is possible 691
Another thing is available temp is possible 692
Okay 693
Accept and compile my program as you can see here 694
That are three different programs and 1 function block 695
if i click here 696
the inputs and outputs 697
object browser that are some items it looks like the classical CODESYS 698
based editor 699
You'll see standart Functionality 700
Which device package 701
What is the units POUs Global variables 702
If you're familiar with CODESYS is based 703
Devices or you're using codesys 704
It's really similar to you 705
I told you I think it's a good idea to make some exercises 706
Create a new St unit and write your own programs 707
Execution system with different tasks and see 708
with traces 709
What's going on? 710
Set some breakpoints 711
in your program in structure text 712
Let's try in run mode 713
We are created in units when you are working with structure text 714
It's 715
More 716
Possible to make a download in run 717
when you compare program in MCC 718
That's why it still has an advantage at this point 719
This is another reason why we choose the program which structure text it's basic 720
Easy to copy and paste and it has some advantages 721
So ... 722
We have our program and to program 1 let's set a breakpoint here 723
for program 1 724
There's no code I have to add some code here or make an assignment variable 725
A variable as integer 726
Let's say 727
make and assignment is Equals 728
15 729
So we didn't called our program and MT program 1 730
Maybe we should call First 731
Okay 732
Let's say remove breakpoints 733
No that's a breakpoint here 734
Let's take our glasses to look 735
Program did not want to here your right is not assigned to any task 736
Let's assigned to a task 737
Backgrounds 738
back program accept close 739
Downloading in run 740
Let's try 741
How to change the execution system so 742
I have to stop first then download again 743
Set an alarm 744
I want to work with my back program 745
So 746
Let's add here some variable 747
Okay 748
You went online and offline partner 749
is Persistent after that 750
The old breakpoints is activated to use 751
So let's see here there is a break point 752
Let's monitor available is 150 753
But be careful assigned my program in background so 754
if i Activate 755
The breakpoints 756
Note that brakepoints could be activated do you want to take the 757
The first thing to develop test now and I say yes 758
call positions 759
okay 760
CPU is in run and 761
Debug mode background task to be stopped at this case 762
Let's check the operating States 763
You'll see a background task is running 764
set in simotion 765
in back program I hit to activate 766
Okay 767
Now it's broken and background task is 768
Stop right here as you can see 769
It's not logical to do this operation in background task but it's 770
On the other hand looks like this now or program interpreter located 771
line 49 772
At this point at this breakpoint 773
Then I can continue the same way as the MCC charts just continue 774
at next cycle same breakpoint the program Brooks again 775
I have to deactivate the breakpoints 776
After that I hit the continiue 777
And program continues 778
So I can see it is running so 779
Homework for you create structure program 780
structure text and test your program in simulation 781
See you next time