Shun 2 vuotta sitten
vanhempi
commit
f1a17d8768

+ 2 - 1
README.md

@@ -454,4 +454,5 @@ while(true)
 1. 自定义订阅细节修改,移除不必要的事件
 2. 新增松下PLC
 3. 修改获取参数函数细节
-4. 移除不必要的事件跳转
+4. 移除不必要的事件跳转
+5. OpcUa Da 属性BUG修改

+ 1 - 1
src/YSAI.AllenBradley/AllenBradleyOperate.cs

@@ -14,7 +14,7 @@ namespace YSAI.AllenBradley
     /// <summary>
     /// 艾伦·布拉德利 PLC
     /// </summary>
-    public class AllenBradleyOperate : IBaseAbstract, IDaq
+    public sealed class AllenBradleyOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "AllenBradleyOperate";
 

+ 1 - 1
src/YSAI.Beckhoff/BeckhoffOperate.cs

@@ -15,7 +15,7 @@ namespace YSAI.Beckhoff
     /// <summary>
     /// 倍福PLC
     /// </summary>
-    public class BeckhoffOperate : IBaseAbstract, IDaq
+    public sealed class BeckhoffOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "BeckhoffOperate";
 

+ 1 - 1
src/YSAI.Can/CanOperate.cs

@@ -12,7 +12,7 @@ namespace YSAI.Can
     /// <summary>
     /// can的读取比较特殊无须地址
     /// </summary>
-    public class CanOperate : IBaseAbstract, IDaq
+    public sealed class CanOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "CanOperate";
 

+ 1 - 1
src/YSAI.Mewtocol/MewtocolData.cs

@@ -36,7 +36,7 @@ namespace YSAI.Mewtocol
             [Description("协议类型")]
             [JsonConverter(typeof(StringEnumConverter))]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.select)]
-            public ProtocolType ProtocolType { get; set; } = ProtocolType.Tcp;
+            public ProtocolType PType { get; set; } = ProtocolType.Tcp;
 
             /// <summary>
             /// 超时时间

+ 6 - 6
src/YSAI.Mewtocol/MewtocolOperate.cs

@@ -14,7 +14,7 @@ namespace YSAI.Mewtocol
     /// <summary>
     /// 松下PLC 操作
     /// </summary>
-    public class MewtocolOperate : IBaseAbstract, IDaq
+    public sealed class MewtocolOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "MewtocolOperate";
 
