forked from PLCnext/CSharpExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FBWithDateTime.cs
123 lines (96 loc) · 3.01 KB
/
FBWithDateTime.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#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
using Iec61131.Engineering.Prototypes.Common;
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using System;
using System.Iec61131Lib;
namespace ExampleLib
{
[FunctionBlock]
public class FB_with_DateTime
{
[Input]
public bool EN;
[Output, DataType("LINT")]
public long UTC_TICKS;
[Output]
public IecString80 LOCAL_TIME;
[Initialization]
public void __Init()
{
LOCAL_TIME.ctor();
}
[Execution]
public void __Process()
{
if (EN)
{
// Time stamp
UTC_TICKS = DateTime.UtcNow.Ticks;
// ... formatted to string
DateTime dateTimeNow = DateTime.Now;
LOCAL_TIME.s.Init(dateTimeNow.ToString(), false);
}
}
}
[FunctionBlock]
public class FB_DateTime_conversion
{
//int#0 equals TIME#00:00:00
[Input, DataType("TIME")]
public int Time;
[Input, DataType("LTIME")]
public long LTime;
//long#0 equals LDATE#1970-01-01
[Input, DataType("LDATE")]
public long LDate;
// the short form LTOD and LDT does not work
[Input, DataType("LTIME_OF_DAY")]
public long Time_of_Day;
[Input, DataType("LDATE_AND_TIME")]
public long Date_and_Time;
[Output, DataType("DINT")]
public int int_TIME;
[Output, DataType("LINT")]
public long lLTIME;
[Output, DataType("LINT")]
public long lLDATE;
[Output, DataType("LINT")]
public long lLTOD;
[Output, DataType("LINT")]
public long lLDT;
[Output, DataType("TIME")]
public int out_TIME;
[Output, DataType("LTIME")]
public long out_LTIME;
[Output, DataType("LDATE")]
public long out_LDATE;
[Output, DataType("LTIME_OF_DAY")]
public long out_LTOD;
[Output, DataType("LDATE_AND_TIME")]
public long out_LDT;
[Output, DataType("LDATE_AND_TIME")]
public long LDT_now;
[Initialization]
public void __Init()
{
}
[Execution]
public void __Process()
{
int_TIME = out_TIME = Time;
lLTIME = out_LTIME = LTime;
lLDATE = out_LDATE = LDate;
lLTOD = out_LTOD = Time_of_Day;
lLDT = out_LDT = Date_and_Time;
TimeSpan test = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
LDT_now = (long)(test.TotalMilliseconds * 1000000.0);
}
}
}