|
|
@@ -1,8 +1,45 @@
|
|
|
|
|
|
|
|
|
+using System.Diagnostics;
|
|
|
+using YSAI.Unility;
|
|
|
|
|
|
+/// <summary>
|
|
|
+/// 开关
|
|
|
+/// </summary>
|
|
|
+Stopwatch stopwatch=null;
|
|
|
+/// <summary>
|
|
|
+/// 开始记录
|
|
|
+/// </summary>
|
|
|
+void StartRecord()
|
|
|
+{
|
|
|
+ if (stopwatch == null)
|
|
|
+ {
|
|
|
+ stopwatch = new Stopwatch();
|
|
|
+ }
|
|
|
+ stopwatch.Start(); // 开始监视代码运行时间
|
|
|
+}
|
|
|
+/// <summary>
|
|
|
+/// 停止记录
|
|
|
+/// </summary>
|
|
|
+/// <returns>时,分,秒,毫秒</returns>
|
|
|
+(int hours, int minutes, int seconds, int milliseconds) StopRecord()
|
|
|
+{
|
|
|
+ stopwatch.Stop(); // 停止监视
|
|
|
+ TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
|
|
|
+ int hours = timespan.Hours; // 总小时
|
|
|
+ int minutes = timespan.Minutes; // 总分钟
|
|
|
+ int seconds = timespan.Seconds; // 总秒数
|
|
|
+ int milliseconds = timespan.Milliseconds; // 总毫秒数
|
|
|
+ stopwatch.Restart();//复位
|
|
|
+ return (hours, minutes, seconds, milliseconds);
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
+while (true)
|
|
|
+{
|
|
|
+ StartRecord();
|
|
|
+ Console.ReadLine();
|
|
|
+ Console.WriteLine(StopRecord().ToJson());
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -440,84 +477,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>();
|
|
|
+///// <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;
|
|
|
-}
|
|
|
+// 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"));
|
|
|
+////Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\[6032]Node_Address 202310120854271486.json"));
|
|
|
|
|
|
-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()
|
|
|
- });
|
|
|
-}
|
|
|
+//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;
|
|
|
+// 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());
|
|
|
-}
|
|
|
+//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;
|
|
|
- }
|
|
|
-}
|
|
|
+//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;
|
|
|
+// }
|
|
|
+//}
|
|
|
|
|
|
|
|
|
|