Sfoglia il codice sorgente

Modified RT Alarm Notify, Create Heater type

Zixuan 1 giorno fa
parent
commit
96c039b77b

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

@@ -18,6 +18,13 @@ public enum AlarmType
     TcBroken = 3
 }
 
+public enum HeaterType
+{
+    Undefined,
+    GaseLine,
+    ForeLine,
+}
+
 public struct ST_ALARM
 {
     public byte Mini8Index { get; set; }
@@ -26,4 +33,15 @@ public struct ST_ALARM
     public float Caps { get; set; }
     public float Floor { get; set; }
     public AlarmType AlarmType { get; set; }
+}
+
+public class ST_ALARM_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 AlarmType AlarmType { get; set; }
+    public HeaterType HeaterType { get; set; }
 }

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

@@ -18,7 +18,7 @@ public interface IConnectNotify
 public interface IRTMini8Provider : IConnectNotify
 {
     void CurrentTempConfigFile(string fileName);
-    void ChannelAlarmNotify(ST_ALARM alarm);
+    void ChannelAlarmNotify(ST_ALARM_Notify alarm);
     void Mini8ConnectNotify(byte mini8Index);
     void Mini8DisconnectNotify(byte mini8);
 }

+ 4 - 0
Communicators/RTCommunicator/RTCommunicatorTLV/RTCommunicatorTLV.csproj

@@ -42,6 +42,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="HeaterTypeAnalizer.cs" />
     <Compile Include="RTCommunicator_TLV.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TagDefination.cs" />
@@ -62,6 +63,9 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
+    <None Include="HeaterType.csv">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 29 - 2
Communicators/RTCommunicator/RTCommunicatorTLV/RTCommunicator_TLV.cs

@@ -1,10 +1,13 @@
 using RTCommunicatorBase;
+using System;
 using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.IO;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 
-using TLVProtocal;  
+using TLVProtocal;
 using UniversalNetFrame451;
 using UniversalNetFrame451.IO;
 
@@ -15,6 +18,7 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
     private IRTMini8Provider _provider;
     private ITlvCommunicatorClient _client;
     private readonly ConcurrentDictionary<byte, Timer> _DisconnectNotifyTimer = [];
