Ver código fonte

版本更新,细节优化

Shun 2 anos atrás
pai
commit
650c88a6eb

+ 2 - 2
src/YSAI.DAQ/YSAI.Core/YSAI.Core.csproj

@@ -5,7 +5,7 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-    <Version>1.0.0.82</Version>
+    <Version>1.0.0.83</Version>
     <Authors>Shun</Authors>
     <Company>YSAI</Company>
     <Product>SCADA</Product>
@@ -17,7 +17,7 @@
 		<PackageReference Include="Microsoft.ClearScript" Version="7.4.4" />
 		<PackageReference Include="System.IO.Ports" Version="7.0.0" />
 		<PackageReference Include="YSAI.Log" Version="1.0.0.11" />
-		<PackageReference Include="YSAI.Unility" Version="1.0.0.27" />
+		<PackageReference Include="YSAI.Unility" Version="1.0.0.28" />
 	</ItemGroup>
 
 </Project>

+ 2 - 2
src/YSAI.DAQ/YSAI.NetMQ/NetMQData.cs

@@ -33,7 +33,7 @@ namespace YSAI.NetMQ
             /// </summary>
             [Description("队列大小")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.unmber)]
-            public int ReceiveHighWatermark { get; set; } = 1;
+            public int ReceiveHighWatermark { get; set; } = 1000;
 
             /// <summary>
             /// 超时时间
@@ -41,7 +41,7 @@ namespace YSAI.NetMQ
             [Description("超时时间")]
             [Unit("ms")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.unmber)]
-            public int TimeOut { get; set; } = 1;
+            public int TimeOut { get; set; } = 1000;
         }
 
     }

+ 1 - 1
src/YSAI.DAQ/YSAI.NetMQ/NetMQOperate.cs

