-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFunWithANY_BIT.cs
More file actions
84 lines (76 loc) · 2.83 KB
/
FunWithANY_BIT.cs
File metadata and controls
84 lines (76 loc) · 2.83 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
#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.Iec61131Lib;
namespace ExampleLib
{
/// <summary>
/// The example limits a value into a defined range
/// </summary>
[Function, DataType("LWORD")]
public static class Fun_with_ANY_BIT
{
// All Any parameters must be passed by ref!
[Execution]
public unsafe static ulong __Process(
[Input, DataType("ANY_BIT")] ref Any VALUE)
{
ulong retValue = 0;
// get the size of the connected value type
uint SIZE_OF_VALUE = VALUE.nLength;
// Get the element type constants associate to the runtime type handle.
// The values are defined in the standard ECMA-335 "Common Language Infrastructure (CLI)",
// Partition II, chapter II.23.1.16 "Element types used in signatures")
Eclr.TypeCode code = (Eclr.TypeCode)Eclr.TypeInfo.GetTypeCode(VALUE.pRuntimeTypeHandle);
// type dependent action
switch (code)
{
case Eclr.TypeCode.Boolean:
{
bool tempValue = *(bool*)VALUE.pValue;
if (tempValue)
{
retValue = 1;
}
else
{
retValue = 0;
}
break;
}
case Eclr.TypeCode.Byte:
{
byte tempValue = *(byte*)VALUE.pValue;
retValue = tempValue;
break;
}
case Eclr.TypeCode.UInt16:
{
ushort tempValue = *(ushort*)VALUE.pValue;
retValue = tempValue;
break;
}
case Eclr.TypeCode.UInt32:
{
uint tempValue = *(uint*)VALUE.pValue;
retValue = tempValue;
break;
}
case Eclr.TypeCode.UInt64:
{
ulong tempValue = *(ulong*)VALUE.pValue;
retValue = tempValue;
break;
}
}
return retValue;
}
}
}