+    private Dictionary<byte, Dictionary<byte, HeaterType>> _HeaterTypes;
 
     public bool Initialize(IRTMini8Provider provider)
     {
@@ -23,6 +27,9 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
 
         if (this._provider is not null)
             return false;
+        string path = Path.Combine(Environment.CurrentDirectory, "HeaterType.csv");
+        if (!HeaterTypeAnalizer.Analize(path, out _HeaterTypes) || _HeaterTypes is null)
+            return false;
 
         this._provider = provider;
         return true;
@@ -95,7 +102,27 @@ public class RTCommunicator_TLV : IRTMini8Sender, ITlvProvider
                 case Tags.ChannelAlarmNotify:
                     if (!StructConverter.TryGetStruct(data.RawData, out ST_ALARM? alarm) || alarm is null)
                         return;
-                    this._provider?.ChannelAlarmNotify(alarm.Value);
+
+                    if (this._HeaterTypes is null)
+                        return;
+
+                    if (!this._HeaterTypes.TryGetValue(alarm.Value.Mini8Index, out var channels) || channels is null)
+                        return;
+
+                    if (!channels.TryGetValue(alarm.Value.ChannelIndex, out HeaterType heaterType))
+                        return;
+
+                    ST_ALARM_Notify alarmNotify = new()
+                    {
+                        Mini8Index = alarm.Value.Mini8Index,
+                        ChannelIndex = alarm.Value.ChannelIndex,
+                        PV = alarm.Value.PV,
+                        Caps = alarm.Value.Caps,
+                        Floor = alarm.Value.Floor,
+                        AlarmType = alarm.Value.AlarmType,
+                        HeaterType = heaterType,
+                    };
+                    this._provider?.ChannelAlarmNotify(alarmNotify);
                     break;
                 case Tags.Mini8ConnectNotify:
                     {

+ 6 - 0
Minics.sln

@@ -89,6 +89,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtocalGeneral", "Communic
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwinCatADS", "CommunicationProtocols\TwinCatADS\TwinCatADS.csproj", "{81EA7F4C-9379-4314-B8DC-F907F86D8535}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test2", "Test2\Test2.csproj", "{B9BC06BF-BC8E-46C8-AADC-942134A1927D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -223,6 +225,10 @@ Global
 		{81EA7F4C-9379-4314-B8DC-F907F86D8535}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{81EA7F4C-9379-4314-B8DC-F907F86D8535}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{81EA7F4C-9379-4314-B8DC-F907F86D8535}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B9BC06BF-BC8E-46C8-AADC-942134A1927D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B9BC06BF-BC8E-46C8-AADC-942134A1927D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B9BC06BF-BC8E-46C8-AADC-942134A1927D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B9BC06BF-BC8E-46C8-AADC-942134A1927D}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 3
Test/Program.cs

@@ -172,10 +172,9 @@ public class TestClass : IRTMini8Provider
 
     }
 
-    public void ChannelAlarmNotify(ST_ALARM alarm)
+    public void ChannelAlarmNotify(ST_ALARM_Notify alarm)
     {
-        Console.WriteLine($"Alarm Mini8 {alarm.Mini8Index}-{alarm.ChannelIndex:00} {alarm.PV:000.00} {alarm.Caps:000.00} {alarm.Floor:000.00} {alarm.AlarmType}");
-
+        Console.WriteLine($"Alarm Mini8 {alarm.Mini8Index}-{alarm.ChannelIndex:00} {alarm.PV:000.00} {alarm.Caps:000.00} {alarm.Floor:000.00} {alarm.AlarmType} {alarm.HeaterType}");
     }
 
     public void Mini8ConnectNotify(byte mini8Index)

+ 80 - 0
Test2/Program.cs

@@ -0,0 +1,80 @@
+using RTCommunicatorBase;
+using TLVProtocal;
+using UniversalNetFrame451.IO;
+
+namespace Test2;
+
+internal class Program
+{
+    static void Main(string[] args)
+    {
+        Test test = new();
+        test.Initialize();
+        test.Open("127.0.0.1", 50052);
+        while (true)
+        {
+            byte mini8 = Convert.ToByte(Console.ReadLine());
+            byte channel = Convert.ToByte(Console.ReadLine());
+
+            test.Send(mini8,channel);
+        }
+    }
+}
+
+internal class Test : ITlvProvider
+{
+    private ITlvCommunicatorServer? _server;
+
+
+    public bool Initialize()
+    {
+        if (this._server is not null)
+            return false;
+
+        this._server = TlvFactory.GetTlvServer();
+        this._server.Initialize(this);
+        return true;
+    }
+
+    public bool Open(string IP, ushort port)
+    {
+        if (this._server is null)
+            return false;
+
+        return this._server.Open(IP, port);
+
+    }
+
+    public void Received(TlvData data)
+    {
+    }
+
+    public TlvData RequestReply(TlvData tlvData)
+    {
+        return default!;
+    }
+
+    public void Connected(TcpConnection connection)
+    {
+        Console.WriteLine("Connected");
+    }
+
+    public void Disconnected(TcpConnection connection)
+    {
+        Console.WriteLine("Disconnected");
+    }
+
+    public bool Send(byte mini8, byte channel)
+    {
+        ST_ALARM alarm = new()
+        {
+            Mini8Index = mini8,
+            ChannelIndex = channel,
+            PV = 100,
+            Caps = 120,
+            Floor = 80,
+            AlarmType = AlarmType.CapsOverFlow,
+        };
+        return this._server?.Send(1, alarm) == true;
+    }
+}

+ 15 - 0
Test2/Test2.csproj

@@ -0,0 +1,15 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\Communicators\RTCommunicator\RTCommunicatorBase\RTCommunicatorBase.csproj" />
+    <ProjectReference Include="..\TLVProtocal\TLV_Protocol.csproj" />
+  </ItemGroup>
+
+</Project>