Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFBWithUserStruct.cs
More file actions
Latest commit
101 lines (89 loc) · 2.57 KB
/
Copy pathFBWithUserStruct.cs
File metadata and controls
101 lines (89 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#region Copyright
//
// Copyright (c) Phoenix Contact GmbH & Co. KG. All rights reserved.
// Licensed under the MIT. See LICENSE file in the project root for full license information.
//
#endregion Copyright
usingIec61131.Engineering.Prototypes.Methods;
usingIec61131.Engineering.Prototypes.Types;
usingIec61131.Engineering.Prototypes.Variables;
usingIec61131.Engineering.Prototypes.Common;
namespaceExampleLib
{
// The attribute "Structure" is necessary to make the struct visible in the PLCnext Engineer
[Structure]
publicstructPosition
{
// the fields must be public as well as the struct itself
[DataType("DINT")]
publicintx;
[DataType("DINT")]
publicinty;
}
// Pass 'Input' and 'Output' parameter by value.
[FunctionBlock]
publicclassFB_with_user_struct1
{
[Input]
publicPositionNEW_POSITION;
[Output]
publicPositionCURRENT_POSITION;
[Initialization]
publicvoid__Init()
{
}
[Execution]
publicvoid__Process()
{
if(CURRENT_POSITION.x<NEW_POSITION.x)
{
CURRENT_POSITION.x++;
}
elseif(CURRENT_POSITION.x>NEW_POSITION.x)
{
CURRENT_POSITION.x--;
}
if(CURRENT_POSITION.y<NEW_POSITION.y)
{
CURRENT_POSITION.y++;
}
elseif(CURRENT_POSITION.y>NEW_POSITION.y)
{
CURRENT_POSITION.y--;
}
}
}
// Pass parameters by reference as an 'InOut' parameter. This saves memory and CPU time for copying values for large arrays and structures.
[FunctionBlock]
publicclassFB_with_user_struct2
{
[InOut]
unsafepublicPosition*NEW_POSITION;
[InOut]
unsafepublicPosition*CURRENT_POSITION;
[Initialization]
publicvoid__Init()
{
}
[Execution]
unsafepublicvoid__Process()
{
if((*CURRENT_POSITION).x<(*NEW_POSITION).x)
{
(*CURRENT_POSITION).x++;
}
elseif((*CURRENT_POSITION).x>(*NEW_POSITION).x)
{
(*CURRENT_POSITION).x--;
}
if((*CURRENT_POSITION).y<(*NEW_POSITION).y)
{
(*CURRENT_POSITION).y++;
}
elseif((*CURRENT_POSITION).y>(*NEW_POSITION).y)
{
(*CURRENT_POSITION).y--;
}
}
}
}