1

00:00:00,256  -->  00:00:06,400
Hello my name is caner and siemens simotion system

2

00:00:06,656  -->  00:00:09,984
And programming course if this chapter

3

00:00:10,240  -->  00:00:12,800
chapter is 25

4

00:00:13,056  -->  00:00:18,432
we will learn about functions and function blocks

5

00:00:18,688  -->  00:00:24,832
Let's open our sitrain motion program notes

6

00:00:26,112  -->  00:00:28,160
What you will learn

7

00:00:29,696  -->  00:00:31,488
this course

8

00:00:31,744  -->  00:00:34,304
Contents are

9

00:00:35,072  -->  00:00:38,400
Blocks for structured programming

10

00:00:38,656  -->  00:00:44,800
Properties of functions define a function in St source

11

00:00:45,824  -->  00:00:49,408
Declaration and statement part of a function

12

00:00:49,664  -->  00:00:52,224
Calling user function

13

00:00:52,480  -->  00:00:55,808
Short form of user functions

14

00:00:57,088  -->  00:00:57,856
calls

15

00:00:58,368  -->  00:01:01,184
arrays with Dynamic lengths

16

00:01:02,464  -->  00:01:07,072
It's possible from 4.2

17

00:01:07,584  -->  00:01:11,424
Properties of function block defining a function block

18

00:01:12,192  -->  00:01:17,824
Parameters in function block standard functions in simotion

19

00:01:18,336  -->  00:01:21,152
standart function block in simotion

20

00:01:22,944  -->  00:01:24,992
Axis

21

00:01:25,504  -->  00:01:30,368
Technology objects and so on...

22

00:01:31,904  -->  00:01:33,184
Let's start

23

00:01:34,464  -->  00:01:39,840
That's the first page you see here block for structured programming

24

00:01:41,632  -->  00:01:43,680
There's a cyclic task

25

00:01:44,448  -->  00:01:49,568
there is one motor and controller for the motor that are some valves

26

00:01:49,824  -->  00:01:55,456
limit values and coping procedure at the background task

27

00:01:55,968  -->  00:01:57,760
you will see here

28

00:01:58,272  -->  00:02:02,112
Motor 1 in example for consist of

29

00:02:02,368  -->  00:02:08,512
Starting. Inputs and output of this

30

00:02:08,768  -->  00:02:10,560
Function or function block

31

00:02:11,840  -->  00:02:12,864
So

32

00:02:16,960  -->  00:02:23,104
Subtask are solved in separate which model of programming

33

00:02:23,360  -->  00:02:28,224
Parameterisation makes for flexible application

34

00:02:28,992  -->  00:02:35,136
Reusable of blocks libraries Blocks can be called and unlimited number

35

00:02:36,416  -->  00:02:41,280
So basically you define or design

36

00:02:42,048  -->  00:02:43,584
A motor block

37

00:02:43,840  -->  00:02:49,984
Function or function block then you have

38

00:02:50,240  -->  00:02:56,384
100 Motors in your system for instance

39

00:02:56,640  -->  00:02:57,408
This

40

00:02:57,664  -->  00:03:02,016
function Block instance 400 times

41

00:03:02,528  -->  00:03:08,160
And assign the input and output related to each motor

42

00:03:09,696  -->  00:03:12,000
There are some restriction

43

00:03:12,256  -->  00:03:18,400
No axis to global operand from inside the function communication

44

00:03:18,656  -->  00:03:21,472
List

45

00:03:25,056  -->  00:03:27,872
Best idea

46

00:03:28,384  -->  00:03:31,712
Properties of functions

47

00:03:31,968  -->  00:03:33,248
Or

48

00:03:33,504  -->  00:03:39,648
Parameterizeable blocks any number of input parameters and number

49

00:03:39,904  -->  00:03:41,696
No parameters

50

00:03:42,976  -->  00:03:46,048
no memory

51

00:03:46,560  -->  00:03:50,656
there are temporary available only in functions

52

00:03:51,424  -->  00:03:55,264
This is the difference between function and function block

53

00:03:55,776  -->  00:04:00,640
Only one of the parameter is ret val

54

00:04:01,408  -->  00:04:06,784
You define the datatype real or whatever

55

00:04:08,064  -->  00:04:13,440
you don't use global variables and  you don't use

56

00:04:13,696  -->  00:04:17,024
 absolute operands and global address

57

00:04:17,280  -->  00:04:18,303
no meaning

58

00:04:19,071  -->  00:04:25,215
return an identical result with the same input parameters is possible via function

59

00:04:27,263  -->  00:04:33,407
If your programmer and you have already commissioned some projects in simatic manager

60

00:04:33,663  -->  00:04:35,199
This is the same

61

00:04:35,967  -->  00:04:38,527
As function and function block idea

62

