lixun 2 yıl önce
ebeveyn
işleme
4d671d4bc1

+ 1 - 0
readme.txt

@@ -28,6 +28,7 @@ RabbitMQ Publisher/Consumer
 5.支持快速对接,与配置
 6.支持虚拟点位
 7.所有采集协议支持订阅模式
+8.采集与转发协议接口统一
 
 
 doc 中有演示视频

+ 0 - 2
src/YSAI.DAQ/YSAI.Core/data/AddressManage.cs

@@ -24,7 +24,5 @@ namespace YSAI.Core.data
         /// 指定数采类型的实例参数
         /// </summary>
         public object? InstanceParam { get; set; }
-
-        
     }
 }

+ 0 - 12
src/YSAI.DAQ/YSAI.Manage.Core/YSAI.Manage.Core.csproj

@@ -7,21 +7,9 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <None Remove="config\RelaySample.json" />
     <None Remove="Sample.json" />
   </ItemGroup>
 
-  <ItemGroup>
-    <Content Include="config\DaqSample.json">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
-      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
-    </Content>
-    <Content Include="config\RelaySample.json">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </Content>
-  </ItemGroup>
-
   <ItemGroup>
     <ProjectReference Include="..\YSAI.DB\YSAI.DB.csproj" />
     <ProjectReference Include="..\YSAI.Kafka\YSAI.Kafka.csproj" />

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 27542
src/YSAI.DAQ/YSAI.Manage.Core/config/DaqSample.json


+ 0 - 123
src/YSAI.DAQ/YSAI.Manage.Core/config/RelaySample.json

@@ -1,123 +0,0 @@
-{
-    "DllDatas": [
-        {
-            "DllPath": "YSAI.Mqtt.dll",
-            "IsAbsolutePath": false,
-            "NamespaceDatas": [
-                {
-                    "Namespace": "YSAI.Mqtt.client",
-                    "ClassDatas": [
-                        {
-                            "SN": "YSAI.Mqtt.MqttClientOperate[Instance]",
-                            "ClassName": "MqttClientOperate",
-                            "ConstructorParam": [
-                                {
-                                    "SN": "YSAI",
-                                    "ServerIPAddress": "127.0.0.1",
-                                    "ServerPort": 11819,
-                                    "ServerLoginID": "ysai",
-                                    "ServerLoginPassword": "ysai",
-                                    "ClientID": null,
-                                    "QualityOfServiceLevel": "AtMostOnce"
-                                }
-                            ],
-                            "MethodDatas": [
-                                {
-                                    "SN": "[Init]",
-                                    "WhetherExecute": true,
-                                    "MethodName": "Init",
-                                    "MethodParam": null
-                                },
-                                {
-                                    "SN": "[On]",
-                                    "WhetherExecute": true,
-                                    "MethodName": "On",
-                                    "MethodParam": null
-                                },
-                                {
-                                    "SN": "[PublishSubscribe]",
-                                    "WhetherExecute": false,
-                                    "MethodName": "PublishSubscribe",
-                                    "MethodParam": null
-                                }
-                            ],
-                            "EventDatas": null
-                        }
-                    ]
-                }
-            ]
-        },
-        {
-            "DllPath": "YSAI.Kafka.dll",
-            "IsAbsolutePath": false,
-            "NamespaceDatas": [
-                {
-                    "Namespace": "YSAI.Kafka",
-                    "ClassDatas": [
-                        {
-                            "SN": "YSAI.Kafka.KafkaProducerOperate[Instance]",
-                            "ClassName": "KafkaProducerOperate",
-                            "ConstructorParam": [
-                                {
-                                    "ClientId": "ysai",
-                                    "WaitTime": 1000,
-                                    "SN": "YSAI",
-                                    "BootstrapServers": "127.0.0.1:8083"
-                                }
-                            ],
-                            "MethodDatas": [
-                                {
-                                    "SN": "[Produce]",
-                                    "WhetherExecute": false,
-                                    "MethodName": "Produce",
-                                    "MethodParam": null
-                                }
-                            ],
-                            "EventDatas": null
-                        }
-                    ]
-                }
-            ]
-        },
-        {
-            "DllPath": "YSAI.RabbitMQ.dll",
-            "IsAbsolutePath": false,
-            "NamespaceDatas": [
-                {
-                    "Namespace": "YSAI.RabbitMQ",
-                    "ClassDatas": [
-                        {
-                            "SN": "YSAI.RabbitMQ.RabbitMQPublisherOperate[Instance]",
-                            "ClassName": "RabbitMQPublisherOperate",
-                            "ConstructorParam": [
-                                {
-                                    "SN": "YSAI",
-                                    "ExChangeName": "exYSAI",
-                                    "HostName": "localhost",
-                                    "Port": 4369,
-                                    "UserName": "ysai",
-                                    "Password": "ysai"
-                                }
-                            ],
-                            "MethodDatas": [
-                                {
-                                    "SN": "[On]",
-                                    "WhetherExecute": true,
-                                    "MethodName": "On",
-                                    "MethodParam": null
-                                },
-                                {
-                                    "SN": "[Publish]",
-                                    "WhetherExecute": false,
-                                    "MethodName": "Publish",
-                                    "MethodParam": null
-                                }
-                            ],
-                            "EventDatas": null
-                        }
-                    ]
-                }
-            ]
-        }
-    ]
-}