@@ -247,7 +247,7 @@ namespace YSAI.NetMQ
                 while (!source.IsCancellationRequested)
                 {
                     string Content = string.Empty;
-                    if (sSocket.TryReceiveFrameString(TimeSpan.FromSeconds(timeout), out string Topic, out bool moreFrames))
+                    if (sSocket.TryReceiveFrameString(TimeSpan.FromMilliseconds(timeout), out string Topic, out bool moreFrames))
                     {
                         if (moreFrames)
                         {

+ 39 - 28
src/YSAI.DAQ/YSAI.Test.All/Program.cs

@@ -1,4 +1,15 @@
 
+//Console.WriteLine(DateTime.Parse($"{0}:{0}:{0}.{123}").ToString("HH:mm:ss:fff"));
+
+using YSAI.Unility;
+
+while (true)
+{
+    TimeTool.Instance("1").StartRecord();
+    Thread.Sleep(100);
+    Console.WriteLine(TimeTool.Instance("1").StopRecord().milliseconds);
+}
+
 
 //using NetMQ;
 //using NetMQ.Sockets;
@@ -30,44 +41,44 @@
 
 
 
-using YSAI.NetMQ;
-using YSAI.Unility;
-string topic = "666";
-string topic1 = "777";
-int count = 1;
+//using YSAI.NetMQ;
+//using YSAI.Unility;
+//string topic = "666";
+//string topic1 = "777";
+//int count = 1;
 
-NetMQOperate netMQClientOperate = NetMQOperate.Instance(new NetMQData.Basics());
-Console.WriteLine(netMQClientOperate.On().ToJson().JsonFormatting());
+//NetMQOperate netMQClientOperate = NetMQOperate.Instance(new NetMQData.Basics());
+//Console.WriteLine(netMQClientOperate.On().ToJson().JsonFormatting());
 
-netMQClientOperate.OnEvent += NetMQClientOperate_OnEvent;
+//netMQClientOperate.OnEvent += NetMQClientOperate_OnEvent;
 
-Console.WriteLine(netMQClientOperate.Subscribe(topic).ToJson().JsonFormatting());
-Console.WriteLine(netMQClientOperate.Subscribe(topic1).ToJson().JsonFormatting());
+//Console.WriteLine(netMQClientOperate.Subscribe(topic).ToJson().JsonFormatting());
+//Console.WriteLine(netMQClientOperate.Subscribe(topic1).ToJson().JsonFormatting());
 
-while (true)
-{
-    Console.ReadLine();
+//while (true)
+//{
+//    Console.ReadLine();
 
-    netMQClientOperate.Produce(topic, new Random().NextDouble().ToString());
-    netMQClientOperate.Produce(topic1, new Random().NextDouble().ToString());
-    count++;
+//    netMQClientOperate.Produce(topic, new Random().NextDouble().ToString());
+//    netMQClientOperate.Produce(topic1, new Random().NextDouble().ToString());
+//    count++;
 
 
-    if (count == 10)
-    {
-        Console.WriteLine(netMQClientOperate.UnSubscribe(topic).State);
-        Console.WriteLine(netMQClientOperate.UnSubscribe(topic1).State);
-        break;
-    }
-}
+//    if (count == 10)
+//    {
+//        Console.WriteLine(netMQClientOperate.UnSubscribe(topic).State);
+//        Console.WriteLine(netMQClientOperate.UnSubscribe(topic1).State);
+//        break;
+//    }
+//}
 
-Console.ReadKey();
+//Console.ReadKey();
 
 
-void NetMQClientOperate_OnEvent(object? sender, YSAI.Core.data.EventResult e)
-{
-    Console.WriteLine(e.ToJson());
-}
+//void NetMQClientOperate_OnEvent(object? sender, YSAI.Core.data.EventResult e)
+//{
+//    Console.WriteLine(e.ToJson());
+//}
 
 
 

+ 1 - 5
src/YSAI.DAQ/YSAI.Test.All/YSAI.Test.All.csproj

@@ -13,11 +13,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\YSAI.Beckhoff\YSAI.Beckhoff.csproj" />
-    <ProjectReference Include="..\YSAI.Mitsubishi\YSAI.Mitsubishi.csproj" />
-    <ProjectReference Include="..\YSAI.NetMQ\YSAI.NetMQ.csproj" />
-    <ProjectReference Include="..\YSAI.Netty\YSAI.Netty.csproj" />
-    <ProjectReference Include="..\YSAI.Omron\YSAI.Omron.csproj" />
+    <ProjectReference Include="..\YSAI.Unility\YSAI.Unility.csproj" />
   </ItemGroup>
 
 

+ 42 - 14
src/YSAI.DAQ/YSAI.Unility/TimeTool.cs

@@ -52,33 +52,27 @@ namespace YSAI.Unility
         /// <summary>
         /// 开关
         /// </summary>
-        private Stopwatch stopwatch;
+        private ValueStopwatch stopwatch;
 
         /// <summary>
         /// 开始记录
         /// </summary>
         public void StartRecord()
         {
-            if (stopwatch == null)
-            {
-                stopwatch = new Stopwatch();
-            }
-            stopwatch.Start(); //  开始监视代码运行时间
+            stopwatch = ValueStopwatch.StartNew(); //  开始监视代码运行时间
         }
 
         /// <summary>
         /// 停止记录
         /// </summary>
-        /// <returns>时,分,秒,毫秒</returns>
+        /// <returns>时,分,秒,毫秒,时分秒毫秒</returns>
         public (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();//复位
+            TimeSpan timespan = stopwatch.GetElapsedTime(); //  获取当前实例测量得出的总时间
+            int hours = Math.Round(timespan.TotalHours).ToInt(); // 总小时
+            int minutes = Math.Round(timespan.TotalMinutes).ToInt();  // 总分钟
+            int seconds = Math.Round(timespan.TotalSeconds).ToInt();  //  总秒数
+            int milliseconds = Math.Ceiling(timespan.TotalMilliseconds).ToInt();  //  总毫秒数
             return (hours, minutes, seconds, milliseconds);
         }
 
@@ -94,5 +88,39 @@ namespace YSAI.Unility
             while (stopTime.Elapsed.TotalMilliseconds < time) { }
             stopTime.Stop();
         }
+
+        /// <summary>
+        /// 直接操作底层,性能消耗更小
+        /// </summary>
+        internal struct ValueStopwatch
+        {
+            private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
+
+            private readonly long _startTimestamp;
+
+            public bool IsActive => _startTimestamp != 0;
+
+            private ValueStopwatch(long startTimestamp)
+            {
+                _startTimestamp = startTimestamp;
+            }
+
+            public static ValueStopwatch StartNew() => new ValueStopwatch(Stopwatch.GetTimestamp());
+
+            public TimeSpan GetElapsedTime()
+            {
+                // Start timestamp can't be zero in an initialized ValueStopwatch. It would have to be literally the first thing executed when the machine boots to be 0.
+                // So it being 0 is a clear indication of default(ValueStopwatch)
+                if (!IsActive)
+                {
+                    throw new InvalidOperationException("An uninitialized, or 'default', ValueStopwatch cannot be used to get elapsed time.");
+                }
+
+                var end = Stopwatch.GetTimestamp();
+                var timestampDelta = end - _startTimestamp;
+                var ticks = (long)(TimestampToTicks * timestampDelta);
+                return new TimeSpan(ticks);
+            }
+        }
     }
 }

+ 1 - 1
src/YSAI.DAQ/YSAI.Unility/YSAI.Unility.csproj

@@ -5,7 +5,7 @@
 		<ImplicitUsings>enable</ImplicitUsings>
 		<Nullable>enable</Nullable>
 		<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-		<Version>1.0.0.27</Version>
+		<Version>1.0.0.29</Version>
 		<Authors>Shun</Authors>
 		<Company>YSAI</Company>
 		<Product>SCADA</Product>