00:04:45,183  -->  00:04:49,535
How do we Define a function in ST source

63

00:04:50,303  -->  00:04:52,095
You see here the unit

64

00:04:52,863  -->  00:04:56,447
Interface and implementation area

65

00:04:57,215  -->  00:05:03,359
Let's say function my function that are described in implementation area

66

00:05:04,383  -->  00:05:06,943
The return value some type

67

00:05:11,551  -->  00:05:17,695
I have defined by myself as user-defined data type here in interface section

68

00:05:19,231  -->  00:05:21,535
And there are some

69

00:05:22,047  -->  00:05:23,839
Other inout 

70

00:05:24,095  -->  00:05:27,935
parameters and this is my program code for function

71

00:05:38,687  -->  00:05:41,759
Decleration part of a function

72

00:05:44,063  -->  00:05:48,927
You'll see here type definition inside the function

73

00:05:49,695  -->  00:05:50,463
inputs

74

00:05:51,487  -->  00:05:52,255
inout

75

00:05:52,767  -->  00:05:55,839
And some variables temporary

76

00:05:58,399  -->  00:06:04,543
Input parameters and variables can initialize inout parameters can not be initialized

77

00:06:06,591  -->  00:06:12,735
assigment is important assignment of the return value you'll see here

78

00:06:12,991  -->  00:06:17,087
Assignment equals blah blah blah

79

00:06:20,671  -->  00:06:26,815
Statement of a function is here right access to a variable

80

00:06:27,071  -->  00:06:32,191
temporary is variable assignment

81

00:06:33,727  -->  00:06:38,847
At the end of the function statement that are some real axis

82

00:06:40,639  -->  00:06:43,967
how call user The functions

83

00:06:44,991  -->  00:06:49,087
You will see in Main program

84

00:06:49,343  -->  00:06:53,183
I just call value the functioning

85

00:06:54,207  -->  00:06:59,071
actual parameters ST call

86

00:06:59,327  -->  00:07:02,655
I assign here

87

00:07:02,911  -->  00:07:04,191
A variable

88

00:07:05,727  -->  00:07:09,567
These are the formal input parameters of the FC

89

00:07:13,663  -->  00:07:19,807
Especially as the type of assignment is neither possible or necessary

90

00:07:20,575  -->  00:07:26,719
with the other data types return will you must always be assigned to a variable

91

00:07:32,607  -->  00:07:36,191
And the short form of function calls

92

00:07:36,703  -->  00:07:42,591
In this example the function name is start Task and enable axes

93

00:07:43,871  -->  00:07:49,247
So return with you is MCC Red Double integer as

94

00:07:50,271  -->  00:07:51,807
Described here

95

00:07:55,391  -->  00:07:58,975
you see action parameters of the FC call

96

00:08:01,279  -->  00:08:05,119
leading axis all active inactive

97

00:08:06,911  -->  00:08:08,703
You don't see here

98

00:08:08,959  -->  00:08:13,567
symbolic name of input and output

99

00:08:14,079  -->  00:08:18,687
Items just a assigment Just actual parameters off

100

00:08:19,711  -->  00:08:24,063
Function so this is the short form called

101

00:08:24,831  -->  00:08:30,207
This is the long form

102

00:08:31,487  -->  00:08:32,511
Next page

103

00:08:33,279  -->  00:08:36,351
arrays with Dynamic length

104

00:08:38,911  -->  00:08:45,055
for inout parameters FC FB it's possible to use

105

00:08:45,311  -->  00:08:51,455
Dynamic length in arrays address of decleration

106

00:08:51,711  -->  00:08:54,783
Specification of limits for index

107

00:08:55,807  -->  00:08:57,087
So

108

00:08:58,623  -->  00:09:04,767
This is an example of usage access the lengths and limits of every possible via system functions

109

00:09:06,815  -->  00:09:12,703
Last index of array

110

00:09:13,727  -->  00:09:17,567
It's value type double integer for these

111

00:09:19,359  -->  00:09:23,199
Axis occupied memory via sizeof

112

00:09:24,223  -->  00:09:26,527
this functions is usable

113

00:09:27,551  -->  00:09:32,671
To create and manage array data type variable

114

00:09:32,927  -->  00:09:36,767
Properties of function blocks

115

00:09:37,279  -->  00:09:43,423
Call forms to IEC standart. Any number of input output parameters possible

116

00:09:43,679  -->  00:09:44,959
with memory

117

00:09:45,727  -->  00:09:51,871
not just temporarily also use static variables that's why we have to ask

118

00:09:52,127  -->  00:09:55,199
Assign an instance for function blocks

119

00:09:55,455  -->  00:09:58,271
Call with seperate data area.

120

00:09:59,039  -->  00:10:01,599
But the encapsulation is possible

121

00:10:02,111  -->  00:10:04,671
Application in cyclic task