+ 1 - 1
src/YSAI.DAQ/YSAI.Manage/Properties/launchSettings.json

@@ -14,7 +14,7 @@
       "dotnetRunMessages": true,
       "launchBrowser": true,
       "launchUrl": "swagger",
-      "applicationUrl": "https://0.0.0.0:19876;http://0.0.0.0:19875",
+      "applicationUrl": "https://127.0.0.1:19876;http://127.0.0.1:19875",
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"
       }

+ 0 - 33
src/YSAI.DAQ/YSAI.Relay/RelayData.cs

@@ -15,7 +15,6 @@ namespace YSAI.Relay
         /// </summary>
         public class Basics
         {
-
             /// <summary>
             /// 消息主题
             /// </summary>
@@ -49,38 +48,6 @@ namespace YSAI.Relay
             /// RabbitMQ 参数集合
             /// </summary>
             public List<RabbitMQData.Basics>? RabbitMQDataArray { get; set; }
-
-            /// <summary>
-            /// 重写基类中的Equals方法
-            /// </summary>
-            /// <param name="obj"></param>
-            /// <returns></returns>
-            public override bool Equals(object obj)
-            {
-                if (obj == null)
-                {
-                    return false;
-                }
-                Basics? Obj = obj as Basics;
-                if (Obj == null)
-                {
-                    return false;
-                }
-                else
-                {
-                    if (MqttClientDataArray.SequenceEqual(Obj.MqttClientDataArray) &&
-                        KafkaProducerDataArray.SequenceEqual(Obj.KafkaProducerDataArray) &&
-                        RabbitMQDataArray.SequenceEqual(Obj.RabbitMQDataArray))
-                    {
-                        return true;
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-            }
         }
-
     }
 }

+ 2 - 1
src/YSAI.DAQ/YSAI.Relay/RelayOperate.cs

