|
|
@@ -440,51 +440,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
-//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;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// 读取Csv,返回行集合
|
|
|
+/// </summary>
|
|
|
+/// <param name="path"></param>
|
|
|
+/// <param name="hasTitle"></param>
|
|
|
+/// <returns></returns>
|
|
|
+ List<string> ReadCsv(string path, bool hasTitle)
|
|
|
+{
|
|
|
+ if (!File.Exists(path))
|
|
|
+ return new List<string>();
|
|
|
+
|
|
|
+ var lines = File.ReadAllLines(path).ToList();
|
|
|
+ if (hasTitle)
|
|
|
+ {
|
|
|
+ lines.RemoveAt(0);
|
|
|
+ }
|
|
|
+ return lines;
|
|
|
+}
|
|
|
|
|
|
//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());
|
|
|
-//}
|
|
|
-
|
|
|
-//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;
|
|
|
-// }
|
|
|
-//}
|
|
|
+Address address = new Address();
|
|
|
+address.SN = Guid.NewGuid().ToString();
|
|
|
+address.CreationTime = DateTime.Now;
|
|
|
+address.AddressArray = new List<AddressDetails>();
|
|
|
+List<string> strings = ReadCsv("C:\\Users\\Shun\\Desktop\\6022.csv", true);
|
|
|
+foreach (var item in strings)
|
|
|
+{
|
|
|
+ string[] str = item.Split(",");
|
|
|
+ string addressD = str[0].Replace("\"", "");
|
|
|
+ address.AddressArray.Add(new AddressDetails()
|
|
|
+ {
|
|
|
+ AddressName = $"ns=2;s=6022.6022.{addressD}",
|
|
|
+ SN = Guid.NewGuid().ToString()
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+ OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
|
|
|
+{
|
|
|
+ ServerUrl = "opc.tcp://192.168.2.220:49320",
|
|
|
+ CustomName = "YSAI 性能测试",
|
|
|
+ TaskNumber=10,
|
|
|
+ TaskHandleInterval=1
|
|
|
+});
|
|
|
+Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
|
|
|
+opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
|
|
|
+
|
|
|
+while (true)
|
|
|
+{
|
|
|
+ Console.ReadLine();
|
|
|
+ OperateResult operateResult = opcUaClientOperate.Subscribe(address);
|
|
|
+ Console.WriteLine(operateResult.ToJson().JsonFormatting());
|
|
|
+}
|
|
|
+
|
|
|
+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;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
|