Zixuan 3 weeks ago
parent
commit
c47a7f8f1a

+ 5 - 44
.gitignore

@@ -1,44 +1,5 @@
-/.vs
-/Binary
-/packages
-/Communicators/Mini8Communicator/IMini8Communicator/obj/Debug/net8.0
-/Communicators/Mini8Communicator/IMini8Communicator/obj
-/Communicators/Mini8Communicator
-/Configs/CofigOperator/obj
-/Configs/ConfigFile/obj
-/ConsoleData/RealtimeData/obj
-/DataBase
-/HistoryUI/obj
-/Log
-/MinicsConsole/obj
-/MinicsUI/obj
-/ModelData
-/Test/obj
-/Tools
-/Universal/obj
-/Communicators/RTCommunicator
-/Configs/CofigOperator/bin/Debug/net8.0
-/Test/bin/Debug/net8.0
-/TLVProtocal
-/Universal/bin/Debug/net8.0
-/UniversalNetFrame451
-/CommunicationProtocols/FinsTcp/bin/Debug/net8.0
-/CommunicationProtocols/FinsTcp/obj
-/CommunicationProtocols/ModBusTcp/obj
-/CommunicationProtocols/ProtocalGeneral/bin/Debug/net8.0
-/CommunicationProtocols/ProtocalGeneral/obj
-/ConsoleData/RealtimeData/bin/Debug/net8.0
-/CommunicationProtocols/ModBusTcp/bin/Debug/net8.0
-/CommunicationProtocols/ModBusTcp/bin
-/CommunicationProtocols/FinsTcp/bin/Release/net8.0
-/CommunicationProtocols/ProtocalGeneral/bin/Release/net8.0
-/Configs/CofigOperator/bin/Release/net8.0
-/ConsoleData/RealtimeData/bin/Release/net8.0
-/Test/bin/Release/net8.0
-/Universal/bin/Release/net8.0
-/CommunicationProtocols/TwinCatADS/obj
-/CommunicationProtocols/TwinCatADS/bin/Debug/net8.0
-/CommunicationProtocols/TwinCatADS/bin/Release/net8.0
-/Test2/bin/Debug/net8.0
-/Test2/obj
-/Test2/bin/Release/net8.0
+.vs/
+Binary/
+packages/
+obj/
+bin/

+ 19 - 0
Communicators/RTCommunicator/RTCommunicatorBase/Data.cs

@@ -35,6 +35,25 @@ public struct ST_ALARM
     public AlarmType AlarmType { get; set; }
 }
 