@@ -108,7 +108,7 @@ namespace YSAI.Relay
             return Task.Factory.StartNew(() =>
             {
                 //循环
-                while (true)
+                while (TaskArray != null)
                 {
                     try
                     {
@@ -322,6 +322,7 @@ namespace YSAI.Relay
             if (MqttClientArray != null) { foreach (var item in MqttClientArray) { item.Value.Dispose(); } MqttClientArray = null; }
             if (RabbitMQArray != null) { foreach (var item in RabbitMQArray) { item.Value.Dispose(); } RabbitMQArray = null; }
             if (TaskArray != null) { foreach (var item in TaskArray) { item.Value.Dispose(); } TaskArray = null; }
+            DataQueue.Clear();
             ThisObjList = null;
             GC.Collect();
             GC.SuppressFinalize(this);

+ 2 - 0
src/YSAI.DAQ/YSAI.Relay/config/RelayConfig.json

@@ -1,6 +1,8 @@
 {
     "MessageTopic": "message",
     "StatusTopic": "status",
+    "TaskHandleCount": 8,
+    "TaskHandleAccomplishSleepTime": 500,
     "MqttClientDataArray": [
         {
             "SN": "mqtt转发一号",

+ 6 - 76
src/YSAI.DAQ/YSAI.Test/TestAll.cs

@@ -566,14 +566,7 @@ namespace YSAI.Test
                     AddressDescribe = "一个动态的布尔类型",
                     AddressAnotherName = "test",
                     AddressPropertyName = "aaa",
-                    AddressType = Core.@enum.AddressType.Reality,
-                    MqttRelay = new AddressRelay.MqttRelayParam()
-                    {
-                        QoSLevel = 0,
-                        Retain = true,
-                        Topic = "Test/aaa",
-                        ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                    }
+                    AddressType = Core.@enum.AddressType.Reality
                 },
                 new AddressDetails()
                 {
@@ -595,13 +588,6 @@ namespace YSAI.Test
                             ScriptFunction = "Convert",
                             ScriptType = Core.script.ScriptData.ScriptType.JavaScript
                         }
-                    },
-                    MqttRelay = new AddressRelay.MqttRelayParam()
-                    {
-                        QoSLevel = 0,
-                        Retain = true,
-                        Topic = "Test/aah",
-                        ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
                     }
                 },
                 new AddressDetails()
@@ -624,13 +610,6 @@ namespace YSAI.Test
                              ScriptFunction = "Convert",
                              ScriptType = Core.script.ScriptData.ScriptType.JavaScript
                          }
-                     },
-                     MqttRelay = new AddressRelay.MqttRelayParam()
-                     {
-                         QoSLevel = 0,
-                         Retain = true,
-                         Topic = "Test/aag",
-                         ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
                      }
                  },
                 new AddressDetails()
@@ -640,14 +619,7 @@ namespace YSAI.Test
                      AddressDescribe = "虚拟地址",
                      AddressAnotherName = "test",
                      AddressPropertyName = "OPCDA_VirtualAddress",
-                     AddressType = Core.@enum.AddressType.Virtual,
-                    MqttRelay = new AddressRelay.MqttRelayParam()
-                    {
-                        QoSLevel = 0,
-                        Retain = true,
-                        Topic = "Test/OPCDA_VirtualAddress",
-                        ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                    }
+                     AddressType = Core.@enum.AddressType.Virtual
                  },
                 new AddressDetails()
                   {
@@ -656,14 +628,7 @@ namespace YSAI.Test
                       AddressDescribe = "虚拟动态地址",
                       AddressAnotherName = "test",
                       AddressPropertyName = "OPCDA_VirtualDynamicAddress",
-                      AddressType = Core.@enum.AddressType.VirtualDynamic,
-                        MqttRelay = new AddressRelay.MqttRelayParam()
-                        {
-                            QoSLevel = 0,
-                            Retain = true,
-                            Topic = "Test/OPCDA_VirtualDynamicAddress",
-                            ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                        }
+                      AddressType = Core.@enum.AddressType.VirtualDynamic
                   }
             };
 
@@ -682,14 +647,7 @@ namespace YSAI.Test
                     AddressDescribe = "一个动态的布尔类型",
                     AddressAnotherName = "test",
                     AddressPropertyName = "Boolean_Dynamic",
-                    AddressType = Core.@enum.AddressType.Reality,
-                    MqttRelay = new AddressRelay.MqttRelayParam()
-                    {
-                        QoSLevel = 0,
-                        Retain = true,
-                        Topic = "Test/Boolean_Dynamic",
-                        ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                    }
+                    AddressType = Core.@enum.AddressType.Reality
                 },
                 new AddressDetails()
                 {
@@ -711,13 +669,6 @@ namespace YSAI.Test
                             ScriptFunction = "Convert",
                             ScriptType = Core.script.ScriptData.ScriptType.JavaScript
                         }
-                    },
-                    MqttRelay = new AddressRelay.MqttRelayParam()
-                    {
-                        QoSLevel = 0,
-                        Retain = true,
-                        Topic = "Test/String_Dynamic",
-                        ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
                     }
                 },
                 new AddressDetails()
@@ -740,13 +691,6 @@ namespace YSAI.Test
                              ScriptFunction = "Convert",
                              ScriptType = Core.script.ScriptData.ScriptType.JavaScript
                          }
-                     },
-                     MqttRelay = new AddressRelay.MqttRelayParam()
-                     {
-                         QoSLevel = 0,
-                         Retain = true,
-                         Topic = "Test/Double_Dynamic",
-                         ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
                      }
                  },
                 new AddressDetails()
@@ -756,14 +700,7 @@ namespace YSAI.Test
                      AddressDescribe = "虚拟地址",
                      AddressAnotherName = "test",
                      AddressPropertyName = "OPCUA_VirtualAddress",
