/
Basics.cs
67 lines (58 loc) · 1.56 KB
/
Basics.cs
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
#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
//uncomment the next row to change the signature of the function block (adding a second input)
//#define AddParameter
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using Iec61131.Engineering.Prototypes.Common;
namespace ExampleLib
{
//the attribute [FunctionBlock] above a class indicates the class to be a function block
[FunctionBlock]
//the name of the class equals the name of the function block
public class Counter
{
[Input]
public bool xActivate;
#if AddParameter
//adding an additional input
[Input]
public bool xDOWN;
#endif
[Output, DataType("DINT")]
public int iOUT;
[Initialization]
public void __Init()
{
}
[Execution]
public void __Process()
{
#if !AddParameter
//counter counts up
if (!xActivate)
{
iOUT++;
}
#else
//counter counts up if input "xDOWN" is false and counts down if "xDOWN" is set to true
if (xActivate)
{
if(xDOWN)
{
iOUT--;
}
else
{
iOUT++;
}
}
#endif
}
}
}