-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathExampleArray.cs
More file actions
104 lines (86 loc) · 3.18 KB
/
ExampleArray.cs
File metadata and controls
104 lines (86 loc) · 3.18 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
102
103
104
// Copyright (c) libplctag.NET contributors
// https://github.com/libplctag/libplctag.NET
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using libplctag;
using libplctag.DataTypes;
using System;
using System.Net;
using System.Threading;
namespace CSharpDotNetFramework
{
class ExampleArray
{
public static void Run()
{
Console.WriteLine($"\r\n*** ExampleArray ***");
//DINT Test Read/Write
const int ARRAY_LENGTH = 5;
const int TIMEOUT = 1000;
const string gateway = "10.10.10.10";
const string path = "1,0";
//Generics version
var dintTag = new Tag<DintPlcMapper, int[,]>()
{
Name = "TestDINTArray2",
Gateway = gateway,
Path = path,
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
ArrayDimensions = new int[] { ARRAY_LENGTH, ARRAY_LENGTH },
Timeout = TimeSpan.FromMilliseconds(TIMEOUT),
};
dintTag.Initialize();
//dintTag.Value = new int[] { 1, 2, 3, 4, 5 };
//dintTag.Write();
dintTag.Read();
dintTag.Write();
//Read back value from local memory
for (int i = 0; i < ARRAY_LENGTH; i++)
{
for (int j = 0; j < ARRAY_LENGTH; j++)
{
Console.WriteLine($"Value[{i}, {j}]: {dintTag.Value[i, j]}");
}
}
//Generics version
var dintTag3 = new Tag<DintPlcMapper, int[,,]>()
{
Name = "TestDINTArray3",
Gateway = gateway,
Path = path,
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
ArrayDimensions = new int[] { ARRAY_LENGTH, ARRAY_LENGTH, ARRAY_LENGTH },
Timeout = TimeSpan.FromMilliseconds(TIMEOUT),
};
dintTag3.Initialize();
//dintTag.Value = new int[] { 1, 2, 3, 4, 5 };
//dintTag.Write();
dintTag3.Read();
dintTag3.Write();
//var myArrayTag = new Tag()
//{
// Name = "TestArray",
// Gateway = "10.10.10.10",
// Path = "1,0",
// PlcType = PlcType.ControlLogix,
// ElementSize = 4,
// ElementCount = ARRAY_LENGTH,
// Timeout = TimeSpan.FromMilliseconds(TIMEOUT),
//};
//myArrayTag.Initialize();
////Read tag value - This pulls the value from the PLC into the local Tag value
//Console.WriteLine($"Starting tag read");
//myArrayTag.Read();
////Read back value from local memory
//for (int i = 0; i < ARRAY_LENGTH; i++)
//{
// int arrayDint = myArrayTag.GetInt32(i * 4);
// Console.WriteLine($"Value[{i}]: {arrayDint}");
//}
}
}
}