|
|
@@ -23,76 +23,76 @@
|
|
|
// Console.WriteLine(e.ToJson().JsonFormatting());
|
|
|
//}
|
|
|
|
|
|
-using S7.Net;
|
|
|
-using System.Collections.Concurrent;
|
|
|
-using YSAI.Core.data;
|
|
|
-using YSAI.Core.@enum;
|
|
|
-using YSAI.Core.subscribe.core;
|
|
|
-using YSAI.Log;
|
|
|
-using YSAI.S7.client;
|
|
|
-using YSAI.Unility;
|
|
|
+//using S7.Net;
|
|
|
+//using System.Collections.Concurrent;
|
|
|
+//using YSAI.Core.data;
|
|
|
+//using YSAI.Core.@enum;
|
|
|
+//using YSAI.Core.subscribe.core;
|
|
|
+//using YSAI.Log;
|
|
|
+//using YSAI.S7.client;
|
|
|
+//using YSAI.Unility;
|
|
|
|
|
|
|
|
|
-S7ClientOperate s7ClientOperate = S7ClientOperate.Instance(new S7ClientData.Basics()
|
|
|
-{
|
|
|
- Ip = "192.168.2.20",
|
|
|
- Port = 102,
|
|
|
- Rack = 0,
|
|
|
- Slot = 1,
|
|
|
- S7CpuType = CpuType.S71200,
|
|
|
- ChangeOut = false,
|
|
|
- HandleInterval = 0,
|
|
|
- SN = Guid.NewGuid().ToString()
|
|
|
-});
|
|
|
-//打开
|
|
|
-OperateResult operateResult = s7ClientOperate.On();
|
|
|
-Console.WriteLine(operateResult.Message);
|
|
|
-
|
|
|
-//点位地址
|
|
|
-Address address = new Address();
|
|
|
-address.SN = Guid.NewGuid().ToString();
|
|
|
-address.CreationTime = DateTime.Now.ToLocalTime();
|
|
|
-address.AddressArray = new List<AddressDetails>();
|
|
|
-address.AddressArray.Add(new AddressDetails()
|
|
|
-{
|
|
|
- AddressName = "DB71.DBD4",
|
|
|
- AddressDataType = YSAI.Core.@enum.DataType.Float,
|
|
|
- AddressType = AddressType.Reality
|
|
|
-});
|
|
|
+//S7ClientOperate s7ClientOperate = S7ClientOperate.Instance(new S7ClientData.Basics()
|
|
|
+//{
|
|
|
+// Ip = "192.168.2.20",
|
|
|
+// Port = 102,
|
|
|
+// Rack = 0,
|
|
|
+// Slot = 1,
|
|
|
+// S7CpuType = CpuType.S71200,
|
|
|
+// ChangeOut = false,
|
|
|
+// HandleInterval = 0,
|
|
|
+// SN = Guid.NewGuid().ToString()
|
|
|
+//});
|
|
|
+////打开
|
|
|
+//OperateResult operateResult = s7ClientOperate.On();
|
|
|
+//Console.WriteLine(operateResult.Message);
|
|
|
|
|
|
-//读取
|
|
|
-operateResult = s7ClientOperate.Read(address);
|
|
|
-Console.WriteLine(operateResult.Message);
|
|
|
-if (operateResult.State)
|
|
|
-{
|
|
|
- foreach (var item in operateResult.RData as ConcurrentDictionary<string, AddressValue>)
|
|
|
- {
|
|
|
- Console.WriteLine(item.Key);
|
|
|
- Console.WriteLine(item.Value.Value);
|
|
|
- }
|
|
|
-}
|
|
|
+////点位地址
|
|
|
+//Address address = new Address();
|
|
|
+//address.SN = Guid.NewGuid().ToString();
|
|
|
+//address.CreationTime = DateTime.Now.ToLocalTime();
|
|
|
+//address.AddressArray = new List<AddressDetails>();
|
|
|
+//address.AddressArray.Add(new AddressDetails()
|
|
|
+//{
|
|
|
+// AddressName = "DB71.DBD4",
|
|
|
+// AddressDataType = YSAI.Core.@enum.DataType.Float,
|
|
|
+// AddressType = AddressType.Reality
|
|
|
+//});
|
|
|
|
|
|
-//订阅
|
|
|
-s7ClientOperate.OnEvent += S7ClientOperate_OnEvent;
|
|
|
-s7ClientOperate.Subscribe(address);
|
|
|
+////读取
|
|
|
+//operateResult = s7ClientOperate.Read(address);
|
|
|
+//Console.WriteLine(operateResult.Message);
|
|
|
+//if (operateResult.State)
|
|
|
+//{
|
|
|
+// foreach (var item in operateResult.RData as ConcurrentDictionary<string, AddressValue>)
|
|
|
+// {
|
|
|
+// Console.WriteLine(item.Key);
|
|
|
+// Console.WriteLine(item.Value.Value);
|
|
|
+// }
|
|
|
+//}
|
|
|
|
|
|
-while (true)
|
|
|
-{
|
|
|
- float value = float.Parse(Console.ReadLine());
|
|
|
- //写入
|
|
|
- ConcurrentDictionary<string, float> keyValuePairs = new ConcurrentDictionary<string, float>();
|
|
|
- keyValuePairs.TryAdd("DB71.DBD4", value);
|
|
|
- operateResult = s7ClientOperate.Write(keyValuePairs);
|
|
|
- Console.WriteLine(operateResult.Message);
|
|
|
-
|
|
|
- SubscribeService<AddressValue> subscribeService = SubscribeService<AddressValue>.Instance();
|
|
|
- Console.WriteLine();
|
|
|
-}
|
|
|
+////订阅
|
|
|
+//s7ClientOperate.OnEvent += S7ClientOperate_OnEvent;
|
|
|
+//s7ClientOperate.Subscribe(address);
|
|
|
|
|
|
-void S7ClientOperate_OnEvent(object? sender, EventResult e)
|
|
|
-{
|
|
|
- Console.WriteLine(e.ToJson().JsonFormatting());
|
|
|
-}
|
|
|
+//while (true)
|
|
|
+//{
|
|
|
+// float value = float.Parse(Console.ReadLine());
|
|
|
+// //写入
|
|
|
+// ConcurrentDictionary<string, float> keyValuePairs = new ConcurrentDictionary<string, float>();
|
|
|
+// keyValuePairs.TryAdd("DB71.DBD4", value);
|
|
|
+// operateResult = s7ClientOperate.Write(keyValuePairs);
|
|
|
+// Console.WriteLine(operateResult.Message);
|
|
|
+
|
|
|
+// SubscribeService<AddressValue> subscribeService = SubscribeService<AddressValue>.Instance();
|
|
|
+// Console.WriteLine();
|
|
|
+//}
|
|
|
+
|
|
|
+//void S7ClientOperate_OnEvent(object? sender, EventResult e)
|
|
|
+//{
|
|
|
+// Console.WriteLine(e.ToJson().JsonFormatting());
|
|
|
+//}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -364,51 +364,51 @@ void S7ClientOperate_OnEvent(object? sender, EventResult e)
|
|
|
|
|
|
|
|
|
|
|
|
-//using System.Collections.Concurrent;
|
|
|
-//using YSAI.Core.data;
|
|
|
-//using YSAI.Log;
|
|
|
-//using YSAI.Opc.ua.client;
|
|
|
-//using YSAI.Unility;
|
|
|
-
|
|
|
+using System.Collections.Concurrent;
|
|
|
+using YSAI.Core.data;
|
|
|
+using YSAI.Log;
|
|
|
+using YSAI.Opc.ua.client;
|
|
|
+using YSAI.Unility;
|
|
|
|
|
|
-//Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\[6032]Node_Address 202310120854271486.json"));
|
|
|
|
|
|
+Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\[6032]Node_Address 202310120854271486.json"));
|
|
|
|
|
|
-//OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
|
|
|
-//{
|
|
|
-// ServerUrl = "opc.tcp://127.0.0.1:8866/Opc.Ua.Service",
|
|
|
-// Password = "ysai",
|
|
|
-// UserName = "ysai",
|
|
|
-// CustomName = "YSAI 性能测试",
|
|
|
-//});
|
|
|
-//Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
|
|
|
-//opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
|
|
|
|
|
|
-//while (true)
|
|
|
-//{
|
|
|
-// Console.ReadLine();
|
|
|
-// OperateResult operateResult = opcUaClientOperate.Subscribe(address);
|
|
|
-// Console.WriteLine(operateResult.ToJson().JsonFormatting());
|
|
|
-//}
|
|
|
+OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
|
|
|
+{
|
|
|
+ ServerUrl = "opc.tcp://127.0.0.1:8866/Opc.Ua.Service",
|
|
|
+ Password = "ysai",
|
|
|
+ UserName = "ysai",
|
|
|
+ CustomName = "YSAI 性能测试",
|
|
|
+});
|
|
|
+Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
|
|
|
+opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
|
|
|
|
|
|
-//void OpcUaClientOperate_OnEvent(object? sender, EventResult e)
|
|
|
-//{
|
|
|
-// switch (e.RType)
|
|
|
-// {
|
|
|
-// case YSAI.Core.@enum.ResultType.KeyValue:
|
|
|
-// ConcurrentDictionary<string, AddressValue> pairs = e.RData as ConcurrentDictionary<string, AddressValue>;
|
|
|
-// foreach (var item in pairs)
|
|
|
-// {
|
|
|
-// String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
|
|
|
+while (true)
|
|
|
+{
|
|
|
+ Console.ReadLine();
|
|
|
+ OperateResult operateResult = opcUaClientOperate.Subscribe(address);
|
|
|
+ Console.WriteLine(operateResult.ToJson().JsonFormatting());
|
|
|
+}
|
|
|
|
|
|
-// LogHelper.Verbose(str);
|
|
|
-// }
|
|
|
-// break;
|
|
|
-// default:
|
|
|
-// Console.WriteLine(e.Message);
|
|
|
-// break;
|
|
|
-// }
|
|
|
-//}
|
|
|
+void OpcUaClientOperate_OnEvent(object? sender, EventResult e)
|
|
|
+{
|
|
|
+ switch (e.RType)
|
|
|
+ {
|
|
|
+ case YSAI.Core.@enum.ResultType.KeyValue:
|
|
|
+ ConcurrentDictionary<string, AddressValue> pairs = e.RData as ConcurrentDictionary<string, AddressValue>;
|
|
|
+ foreach (var item in pairs)
|
|
|
+ {
|
|
|
+ String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
|
|
|
+
|
|
|
+ LogHelper.Verbose(str);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ Console.WriteLine(e.Message);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
|