122

00:10:04,927  -->  00:10:11,071
Timer and counter basically actuated process units with internal States

123

00:10:12,863  -->  00:10:15,167
drives valves ... I'm so on

124

00:10:15,679  -->  00:10:16,959
you see here

125

00:10:21,311  -->  00:10:27,455
Defining a function Block in St source

126

00:10:27,711  -->  00:10:30,271
Difference between FC and FB

127

00:10:31,807  -->  00:10:33,343
It's almost the same

128

00:10:33,855  -->  00:10:36,415
Well of course there are some different

129

00:10:39,231  -->  00:10:42,559
Declaration part of a function block

130

00:10:43,327  -->  00:10:45,631
Input output.

131

00:10:46,655  -->  00:10:52,799
You see here the static variable is different than the function and temporary variable declaration

132

00:10:53,055  -->  00:10:55,615
Also the constant

133

00:10:57,919  -->  00:11:03,807
So in out parameters cannot be initialized there's a deep note for you

134

00:11:04,575  -->  00:11:06,367
at this case

135

00:11:06,623  -->  00:11:12,767
We initialized axis pos long real data type

136

00:11:13,023  -->  00:11:18,911
An assignment initial visit initialization value is 15

137

00:11:23,519  -->  00:11:29,663
You'll see here in this table parameters in function blocks input output in

138

00:11:29,919  -->  00:11:30,687
in out

139

00:11:37,087  -->  00:11:40,671
statement part Of a function block is here

140

00:11:42,207  -->  00:11:46,815
Restrictions with access to parameter and variables are

141

00:11:47,583  -->  00:11:51,167
Read-only axis to input parameters only

142

00:11:51,423  -->  00:11:57,567
Read and write access to output and input parameters is possible

143

00:11:58,079  -->  00:12:02,943
Read and write access for all local variables is possible

144

00:12:03,711  -->  00:12:05,247
constants

145

00:12:05,759  -->  00:12:07,807
value are constant

146

00:12:08,575  -->  00:12:14,463
variable or read-only access to contants is possible

147

00:12:21,119  -->  00:12:24,703
Instant idea of function blocks

148

00:12:24,959  -->  00:12:28,287
here motor1 instance

149

00:12:28,543  -->  00:12:30,335
Motor 2 Motor 3

150

00:12:31,103  -->  00:12:36,991
Call in our program code to the function block

151

00:12:37,759  -->  00:12:42,623
And the instance are there for motor 1 see here

152

00:12:42,879  -->  00:12:45,695
for 2 for 3 with different colors

153

00:12:47,743  -->  00:12:53,887
You may cross the instance as a data block or a member area it's your RAM disk

154

00:12:54,143  -->  00:12:56,703
Or your memory

155

00:12:57,983  -->  00:12:59,519
to understand

156

00:13:02,591  -->  00:13:08,735
So IEC type call of function without instance in St

157

00:13:10,271  -->  00:13:13,855
Normally w will use this case

158

00:13:14,111  -->  00:13:20,255
But if you don't assign the output of a function look to a

159

00:13:20,511  -->  00:13:21,791
Global available

160

00:13:23,327  -->  00:13:28,191
This way of usage instance name. the parameter

161

00:13:28,447  -->  00:13:30,495
Assignment is also possible

162

00:13:38,687  -->  00:13:43,295
call Options action permit language extension

163

00:13:44,063  -->  00:13:45,343
you see here

164

00:13:45,855  -->  00:13:47,135
Imports

165

00:13:47,903  -->  00:13:49,951
Imports Imports

166

00:13:50,207  -->  00:13:51,999
This is the output

167

00:13:54,815  -->  00:14:00,191
And read and write access to input parameters outside of the parameter list

168

00:14:02,751  -->  00:14:06,079
There's an assignment motor to start with

169

00:14:06,847  -->  00:14:09,663
Equalize the digital inputs

170

00:14:10,943  -->  00:14:14,783
Motor 2 speed equals constant value

171

00:14:15,551  -->  00:14:20,927
then you call Motor 2 only estop parameter

172

00:14:21,951  -->  00:14:23,231
estop

173

00:14:25,791  -->  00:14:28,863
So this is also another way to use

174

00:14:40,383  -->  00:14:44,223
Forward declaration in St

175

00:14:44,479  -->  00:14:50,623
Use of fc fb or program program organization pre-order

176

00:14:50,879  -->  00:14:51,903
implementation

177

00:14:53,183  -->  00:14:58,559
So you'll see you're an interface section and implementation section

178

00:14:59,583  -->  00:15:03,167
If you want to use forward decleration

179

00:15:03,935  -->  00:15:08,543
type section of interphase of implementation Part is possible

180

00:15:13,919  -->  00:15:15,455
So we

181

