|
@@ -1,4 +1,5 @@
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
+using OpcDaNetApi;
|
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Concurrent;
|
|
|
using System.Drawing;
|
|
using System.Drawing;
|
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
@@ -11,6 +12,7 @@ using YSAI.Kafka;
|
|
|
using YSAI.Log;
|
|
using YSAI.Log;
|
|
|
using YSAI.Mqtt.client;
|
|
using YSAI.Mqtt.client;
|
|
|
using YSAI.Mqtt.service.websocket;
|
|
using YSAI.Mqtt.service.websocket;
|
|
|
|
|
+using YSAI.Opc.da.client;
|
|
|
using YSAI.Opc.ua.client;
|
|
using YSAI.Opc.ua.client;
|
|
|
using YSAI.Opc.ua.service;
|
|
using YSAI.Opc.ua.service;
|
|
|
using YSAI.RabbitMQ;
|
|
using YSAI.RabbitMQ;
|
|
@@ -23,9 +25,347 @@ namespace YSAI.TestConsole
|
|
|
{
|
|
{
|
|
|
static void Main(string[] args)
|
|
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", SpecificationVer = Specification.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,
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/aaa",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ 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
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/aah",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ 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
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/aag",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new AddressDetails()
|
|
|
|
|
+ {
|
|
|
|
|
+ AddressName = "OPCDA_VirtualAddress",
|
|
|
|
|
+ AddressDataType = Core.@enum.DataType.String,
|
|
|
|
|
+ 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]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new AddressDetails()
|
|
|
|
|
+ {
|
|
|
|
|
+ AddressName = "OPCDA_VirtualDynamicAddress",
|
|
|
|
|
+ AddressDataType = Core.@enum.DataType.String,
|
|
|
|
|
+ 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]"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ 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,
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/Boolean_Dynamic",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ 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
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/String_Dynamic",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ 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
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ MqttRelay = new AddressRelay.MqttRelayParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ QoSLevel = 0,
|
|
|
|
|
+ Retain = true,
|
|
|
|
|
+ Topic = "Test/Double_Dynamic",
|
|
|
|
|
+ ReflectionSN = "YSAI.Mqtt.MqttClientOperate[Instance][PublishSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new AddressDetails()
|
|
|
|
|
+ {
|
|
|
|
|
+ AddressName = "OPCUA_VirtualAddress",
|
|
|
|
|
+ AddressDataType = Core.@enum.DataType.String,
|
|
|
|
|
+ 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]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new AddressDetails()
|
|
|
|
|
+ {
|
|
|
|
|
+ AddressName = "OPCUA_VirtualDynamicAddress",
|
|
|
|
|
+ AddressDataType = Core.@enum.DataType.String,
|
|
|
|
|
+ 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]"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ addressManages.Add(addressManage);
|
|
|
|
|
+
|
|
|
|
|
+ //生成文件
|
|
|
|
|
+ FileTool.StringToFile("config//DaqConfig.json", JsonTool.JsonEntityToString(addressManages).JsonFormatting());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ List<AddressManage>? addresses = JsonTool.StringToJsonEntity<List<AddressManage>>(FileTool.FileToString("config//DaqConfig.json"));
|
|
|
|
|
+
|
|
|
|
|
+ OpcDaClientData.Basics? basics1=JsonTool.StringToJsonEntity<OpcDaClientData.Basics>(addresses[0].InstanceParam.ToString());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //创建一个转发配置
|
|
|
|
|
+ ReflectionData.Basics basics = new ReflectionData.Basics()
|
|
|
|
|
+ {
|
|
|
|
|
+ DllDatas = new List<Basics.DllData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData()
|
|
|
|
|
+ {
|
|
|
|
|
+ DllPath="YSAI.Mqtt.dll",
|
|
|
|
|
+ IsAbsolutePath=false,
|
|
|
|
|
+ NamespaceDatas=new List<Basics.DllData.NamespaceData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData.NamespaceData()
|
|
|
|
|
+ {
|
|
|
|
|
+ Namespace="YSAI.Mqtt.service.websocket",
|
|
|
|
|
+ ClassDatas=new List<Basics.DllData.NamespaceData.ClassData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData()
|
|
|
|
|
+ {
|
|
|
|
|
+ ClassName="MqttWebSocketServiceOperate",
|
|
|
|
|
+ ConstructorParam=new object[]{ new MqttWebSocketServiceData.Basics { LoginID="ysai",LoginPassword="ysai",Port= 11819, HttpPort= 11820, Uri="NB_CLASS" } },
|
|
|
|
|
+ SN="YSAI.Mqtt.MqttWebSocketServiceOperate[Instance]",
|
|
|
|
|
+ MethodDatas=new List<Basics.DllData.NamespaceData.ClassData.MethodData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="On",
|
|
|
|
|
+ SN="[On]",
|
|
|
|
|
+ WhetherExecute=true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData()
|
|
|
|
|
+ {
|
|
|
|
|
+ Namespace="YSAI.Mqtt.client",
|
|
|
|
|
+ ClassDatas=new List<Basics.DllData.NamespaceData.ClassData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData()
|
|
|
|
|
+ {
|
|
|
|
|
+ ClassName="MqttClientOperate",
|
|
|
|
|
+ ConstructorParam=new object[]{ new MqttClientData.Basics { QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce, ServerIPAddress = "127.0.0.1", ServerLoginID = "ysai", ServerLoginPassword = "ysai", ServerPort = 11819 } },
|
|
|
|
|
+ SN="YSAI.Mqtt.MqttClientOperate[Instance]",
|
|
|
|
|
+ MethodDatas=new List<Basics.DllData.NamespaceData.ClassData.MethodData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="Init",
|
|
|
|
|
+ SN="[Init]",
|
|
|
|
|
+ WhetherExecute=true
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="On",
|
|
|
|
|
+ SN="[On]",
|
|
|
|
|
+ WhetherExecute=true
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="Off",
|
|
|
|
|
+ SN="[Off]"
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="PublishSubscribe",
|
|
|
|
|
+ SN="[PublishSubscribe]"
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="AddSubscribe",
|
|
|
|
|
+ SN="[AddSubscribe]"
|
|
|
|
|
+ },
|
|
|
|
|
+ new Basics.DllData.NamespaceData.ClassData.MethodData()
|
|
|
|
|
+ {
|
|
|
|
|
+ MethodName="RemoveSubscribe",
|
|
|
|
|
+ SN="[RemoveSubscribe]"
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ EventDatas=new List<ClassData.EventData>()
|
|
|
|
|
+ {
|
|
|
|
|
+ new ClassData.EventData()
|
|
|
|
|
+ {
|
|
|
|
|
+ EventName="OnEvent",
|
|
|
|
|
+ SN="[OnEvent]"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ //生成文件
|
|
|
|
|
+ FileTool.StringToFile(ReflectionOperate.ConfigFile, JsonTool.JsonEntityToString(basics).JsonFormatting());
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|