+public struct ST_CHANNEL
+{
+    public byte Mini8Index { get; set; }
+    public byte ChannelIndex { get; set; }
+    public float PV { get; set; }
+    public float Caps { get; set; }
+    public float Floor { get; set; }
+}
+
+public class ST_CHANNEL_Notify
+{
+    public byte Mini8Index { get; set; }
+    public byte ChannelIndex { get; set; }
+    public float PV { get; set; }
+    public float Caps { get; set; }
+    public float Floor { get; set; }
+}
+
+
 public class ST_ALARM_Notify
 {
     public byte Mini8Index { get; set; }

+ 9 - 1
Communicators/RTCommunicator/RTCommunicatorBase/Interfaces.cs

@@ -1,7 +1,13 @@
-namespace RTCommunicatorBase;
+using System.Collections;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+
+namespace RTCommunicatorBase;
 
 public interface IRTMini8Sender
 {
+    ConcurrentDictionary<string, ST_CHANNEL_Notify> ChannelData { get; }
+
     bool Initialize(IRTMini8Provider provider);
     bool StartService(string ip, int port);
 
@@ -17,8 +23,10 @@ public interface IConnectNotify
 
 public interface IRTMini8Provider : IConnectNotify
 {
+
     void CurrentTempConfigFile(string fileName);
     void ChannelAlarmNotify(ST_ALARM_Notify alarm);
+    void ChannelRealtimeNotify(ST_CHANNEL_Notify channel);
     void Mini8ConnectNotify(byte mini8Index);
     void Mini8DisconnectNotify(byte mini8);
 }

+ 112 - 0
Communicators/RTCommunicator/RTCommunicatorTLV/HeaterType.csv

@@ -0,0 +1,112 @@
+1,1,GaseLine
+1,2,GaseLine
+1,3,GaseLine
+1,4,GaseLine
+1,5,GaseLine
+1,6,GaseLine
+1,7,GaseLine
+1,8,GaseLine
+1,9,GaseLine
+1,10,GaseLine
+1,11,GaseLine
+1,12,GaseLine
+1,13,GaseLine
+1,14,GaseLine
+1,15,GaseLine
+1,16,GaseLine
+2,1,GaseLine
+2,2,GaseLine
+2,3,GaseLine
+2,4,GaseLine
+2,5,GaseLine
+2,6,GaseLine
+2,7,GaseLine
+2,8,GaseLine
+2,9,GaseLine
+2,10,GaseLine
+2,11,GaseLine
+2,12,GaseLine
+2,13,GaseLine
+2,14,GaseLine
+2,15,GaseLine
+2,16,GaseLine
+3,1,GaseLine
+3,2,GaseLine
+3,3,GaseLine
+3,4,GaseLine
+3,5,GaseLine
+3,6,GaseLine
+3,7,GaseLine
+3,8,GaseLine
+3,9,GaseLine
+3,10,GaseLine
+3,11,GaseLine
+3,12,GaseLine
+3,13,GaseLine
+3,14,GaseLine
+3,15,GaseLine
+3,16,GaseLine
+4,1,ForeLine
+4,2,ForeLine
+4,3,ForeLine
+4,4,ForeLine
+4,5,ForeLine
+4,6,ForeLine
+4,7,ForeLine
+4,8,ForeLine
+4,9,ForeLine
+4,10,GaseLine
+4,11,GaseLine
+4,12,GaseLine
+4,13,GaseLine
+4,14,GaseLine
+4,15,GaseLine
+4,16,GaseLine
+6,1,ForeLine
+6,2,ForeLine
+6,3,ForeLine
+6,4,ForeLine
+6,5,ForeLine
+6,6,ForeLine
+6,7,ForeLine
+6,8,ForeLine
+6,9,ForeLine
+6,10,ForeLine
+6,11,ForeLine
+6,12,ForeLine
+6,13,ForeLine
+6,14,ForeLine
+6,15,ForeLine
+6,16,ForeLine
+7,1,ForeLine
+7,2,ForeLine
+7,3,ForeLine
+7,4,ForeLine
+7,5,ForeLine
+7,6,ForeLine
+7,7,ForeLine
+7,8,ForeLine
+7,9,ForeLine
+7,10,ForeLine
+7,11,ForeLine
+7,12,ForeLine
+7,13,ForeLine
+7,14,ForeLine
+7,15,GaseLine
+7,16,GaseLine
+8,1,GaseLine
+8,2,GaseLine
+8,3,GaseLine
+8,4,GaseLine
+8,5,GaseLine
+8,6,GaseLine
+8,7,GaseLine
+8,8,GaseLine
+8,9,GaseLine
+8,10,GaseLine
+8,11,GaseLine
+8,12,GaseLine
+8,13,GaseLine
+8,14,GaseLine
+8,15,GaseLine
+8,16,GaseLine

+ 59 - 0
Communicators/RTCommunicator/RTCommunicatorTLV/HeaterTypeAnalizer.cs

@@ -0,0 +1,59 @@
+using System.IO;
+using System.Collections.Generic;
+using RTCommunicatorBase;
+
+namespace RTCommunicatorTLV;
+
+internal class HeaterTypeAnalizer
+{
+    public static bool Analize(string filePath, out Dictionary<byte, Dictionary<byte, HeaterType>> types)
+    {
+        types = default;
+        if (string.IsNullOrEmpty(filePath))
+            return false;
+
+        if (!File.Exists(filePath))
+            return false;
+
+        try
+        {
+            using var reader = new StreamReader(filePath);
+            string line;
+            types = [];
+            while ((line = reader.ReadLine()) is not null)
+            {
+                string[] cache = line.Split(',');
+                if (cache.Length != 3)
+                    continue;
+
+                if (!byte.TryParse(cache[0], out byte mini8Index))
+                    continue;
+                if (!byte.TryParse(cache[1], out byte channelIndex))
+                    continue;
+                HeaterType heaterType = cache[2] switch
+                {
+                    "GaseLine" => HeaterType.GaseLine,
+                    "ForeLine" => HeaterType.ForeLine,
+                    _ => HeaterType.Undefined,
+                };
+
+                if (!types.TryGetValue(mini8Index, out Dictionary<byte, HeaterType> heaters) || heaters is null)
+                {
+                    heaters = [];
+                    types[mini8Index] = heaters;
+                }
+
+                heaters[channelIndex] = heaterType;
+            }
+        }
+        catch
+        {
+            return false;
+        }
+
+
+        return true;
+    }
+
+
+}

+ 60 - 5
Communicators/RTCommunicator/RTCommunicatorTLV/RTCommunicator_TLV.cs

@@ -20,6 +20,8 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
     private readonly ConcurrentDictionary<byte, Timer> _DisconnectNotifyTimer = [];
     private Dictionary<byte, Dictionary<byte, HeaterType>> _HeaterTypes;
 
+    public ConcurrentDictionary<string, ST_CHANNEL_Notify> ChannelData { get; } = [];
+
     public bool Initialize(IRTMini8Provider provider)
     {
         if (provider is null)
@@ -32,8 +34,10 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
             return false;
 
         this._provider = provider;
+
         return true;
     }
+
     public bool StartService(string ip, int port)
     {
         if (_provider is null)
@@ -49,8 +53,6 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
         if (!client.Initialize(this, false, 500))
             return false;
 
-
-
         Task.Factory.StartNew(() =>
         {
             while (!client.Open(ip, (ushort)port))
@@ -97,7 +99,13 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
                     string fileName = Encoding.UTF8.GetString(data.RawData);
                     if (string.IsNullOrEmpty(fileName))
                         return;
-                    this._provider?.CurrentTempConfigFile(fileName);
+                    try
+                    {
+                        this._provider?.CurrentTempConfigFile(fileName);
+                    }
+                    catch
+                    {
+                    }
                     break;
                 case Tags.ChannelAlarmNotify:
                     if (!StructConverter.TryGetStruct(data.RawData, out ST_ALARM? alarm) || alarm is null)
@@ -122,14 +130,26 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
                         AlarmType = alarm.Value.AlarmType,
                         HeaterType = heaterType,
                     };
-                    this._provider?.ChannelAlarmNotify(alarmNotify);
+                    try
+                    {
+                        this._provider?.ChannelAlarmNotify(alarmNotify);
+                    }
+                    catch
+                    {
+                    }
                     break;
                 case Tags.Mini8ConnectNotify:
                     {
                         byte index = data.RawData[0];
                         this._DisconnectNotifyTimer.TryRemove(index, out Timer timer);
                         timer?.Dispose();
-                        this._provider?.Mini8ConnectNotify(index);
+                        try
+                        {
+                            this._provider?.Mini8ConnectNotify(index);
+                        }
+                        catch
+                        {
+                        }
                         break;
                     }
                 case Tags.Mini8DisconnectNotify:
@@ -139,6 +159,41 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
                             this._DisconnectNotifyTimer[index] = new(DisconnectNotifyTimerCallBack, index, 0, 1000);
                         break;
                     }
+                case Tags.ChannelRealtimeDataNotify:
+                    if (!StructConverter.TryGetStruct(data.RawData, out ST_CHANNEL? channel) || channel is null)
+                        return;
+
+                    string key = $"{channel.Value.Mini8Index}-{channel.Value.ChannelIndex}";
+
+                    if (this.ChannelData.TryGetValue(key, out ST_CHANNEL_Notify notify) || notify is null)
+                    {
+                        notify = new()
+                        {
+                            Mini8Index = channel.Value.Mini8Index,
+                            ChannelIndex = channel.Value.ChannelIndex,
+                            PV = channel.Value.PV,
+                            Caps = channel.Value.Caps,
+                            Floor = channel.Value.Floor,
+                        };
+                        this.ChannelData[key] = notify;
+                    }
+                    else
+                    {
+                        notify.Mini8Index = channel.Value.Mini8Index;
+                        notify.ChannelIndex = channel.Value.ChannelIndex;
+                        notify.PV = channel.Value.PV;
+                        notify.Caps = channel.Value.Caps;
+                        notify.Floor = channel.Value.Floor;
+                    }
+
+                    try
+                    {
+                        this._provider?.ChannelRealtimeNotify(notify);
+                    }
+                    catch
+                    {
+                    }
+                    break;
                 default:
                     break;
             }

+ 1 - 0
Communicators/RTCommunicator/RTCommunicatorTLV/TagDefination.cs

@@ -6,4 +6,5 @@ public static class Tags
     public const byte ChannelAlarmNotify = 1;
     public const byte Mini8ConnectNotify = 2;
     public const byte Mini8DisconnectNotify = 3;
+    public const byte ChannelRealtimeDataNotify = 4;
 }

+ 1 - 1
Configs/ConfigFile/Base/BasicInfo.xml

@@ -4,7 +4,7 @@
 	<ServerAddress>127.0.0.1</ServerAddress>
 	<ServerPort>55004</ServerPort>
 	<SelectedDisplay>2</SelectedDisplay>
-	<RTServerAddress>192.168.250.199</RTServerAddress>
+	<RTServerAddress>127.0.0.1</RTServerAddress>
 	<RTServerPort>50052</RTServerPort>
 	<GasPanelWindowName>FurnaceGasPanel</GasPanelWindowName>
 	<DBClearTime>2025-05-27T11:28:46.4646633+08:00</DBClearTime>

+ 1 - 1
Configs/ConfigFile/IOList/Mini8-1.xml

@@ -2,7 +2,7 @@
 <AddressSaveXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 	<Mini8>
 		<Index>1</Index>
-		<Address>192.168.250.11</Address>
+		<Address>127.0.0.1</Address>
 		<Port>502</Port>
 		<Interval>200</Interval>
 		<GroupeCount>125</GroupeCount>

+ 10 - 1
MinicsConsole/Connector/RTNotifier.cs

@@ -34,7 +34,16 @@ public class RTNotifier(Hardwares hardwares) : IMini8DataNotifier, IDisposable
 
     void IMini8DataNotifier.ChannelInfoNotify(byte mini8, byte channel, ChannelData channelData)
     {
-        return;
+        ST_CHANNEL data = new()
+        {
+            Mini8Index = mini8,
+            ChannelIndex = channel,
+            PV = channelData.PV,
+            Caps = channelData.Caps,
+            Floor = channelData.Floor,
+        };
+
+        this._server?.Send(Tags.ChannelRealtimeDataNotify, data);
     }
 
     void IMini8DataNotifier.AlarmNotify(byte mini8, byte channel, float temperature)

+ 11 - 8
MinicsConsole/Helper/Mini8DataDispatcher.cs

@@ -18,16 +18,19 @@ public class Mini8DataDispatcher(ILog log)
     {
         if (channelData is null)
             return;
-        Parallel.ForEach(_Connectors.Values, item =>
+        Task.Factory.StartNew(() =>
         {
-            try
-            {
-                item?.ChannelInfoNotify(mini8, channel, channelData);
-            }
-            catch
+            Parallel.ForEach(_Connectors.Values, item =>
             {
-                log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {item.Name} mini8 {mini8} channel {channel}");
-            }
+                try
+                {
+                    item?.ChannelInfoNotify(mini8, channel, channelData);
+                }
+                catch
+                {
+                    log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {item.Name} mini8 {mini8} channel {channel}");
+                }
+            });
         });
     }
 

+ 5 - 0
Test/Program.cs

@@ -186,6 +186,11 @@ public class TestClass : IRTMini8Provider
     {
         Console.WriteLine($"Mini8 Disconnected {mini8}");
     }
+
+    public void ChannelRealtimeNotify(ST_CHANNEL_Notify channel)
+    {
+        Console.WriteLine($"{DateTime.Now:HH:mm:ss.f} Mini8 {channel.Mini8Index} Channel {channel.ChannelIndex} {channel.PV}");
+    }
 }
 
 interface ITest