00:15:15,967  -->  00:15:19,807
Define functional operate mode aS Type

182

00:15:23,647  -->  00:15:25,439
and we create

183

00:15:25,695  -->  00:15:28,767
A global variable operating mode

184

00:15:31,071  -->  00:15:36,959
and here function block operate mode later on described

185

00:15:39,775  -->  00:15:43,359
This is the forward declaration

186

00:15:48,991  -->  00:15:52,575
you need to enable compile option first

187

00:15:53,855  -->  00:15:59,999
Program oorganization units can be used for following purposes

188

00:16:02,047  -->  00:16:06,655
instance decleration of function block call for function

189

00:16:09,471  -->  00:16:10,495
So

190

00:16:11,775  -->  00:16:16,895
Your used within type and type section in the interface to do that

191

00:16:18,175  -->  00:16:23,295
Keep in mind maybe you need it in the future

192

00:16:24,575  -->  00:16:30,719
Command library in simotion Scout you see on the left side that are some

193

00:16:30,975  -->  00:16:33,023
Ready-to-use functions

194

00:16:34,303  -->  00:16:36,351
for different

195

00:16:36,863  -->  00:16:43,007
Section alarm messages Drive function

196

00:16:43,263  -->  00:16:47,103
Communications and so on

197

00:16:49,151  -->  00:16:52,735
That are here several standard functions in simotion

198

00:16:52,991  -->  00:16:54,783
And example

199

00:16:59,903  -->  00:17:06,047
bistable flip flop set reset and triggered counter PLC open commands

200

00:17:09,631  -->  00:17:11,679
and next

201

00:17:12,959  -->  00:17:17,567
How do we access to technology object data types?

202

00:17:19,103  -->  00:17:24,991
In FBs and FCs via input parameters it's possible

203

00:17:26,015  -->  00:17:30,111
So see the keywords

204

00:17:35,999  -->  00:17:39,839
okay If I want to create my own program

205

00:17:40,095  -->  00:17:46,239
FB for position access at the input side I define my access variable

206

00:17:46,495  -->  00:17:48,031
Declaration of input

207

00:17:52,895  -->  00:17:58,783
here Is example usage motion control commands enable access

208

00:17:59,039  -->  00:18:00,319
pos axes

209

00:18:01,343  -->  00:18:04,159
and I can reach

210

00:18:04,415  -->  00:18:08,255
System variable or the variables of the

211

00:18:09,023  -->  00:18:10,559
technology objects

212

00:18:14,911  -->  00:18:16,703
So...

213

00:18:16,959  -->  00:18:22,847
Transformation and checking data type

214

00:18:23,103  -->  00:18:26,943
Typecast explicates or explicit

215

00:18:27,199  -->  00:18:28,479
typecast

216

00:18:30,527  -->  00:18:36,671
With converison or without conversion you see here at this example

217

00:18:36,927  -->  00:18:38,719
drive axes

218

00:18:38,975  -->  00:18:41,023
Assignment to a pos axis

219

00:18:42,559  -->  00:18:47,679
It's just you lost some information

220

00:18:49,983  -->  00:18:51,007
Yep

221

00:18:52,031  -->  00:18:58,175
And you can assign a drive axes to any object type

222

00:18:58,431  -->  00:19:00,735
Variable is possible

223

00:19:02,271  -->  00:19:07,391
teseting TO reference we can use this phrase pos access

224

00:19:08,159  -->  00:19:10,463
Is not equals

225

00:19:10,719  -->  00:19:12,255
Technology objects

226

00:19:13,023  -->  00:19:14,815
null instance

227

00:19:15,327  -->  00:19:17,631
casting succesfull

228

00:19:18,911  -->  00:19:24,543
After that we can use our casting phrase

229

00:19:25,567  -->  00:19:28,383
Example this

230

00:19:31,455  -->  00:19:37,343
For explicit type casting you use anyobject to object

231

00:19:38,879  -->  00:19:42,719
At this case you don't lose information

232

00:19:42,975  -->  00:19:45,023
Because you're converting

233

00:19:45,791  -->  00:19:50,143
Access to pos access object so

234

00:19:53,983  -->  00:19:58,079
I think this second way is more common used

235

00:19:58,847  -->  00:20:00,383
Programming

236

00:20:01,151  -->  00:20:06,015
and before to do that you have to check the TO reference

237

00:20:12,927  -->  00:20:13,951
Okay

238

00:20:14,975  -->  00:20:18,047
That's all so far

239

00:20:20,095  -->  00:20:21,375
you may

240

00:20:21,631  -->  00:20:27,775
Check the exercises in your lecture notes and do related examples

241

00:20:28,799  -->  00:20:30,335
In your PC

242

00:20:31,103  -->  00:20:32,383
On your own

243

00:20:32,639  -->  00:20:33,919
See you then.