-                     AddressType = Core.@enum.AddressType.Virtual,
-                        MqttRelay = new AddressRelay.MqttRelayParam()
-                        {
-                            QoSLevel = 0,
-                            Retain = true,
-                            Topic = "Test/OPCUA_VirtualAddress",
-                            ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                        }
+                     AddressType = Core.@enum.AddressType.Virtual
                  },
                 new AddressDetails()
                   {
@@ -772,14 +709,7 @@ namespace YSAI.Test
                       AddressDescribe = "虚拟动态地址",
                       AddressAnotherName = "test",
                       AddressPropertyName = "OPCUA_VirtualDynamicAddress",
-                      AddressType = Core.@enum.AddressType.VirtualDynamic,
-                        MqttRelay = new AddressRelay.MqttRelayParam()
-                        {
-                            QoSLevel = 0,
-                            Retain = true,
-                            Topic = "Test/OPCUA_VirtualDynamicAddress",
-                            ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
-                        }
+                      AddressType = Core.@enum.AddressType.VirtualDynamic
                   }
             };
 

+ 171 - 2
src/YSAI.DAQ/YSAI.TestConsole/Program.cs

@@ -32,6 +32,177 @@ namespace YSAI.TestConsole
         static void Main(string[] args)
         {
 
+            //创建一个采集配置
+            List<AddressManage> addressManages = new List<AddressManage>();
+
+            AddressManage addressManage = new AddressManage();
+            addressManage.DType = Core.@enum.DaqType.OpcDa;
+            addressManage.SN = "OPCDA采集";
+            addressManage.InstanceParam = new OpcDaClientData.Basics() { SN = "OPCDA采集", ServiceName = "Knight.OPC.Server.Demo", ApiVerType = OpcDaClientData.ApiVerType.COM_DA_20 };
+            addressManage.AddressArray = new List<AddressDetails>()
+            {
+                new AddressDetails()
+                {
+                    AddressName = "a.a.a",
+                    AddressDataType = Core.@enum.DataType.Bool,
+                    AddressDescribe = "一个动态的布尔类型",
+                    AddressAnotherName = "test",
+                    AddressPropertyName = "aaa",
+                    AddressType = Core.@enum.AddressType.Reality
+                },
+                new AddressDetails()
+                {
+                    AddressName = "a.a.h",
+                    AddressDataType = Core.@enum.DataType.String,
+                    AddressDescribe = "一个动态的字符串类型",
+                    AddressAnotherName = "test",
+                    AddressPropertyName = "aah",
+                    AddressType = Core.@enum.AddressType.Reality,
+                    AddressParseParam = new AddressParse()
+                    {
+                        ParseType = Core.@enum.ParseType.ScriptAnalysis,
+                        Script = new Core.script.ScriptData.Basics()
+                        {
+                            ScriptCode = @"function Convert(value) 
+                                            {
+                                                return '这是脚本测试,传入的参数是:' + value;
+                                            }",
+                            ScriptFunction = "Convert",
+                            ScriptType = Core.script.ScriptData.ScriptType.JavaScript
+                        }
+                    }
+                },
+                new AddressDetails()
+                 {
+                     AddressName = "a.a.g",
+                     AddressDataType = Core.@enum.DataType.Double,
+                     AddressDescribe = "一个动态的浮点类型",
+                     AddressAnotherName = "test",
+                     AddressPropertyName = "aag",
+                     AddressType = Core.@enum.AddressType.Reality,
+                     AddressParseParam = new AddressParse()
+                     {
+                         ParseType = Core.@enum.ParseType.ScriptAnalysis,
+                         Script = new Core.script.ScriptData.Basics()
+                         {
+                             ScriptCode = @"function Convert(value) 
+                                            {
+                                                return value*1000;
+                                            }",
+                             ScriptFunction = "Convert",
+                             ScriptType = Core.script.ScriptData.ScriptType.JavaScript
+                         }
+                     }
+                 },
+                new AddressDetails()
+                 {
+                     AddressName = "OPCDA_VirtualAddress",
+                     AddressDataType = Core.@enum.DataType.String,
+                     AddressDescribe = "虚拟地址",
+                     AddressAnotherName = "test",
+                     AddressPropertyName = "OPCDA_VirtualAddress",
+                     AddressType = Core.@enum.AddressType.Virtual
+                 },
+                new AddressDetails()
+                  {
+                      AddressName = "OPCDA_VirtualDynamicAddress",
+                      AddressDataType = Core.@enum.DataType.String,
+                      AddressDescribe = "虚拟动态地址",
+                      AddressAnotherName = "test",
+                      AddressPropertyName = "OPCDA_VirtualDynamicAddress",
+                      AddressType = Core.@enum.AddressType.VirtualDynamic
+                  }
+            };
+
+            addressManages.Add(addressManage);
+
+            addressManage = new AddressManage();
+            addressManage.DType = Core.@enum.DaqType.OpcUa;
+            addressManage.SN = "OPCUA采集";
+            addressManage.InstanceParam = new OpcUaClientData.Basics() { SN = "OPCUA采集", Name = "TEST", Password = "ysai", UserName = "ysai", ServerUrl = "opc.tcp://192.168.2.38:8866/Opc.Ua.Service", SamplingInterval = 100 };
+            addressManage.AddressArray = new List<AddressDetails>()
+            {
+                new AddressDetails()
+                {
+                    AddressName = "ns=2;s=Boolean_Dynamic",
+                    AddressDataType = Core.@enum.DataType.Bool,
+                    AddressDescribe = "一个动态的布尔类型",
+                    AddressAnotherName = "test",
+                    AddressPropertyName = "Boolean_Dynamic",
+                    AddressType = Core.@enum.AddressType.Reality
+                },
+                new AddressDetails()
+                {
+                    AddressName = "ns=2;s=String_Dynamic",
+                    AddressDataType = Core.@enum.DataType.String,
+                    AddressDescribe = "一个动态的字符串类型",
+                    AddressAnotherName = "test",
+                    AddressPropertyName = "String_Dynamic",
+                    AddressType = Core.@enum.AddressType.Reality,
+                    AddressParseParam = new AddressParse()
+                    {
+                        ParseType = Core.@enum.ParseType.ScriptAnalysis,
+                        Script = new Core.script.ScriptData.Basics()
+                        {
+                            ScriptCode = @"function Convert(value) 
+                                            {
+                                                return '这是脚本测试,传入的参数是:' + value;
+                                            }",
+                            ScriptFunction = "Convert",
+                            ScriptType = Core.script.ScriptData.ScriptType.JavaScript
+                        }
+                    }
+                },
+                new AddressDetails()
+                 {
+                     AddressName = "ns=2;s=Double_Dynamic",
+                     AddressDataType = Core.@enum.DataType.Double,
+                     AddressDescribe = "一个动态的浮点类型",
+                     AddressAnotherName = "test",
+                     AddressPropertyName = "Double_Dynamic",
+                     AddressType = Core.@enum.AddressType.Reality,
+                     AddressParseParam = new AddressParse()
+                     {
+                         ParseType = Core.@enum.ParseType.ScriptAnalysis,
+                         Script = new Core.script.ScriptData.Basics()
+                         {
+                             ScriptCode = @"function Convert(value) 
+                                            {
+                                                return value*1000;
+                                            }",
+                             ScriptFunction = "Convert",
+                             ScriptType = Core.script.ScriptData.ScriptType.JavaScript
+                         }
+                     }
+                 },
+                new AddressDetails()
+                 {
+                     AddressName = "OPCUA_VirtualAddress",
+                     AddressDataType = Core.@enum.DataType.String,
+                     AddressDescribe = "虚拟地址",
+                     AddressAnotherName = "test",
+                     AddressPropertyName = "OPCUA_VirtualAddress",
+                     AddressType = Core.@enum.AddressType.Virtual
+                 },
+                new AddressDetails()
+                  {
+                      AddressName = "OPCUA_VirtualDynamicAddress",
+                      AddressDataType = Core.@enum.DataType.String,
+                      AddressDescribe = "虚拟动态地址",
+                      AddressAnotherName = "test",
+                      AddressPropertyName = "OPCUA_VirtualDynamicAddress",
+                      AddressType = Core.@enum.AddressType.VirtualDynamic
+                  }
+            };
+
+            addressManages.Add(addressManage);
+
+            //生成文件
+            FileTool.StringToFile("config//DaqConfig.json", JsonTool.JsonEntityToString(addressManages).JsonFormatting());
+
+
+
+            //转发配置
             RelayData.Basics basics = new RelayData.Basics();
             basics.RabbitMQDataArray = new List<RabbitMQData.Basics>();
             basics.KafkaProducerDataArray = new List<KafkaProducerData.Basics>();
@@ -47,8 +218,6 @@ namespace YSAI.TestConsole
 
             FileTool.StringToFile(RelayOperate.ConfigFile, basics.ToJson().JsonFormatting());
 
-
-
             //创建配置
             Basics basics2 = new Basics()
             {