@@ -103,7 +103,7 @@ namespace YSAI.Mewtocol
             {
                 //节点数据
                 ConcurrentDictionary<string, AddressValue> param = new ConcurrentDictionary<string, AddressValue>();
-                switch (basics.ProtocolType)
+                switch (basics.PType)
                 {
                     case MewtocolData.ProtocolType.Tcp:
                         if (MTcp == null)
@@ -363,7 +363,7 @@ namespace YSAI.Mewtocol
                 //失败消息
                 List<string> FailMessage = new List<string>();
 
-                switch (basics.ProtocolType)
+                switch (basics.PType)
                 {
                     case MewtocolData.ProtocolType.Tcp:
                         if (MTcp == null)
@@ -661,7 +661,7 @@ namespace YSAI.Mewtocol
             string SN = Depart("On");
             try
             {
-                switch (basics.ProtocolType)
+                switch (basics.PType)
                 {
                     case MewtocolData.ProtocolType.Tcp:
                         if (MTcp != null)
@@ -724,7 +724,7 @@ namespace YSAI.Mewtocol
             string SN = Depart("Off");
             try
             {
-                switch (basics.ProtocolType)
+                switch (basics.PType)
                 {
                     case MewtocolData.ProtocolType.Tcp:
                         if (MTcp == null)
@@ -802,7 +802,7 @@ namespace YSAI.Mewtocol
 
         public OperateResult GetStatus()
         {
-            switch (basics.ProtocolType)
+            switch (basics.PType)
             {
                 case MewtocolData.ProtocolType.Tcp:
                     return Break(Depart("GetStatus"), MTcp?.IsConnected ?? false, MTcp?.IsConnected ?? false ? "已连接" : "未连接");

+ 2 - 2
src/YSAI.Mitsubishi/MitsubishiData.cs

@@ -65,13 +65,13 @@ namespace YSAI.Mitsubishi
             [Description("协议类型")]
             [JsonConverter(typeof(StringEnumConverter))]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.select)]
-            public pType PType { get; set; } = pType.A1E;
+            public ProtocolType PType { get; set; } = ProtocolType.A1E;
         }
 
         /// <summary>
         /// 协议类型
         /// </summary>
-        public enum pType
+        public enum ProtocolType
         {
             /// <summary>
             /// 三菱MC.A1E帧

+ 9 - 9
src/YSAI.Mitsubishi/MitsubishiOperate.cs

@@ -16,7 +16,7 @@ namespace YSAI.Mitsubishi
     /// <summary>
     /// 三菱PLC通信客户端
     /// </summary>
-    public class MitsubishiOperate : IBaseAbstract, IDaq
+    public sealed class MitsubishiOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "MitsubishiOperate";
 
@@ -540,11 +540,11 @@ namespace YSAI.Mitsubishi
             //类型判断
             switch (basics.PType)
             {
-                case pType.A1E:
+                case ProtocolType.A1E:
                     details = ParseA1E(address);
                     command = ReadCommand_A1E(details.BeginAddress, details.TypeCode, (ushort)length, isBit);
                     break;
-                case pType.QNA3E:
+                case ProtocolType.QNA3E:
                     details = ParseQNA3E(address);
                     command = ReadCommand_QNA3E(details.BeginAddress, details.TypeCode, (ushort)length, isBit);
                     break;
@@ -553,7 +553,7 @@ namespace YSAI.Mitsubishi
             OperateResult operateResult = null;
             switch (basics.PType)
             {
-                case pType.A1E:
+                case ProtocolType.A1E:
                     var lenght = command[10] + command[11] * 256;
                     if (isBit)
                     {
@@ -564,7 +564,7 @@ namespace YSAI.Mitsubishi
                         operateResult = tcpClientOperate.SendWait(command);
                     }
                     break;
-                case pType.QNA3E:
+                case ProtocolType.QNA3E:
                     operateResult = tcpClientOperate.SendWait(command);
                     break;
             }
@@ -585,11 +585,11 @@ namespace YSAI.Mitsubishi
             byte[] RValue = null;
             switch (basics.PType)
             {
-                case pType.A1E:
+                case ProtocolType.A1E:
                     RValue = new byte[bytes.Length - 2];
                     Array.Copy(bytes, 2, RValue, 0, RValue.Length);
                     break;
-                case pType.QNA3E:
+                case ProtocolType.QNA3E:
                     if (isBit)
                     {
                         len = (ushort)Math.Ceiling(len * 0.5);
@@ -624,11 +624,11 @@ namespace YSAI.Mitsubishi
             //类型判断
             switch (basics.PType)
             {
-                case pType.A1E:
+                case ProtocolType.A1E:
                     details = ParseA1E(address);
                     command = WriteCommand_A1E(details.BeginAddress, details.TypeCode, data, isBit);
                     break;
-                case pType.QNA3E:
+                case ProtocolType.QNA3E:
                     details = ParseQNA3E(address);
                     command = WriteCommand_QNA3E(details.BeginAddress, details.TypeCode, data, isBit);
                     break;

+ 1 - 1
src/YSAI.Modbus/ModbusData.cs

@@ -94,7 +94,7 @@ namespace YSAI.Modbus
             [Description("协议类型")]
             [JsonConverter(typeof(StringEnumConverter))]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.select)]
-            public ProtocolType ProtocolType { get; set; } = ProtocolType.Tcp;
+            public ProtocolType PType { get; set; } = ProtocolType.Tcp;
 
             /// <summary>
             /// 读取超时时间

+ 3 - 3
src/YSAI.Modbus/ModbusOperate.cs

@@ -297,7 +297,7 @@ namespace YSAI.Modbus
                 //工厂方法
                 ModbusFactory modbusFactory = new ModbusFactory();
 
-                switch (basics.ProtocolType)
+                switch (basics.PType)
                 {
                     case ModbusData.ProtocolType.Rtu:
                     case ModbusData.ProtocolType.Ascii:
@@ -323,13 +323,13 @@ namespace YSAI.Modbus
                         SerialPortAdapter serialPortAdapter = new SerialPortAdapter(serialPort);
 
                         //Ascii
-                        if (basics.ProtocolType.Equals(ModbusData.ProtocolType.Ascii))
+                        if (basics.PType.Equals(ModbusData.ProtocolType.Ascii))
                         {
                             //创建对象
                             modbusMaster = modbusFactory.CreateAsciiMaster(serialPortAdapter);
                         }
                         //Rtu
-                        if (basics.ProtocolType.Equals(ModbusData.ProtocolType.Rtu))
+                        if (basics.PType.Equals(ModbusData.ProtocolType.Rtu))
                         {
                             //创建对象
                             modbusMaster = modbusFactory.CreateRtuMaster(serialPortAdapter);

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

@@ -11,7 +11,7 @@ namespace YSAI.NetMQ
     /// <summary>
     /// NetMQ 是轻量级消息传递库 ZeroMQ 的 100% 原生 C# 端
     /// </summary>
-    public class NetMQOperate : IBaseAbstract, IRelay
+    public sealed class NetMQOperate : IBaseAbstract, IRelay
     {
         protected override string TAG => "NetMQClientOperate";
 

+ 1 - 1
src/YSAI.Netty/client/NettyClientOperate.cs

@@ -14,7 +14,7 @@ using YSAI.Unility;
 
 namespace YSAI.Netty.client
 {
-    public class NettyClientOperate : IBaseAbstract, IRelay
+    public sealed class NettyClientOperate : IBaseAbstract, IRelay
     {
         protected override string TAG => "NettyClientOperate";
 

+ 1 - 1
src/YSAI.Netty/service/NettyServiceOperate.cs

@@ -14,7 +14,7 @@ using YSAI.Unility;
 
 namespace YSAI.Netty.service
 {
-    public class NettyServiceOperate : IBaseAbstract, IDisposable
+    public sealed class NettyServiceOperate : IBaseAbstract, IDisposable
     {
         protected override string TAG => "NettyServiceOperate";
 

+ 2 - 2
src/YSAI.Omron/OmronData.cs

@@ -86,7 +86,7 @@ namespace YSAI.Omron
             [Description("协议类型")]
             [JsonConverter(typeof(StringEnumConverter))]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.select)]
-            public pType PType { get; set; } = pType.FINS;
+            public ProtocolType PType { get; set; } = ProtocolType.FINS;
 
             /// <summary>
             /// 数据大小端
@@ -132,7 +132,7 @@ namespace YSAI.Omron
         /// <summary>
         /// 协议类型
         /// </summary>
-        public enum pType
+        public enum ProtocolType
         {
             /// <summary>
             /// 欧姆龙FINS

+ 3 - 3
src/YSAI.Omron/OmronOperate.cs

@@ -15,7 +15,7 @@ namespace YSAI.Omron
     /// <summary>
     /// 欧姆龙PLC操作
     /// </summary>
-    public class OmronOperate : IBaseAbstract, IDaq
+    public sealed class OmronOperate : IBaseAbstract, IDaq
     {
         protected override string TAG => "OmronOperate";
 
@@ -280,7 +280,7 @@ namespace YSAI.Omron
             //类型判断
             switch (basics.PType)
             {
-                case pType.FINS:
+                case ProtocolType.FINS:
                     details = ParseFins(address);
                     command = ReadCommandFins(details, (ushort)length);
                     break;
@@ -332,7 +332,7 @@ namespace YSAI.Omron
             //类型判断
             switch (basics.PType)
             {
-                case pType.FINS:
+                case ProtocolType.FINS:
                     details = ParseFins(address, isBit: isBit);
                     command = WriteCommandFins(details, data);
                     break;

+ 5 - 5
src/YSAI.S7/S7Data.cs

@@ -27,19 +27,19 @@ namespace YSAI.S7
             [Description("IP")]
             [Verify(@"^(25[0-4]|2[0-4]\\d]|[01]?\\d{2}|[1-9])\\.(25[0-5]|2[0-4]\\d]|[01]?\\d?\\d)\\.(25[0-5]|2[0-4]\\d]|[01]?\\d?\\d)\\.(25[0-4]|2[0-4]\\d]|[01]?\\d{2}|[1-9])$", "输入有误")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.text)]
-            public string? Ip { get; set; }
+            public string? Ip { get; set; } = "127.0.0.1";
 
             /// <summary>
             /// 端口
             /// </summary>
             [Description("端口")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.unmber)]
-            public int Port { get; set; }
+            public int Port { get; set; } = 6688;
 
             /// <summary>
             /// CPU类型
             /// </summary>
-            [Description("CPU类型")]
+            [Description("Cpu类型")]
             [JsonConverter(typeof(StringEnumConverter))]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.select)]
             public CpuType S7CpuType { get; set; }
@@ -49,7 +49,7 @@ namespace YSAI.S7
             /// 通常为0,
             /// 但检查Step7或TIA门户的硬件配置
             /// </summary>
-            [Description("PLC机架")]
+            [Description("Plc机架")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.unmber)]
             public int Rack { get; set; } = 0;
 
@@ -58,7 +58,7 @@ namespace YSAI.S7
             /// S7-300/S7-400为2,
             /// S7-1200/S7-1500为0
             /// </summary>
-            [Description("PLCCPU插槽")]
+            [Description("Cpu插槽")]
             [Display(true, true, true, Core.data.ParamStructure.dataCate.unmber)]
             public int Slot { get; set; } = 0;
         }

+ 93 - 93
src/YSAI.Test.All/Program.cs

@@ -1,4 +1,4 @@
-Console.WriteLine();
+
 
 //Console.WriteLine(DateTime.Parse($"{0}:{0}:{0}.{123}").ToString("HH:mm:ss:fff"));
 
@@ -720,104 +720,104 @@
 //    public string Description { get; set; }
 //}
 
-//using System.Collections.Concurrent;
-//using YSAI.Core.data;
-//using YSAI.Log;
-//using YSAI.Opc.ua.client;
-//using YSAI.Unility;
-
-///// <summary>
-///// 读取Csv,返回行集合
-///// </summary>
-///// <param name="path"></param>
-///// <param name="hasTitle"></param>
-///// <returns></returns>
-//List<string> ReadCsv(string path, bool hasTitle)
-//{
-//    if (!File.Exists(path))
-//        return new List<string>();
+using System.Collections.Concurrent;
+using YSAI.Core.data;
+using YSAI.Log;
+using YSAI.Opc.ua.client;
+using YSAI.Unility;
+
+/// <summary>
+/// 读取Csv,返回行集合
+/// </summary>
+/// <param name="path"></param>
+/// <param name="hasTitle"></param>
+/// <returns></returns>
+List<string> ReadCsv(string path, bool hasTitle)
+{
+    if (!File.Exists(path))
+        return new List<string>();
+
+    var lines = File.ReadAllLines(path).ToList();
+    if (hasTitle)
+    {
+        lines.RemoveAt(0);
+    }
+    return lines;
+}
+
+//Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\[6032]Node_Address 202310120854271486.json"));
+
+Address address = new Address();
+address.SN = Guid.NewGuid().ToString();
+address.CreationTime = DateTime.Now;
+address.AddressArray = new List<AddressDetails>();
+List<string> strings = ReadCsv("C:\\Users\\Shun\\Desktop\\6022.csv", true);
+foreach (var item in strings)
+{
+    string[] str = item.Split(",");
+    string addressD = str[0].Replace("\"", "");
+    address.AddressArray.Add(new AddressDetails()
+    {
+        AddressName = $"ns=2;s=6022.6022.{addressD}",
+        SN = Guid.NewGuid().ToString()
+    });
+}
 
-//    var lines = File.ReadAllLines(path).ToList();
-//    if (hasTitle)
-//    {
-//        lines.RemoveAt(0);
-//    }
-//    return lines;
-//}
-
-////Address address = JsonTool.StringToJsonEntity<Address>(FileTool.FileToString("C:\\Users\\Shun\\Desktop\\[6032]Node_Address 202310120854271486.json"));
-
-//Address address = new Address();
-//address.SN = Guid.NewGuid().ToString();
-//address.CreationTime = DateTime.Now;
-//address.AddressArray = new List<AddressDetails>();
-//List<string> strings = ReadCsv("C:\\Users\\Shun\\Desktop\\6022.csv", true);
-//foreach (var item in strings)
-//{
-//    string[] str = item.Split(",");
-//    string addressD = str[0].Replace("\"", "");
-//    address.AddressArray.Add(new AddressDetails()
-//    {
-//        AddressName = $"ns=2;s=6022.6022.{addressD}",
-//        SN = Guid.NewGuid().ToString()
-//    });
-//}
-
-////address.AddressArray.Add(new AddressDetails()
-////{
-////    AddressName = $"ns=2;s=6022.6022.LAP5_DP2113_AUTO",
-////    SN = Guid.NewGuid().ToString()
-////});
-
-////address.AddressArray.Add(new AddressDetails()
-////{
-////    AddressName = $"ns=2;s=6022.6022.LAP5_DP2112_STATE_RUN",
-////    SN = Guid.NewGuid().ToString()
-////});
-
-//OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
+//address.AddressArray.Add(new AddressDetails()
 //{
-//    ServerUrl = "opc.tcp://192.168.2.220:49320",
-//    CustomName = "YSAI 性能测试",
-//    TaskNumber = 10,
-//    TaskHandleInterval = 1,
-//    SubscribeSingleGroupMaxCount = 1000,
+//    AddressName = $"ns=2;s=6022.6022.LAP5_DP2113_AUTO",
+//    SN = Guid.NewGuid().ToString()
 //});
-//Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
-//opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
 
-//while (true)
-//{
-//    Console.ReadLine();
-//    OperateResult operateResult = opcUaClientOperate.Subscribe(address);
-//    Console.WriteLine(operateResult.ToJson().JsonFormatting());
-//}
-
-//void OpcUaClientOperate_OnEvent(object? sender, EventResult e)
+//address.AddressArray.Add(new AddressDetails()
 //{
-//    switch (e.RType)
-//    {
-//        case YSAI.Core.@enum.ResultType.KeyValue:
-
-//            ConcurrentDictionary<string, AddressValue> pairs = e.GetRData<ConcurrentDictionary<string, AddressValue>>();
-//            foreach (var item in pairs)
-//            {
-//                if (item.Value.AddressName.Equals("ns=2;s=6022.6022.LAP5_DP2112_STATE_RUN") || item.Value.AddressName.Equals("ns=2;s=6022.6022.LAP5_DP2113_AUTO"))
-//                {
-//                    //String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
-//                    //LogHelper.Verbose(str);
-//                }
-
-//                String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
-//                LogHelper.Verbose(str);
-//            }
-//            break;
+//    AddressName = $"ns=2;s=6022.6022.LAP5_DP2112_STATE_RUN",
+//    SN = Guid.NewGuid().ToString()
+//});
 
-//        default:
-//            //Console.WriteLine(e.Message);
-//            break;
-//    }
-//}
+OpcUaClientOperate opcUaClientOperate = OpcUaClientOperate.Instance(new OpcUaClientData.Basics
+{
+    ServerUrl = "opc.tcp://192.168.2.220:49320",
+    CustomName = "YSAI 性能测试",
+    TaskNumber = 10,
+    TaskHandleInterval = 1,
+    SubscribeSingleGroupMaxCount = 1000,
+});
+Console.WriteLine(opcUaClientOperate.On().ToJson().JsonFormatting());
+opcUaClientOperate.OnEvent += OpcUaClientOperate_OnEvent;
+
+while (true)
+{
+    Console.ReadLine();
+    OperateResult operateResult = opcUaClientOperate.Subscribe(address);
+    Console.WriteLine(operateResult.ToJson().JsonFormatting());
+}
+
+void OpcUaClientOperate_OnEvent(object? sender, EventResult e)
+{
+    switch (e.RType)
+    {
+        case YSAI.Core.@enum.ResultType.KeyValue:
+
+            ConcurrentDictionary<string, AddressValue> pairs = e.GetRData<ConcurrentDictionary<string, AddressValue>>();
+            foreach (var item in pairs)
+            {
+                if (item.Value.AddressName.Equals("ns=2;s=6022.6022.LAP5_DP2112_STATE_RUN") || item.Value.AddressName.Equals("ns=2;s=6022.6022.LAP5_DP2113_AUTO"))
+                {
+                    String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
+                    LogHelper.Verbose(str);
+                }
+
+                //String str = String.Format("{0,-100}{1,-100}", item.Key, item.Value.Value);
+                //LogHelper.Verbose(str);
+            }
+            break;
+
+        default:
+            //Console.WriteLine(e.Message);
+            break;
+    }
+}
 
 //using Opc.Ua;
 //using YSAI.Core.data;

+ 1 - 1
src/YSAI.Test/UnitTest1.cs

@@ -284,7 +284,7 @@ namespace YSAI.Test
 
             using (ModbusOperate modbusOperate = ModbusOperate.Instance(new ModbusData.Basics()
             {
-                ProtocolType = ModbusData.ProtocolType.Tcp,
+                PType = ModbusData.ProtocolType.Tcp,
                 Ip = "127.0.0.1"
             }))
             {