-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathExampleRW.cs
More file actions
72 lines (56 loc) · 2.19 KB
/
ExampleRW.cs
File metadata and controls
72 lines (56 loc) · 2.19 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
// 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 ExampleRW
{
public static void Run()
{
Console.WriteLine($"\r\n*** ExampleRW ***");
const int TIMEOUT = 5000;
//DINT Test Read/Write
var myTag = new Tag<DintPlcMapper, int>()
{
//Name of tag on the PLC, Controller-scoped would be just "SomeDINT"
Name = "PROGRAM:SomeProgram.SomeDINT",
//PLC IP Address
Gateway = "10.10.10.10",
//CIP path to PLC CPU. "1,0" will be used for most AB PLCs
Path = "1,0",
//Type of PLC
PlcType = PlcType.ControlLogix,
//Protocol
Protocol = Protocol.ab_eip,
//A global timeout value that is used for Initialize/Read/Write methods
Timeout = TimeSpan.FromMilliseconds(TIMEOUT),
};
myTag.Initialize();
//Read tag value - This pulls the value from the PLC into the local Tag value
Console.WriteLine($"Starting tag read");
myTag.Read();
//Read back value from local memory
int myDint = myTag.Value;
Console.WriteLine($"Initial Value: {myDint}");
//Set Tag Value
myDint++;
myTag.Value = myDint;
Console.WriteLine($"Starting tag write ({myDint})");
myTag.Write();
//Read tag value - This pulls the value from the PLC into the local Tag value
Console.WriteLine($"Starting synchronous tag read");
myTag.Read();
//Read back value from local memory
var myDintReadBack = myTag.Value;
Console.WriteLine($"Final Value: {myDintReadBack}");
}
}
}