Shun 2 years ago
parent
commit
5fd292e746

BIN
src/YSAI.DAQ/YSAI.Lib/YSAI.Modbus.Pack/YSAI.Modbus.dll


BIN
src/YSAI.DAQ/YSAI.Lib/YSAI.Modbus.Pack/YSAI.Modbus.pdb


+ 16 - 12
src/YSAI.DAQ/YSAI.Log/LogBase.cs

@@ -58,12 +58,16 @@ namespace YSAI.Log
             {
                 filename = LogFileName;
             }
-
+            //文件夹
+            string folder = string.Empty;
+            //后缀
+            string suffix = string.Empty;
             //名称格式
             string[] strings = filename.Split('.');
             if (strings.Length == 2)
             {
-                filename = $"{strings[0]}-.{strings[1]}";
+                folder = strings[0];
+                suffix = $".{strings[1]}";
             }
             else
             {
@@ -79,7 +83,8 @@ namespace YSAI.Log
                         name += $"{strings[i]}.";
                     }
                 }
-                filename = $"{name}-.{strings[strings.Length - 1]}";
+                folder = name;
+                suffix = $".{strings[strings.Length - 1]}";
             }
 
             //对象判断
@@ -89,10 +94,10 @@ namespace YSAI.Log
                 string template = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} | {Level:u3} | {Message:lj}{NewLine}{Exception}";
 
                 //路径
-                string path = $"{LogFileLocation}{LogFolderName}//{DateTime.Now.ToString("yyyy-MM-dd")}//";
+                string path = $"{LogFileLocation}{LogFolderName}/{DateTime.Now.ToString("yyyy-MM-dd")}/";
 
                 //文件路径
-                string filePath = $"{path}/{filename}";
+                string filePath = $"{path}/{folder}/{suffix}";
 
                 //以什么格式记录日志
                 RollingInterval rollingInterval = RollingInterval.Hour;  //小时
@@ -117,7 +122,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Verbose:
                     if (exception != null)
                     {
-                        LogIoc[filename].Verbose(info, exception);
+                        LogIoc[filename].Verbose(exception, info);
                     }
                     else
                     {
@@ -127,7 +132,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Debug:
                     if (exception != null)
                     {
-                        LogIoc[filename].Debug(info, exception);
+                        LogIoc[filename].Debug(exception, info);
                     }
                     else
                     {
@@ -137,7 +142,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Information:
                     if (exception != null)
                     {
-                        LogIoc[filename].Information(info, exception);
+                        LogIoc[filename].Information(exception, info);
                     }
                     else
                     {
@@ -147,7 +152,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Warning:
                     if (exception != null)
                     {
-                        LogIoc[filename].Warning(info, exception);
+                        LogIoc[filename].Warning(exception, info);
                     }
                     else
                     {
@@ -157,7 +162,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Error:
                     if (exception != null)
                     {
-                        LogIoc[filename].Error(info, exception);
+                        LogIoc[filename].Error(exception, info);
                     }
                     else
                     {
@@ -167,7 +172,7 @@ namespace YSAI.Log
                 case Serilog.Events.LogEventLevel.Fatal:
                     if (exception != null)
                     {
-                        LogIoc[filename].Fatal(info, exception);
+                        LogIoc[filename].Fatal(exception, info);
                     }
                     else
                     {
@@ -175,7 +180,6 @@ namespace YSAI.Log
                     }
                     break;
             }
-
         }
 
         /// <summary>

+ 1 - 1
src/YSAI.DAQ/YSAI.Manage/param/YSAI.Kafka.Param.json

@@ -1,5 +1,5 @@
 {
-    "SN": "54178e14-cee5-4297-8674-9ba67514816b",
+    "SN": "ac0f9544-48f0-433a-946c-15dc6d2b2ae9",
     "BootstrapServers": null,
     "WaitTime": 1000,
     "SecurityProtocol": "Plaintext",

+ 8 - 3
src/YSAI.DAQ/YSAI.Manage/param/YSAI.Modbus.Param.json

@@ -6,9 +6,14 @@
     "MRType": "NULL",
     "MWType": "NULL",
     "WriteTimeOut": 2000,
-    "TcpParam": null,
-    "UdpParam": null,
-    "SerialPortParam": null,
+    "Ip": "127.0.0.1",
+    "Port": 502,
+    "ConnectTimeOut": 5000,
+    "PortName": null,
+    "BaudRate": 19200,
+    "ParityBit": "Even",
+    "DataBit": 8,
+    "StopBit": "One",
     "SleepTime": 0,
     "DataChangeOut": true,
     "SameDataOut": false

+ 80 - 118
src/YSAI.DAQ/YSAI.Manage/param/YSAI.Modbus.ParamDetails.json

@@ -122,145 +122,107 @@
         "ObjArray": null
     },
     {
-        "Name": "TcpParam",
-        "Describe": "TCP参数",
-        "ParamType": "TcpParam",
+        "Name": "Ip",
+        "Describe": "IP",
+        "ParamType": "String",
+        "EnumArray": null,
+        "ObjArray": null
+    },
+    {
+        "Name": "Port",
+        "Describe": "端口",
+        "ParamType": "Int32",
+        "EnumArray": null,
+        "ObjArray": null
+    },
+    {
+        "Name": "ConnectTimeOut",
+        "Describe": "连接超时时间",
+        "ParamType": "Int32",
+        "EnumArray": null,
+        "ObjArray": null
+    },
+    {
+        "Name": "PortName",
+        "Describe": "串口号",
+        "ParamType": "String",
         "EnumArray": null,
-        "ObjArray": [
+        "ObjArray": null
+    },
+    {
+        "Name": "BaudRate",
+        "Describe": "波特率",
+        "ParamType": "Int32",
+        "EnumArray": null,
+        "ObjArray": null
+    },
+    {
+        "Name": "ParityBit",
+        "Describe": "校验位",
+        "ParamType": "Enum",
+        "EnumArray": [
             {
-                "Name": "Ip",
-                "Describe": "IP",
-                "ParamType": "String",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 0,
+                "Name": "None",
+                "Describe": ""
             },
             {
-                "Name": "Port",
-                "Describe": "端口",
-                "ParamType": "Int32",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 1,
+                "Name": "Odd",
+                "Describe": ""
             },
             {
-                "Name": "ConnectTimeOut",
-                "Describe": "连接超时时间",
-                "ParamType": "Int32",
-                "EnumArray": null,
-                "ObjArray": null
-            }
-        ]
-    },
-    {
-        "Name": "UdpParam",
-        "Describe": "UDP参数",
-        "ParamType": "UdpParam",
-        "EnumArray": null,
-        "ObjArray": [
+                "Value": 2,
+                "Name": "Even",
+                "Describe": ""
+            },
             {
-                "Name": "Ip",
-                "Describe": "IP",
-                "ParamType": "String",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 3,
+                "Name": "Mark",
+                "Describe": ""
             },
             {
-                "Name": "Port",
-                "Describe": "端口",
-                "ParamType": "Int32",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 4,
+                "Name": "Space",
+                "Describe": ""
             }
-        ]
+        ],
+        "ObjArray": null
     },
     {
-        "Name": "SerialPortParam",
-        "Describe": "串口参数",
-        "ParamType": "SerialPortParam",
+        "Name": "DataBit",
+        "Describe": "数据位",
+        "ParamType": "Int32",
         "EnumArray": null,
-        "ObjArray": [
-            {
-                "Name": "PortName",
-                "Describe": "串口号",
-                "ParamType": "String",
-                "EnumArray": null,
-                "ObjArray": null
-            },
+        "ObjArray": null
+    },
+    {
+        "Name": "StopBit",
+        "Describe": "停止位",
+        "ParamType": "Enum",
+        "EnumArray": [
             {
-                "Name": "BaudRate",
-                "Describe": "波特率",
-                "ParamType": "Int32",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 0,
+                "Name": "None",
+                "Describe": ""
             },
             {
-                "Name": "ParityBit",
-                "Describe": "校验位",
-                "ParamType": "Enum",
-                "EnumArray": [
-                    {
-                        "Value": 0,
-                        "Name": "None",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 1,
-                        "Name": "Odd",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 2,
-                        "Name": "Even",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 3,
-                        "Name": "Mark",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 4,
-                        "Name": "Space",
-                        "Describe": ""
-                    }
-                ],
-                "ObjArray": null
+                "Value": 1,
+                "Name": "One",
+                "Describe": ""
             },
             {
-                "Name": "DataBit",
-                "Describe": "数据位",
-                "ParamType": "Int32",
-                "EnumArray": null,
-                "ObjArray": null
+                "Value": 2,
+                "Name": "Two",
+                "Describe": ""
             },
             {
-                "Name": "StopBit",
-                "Describe": "停止位",
-                "ParamType": "Enum",
-                "EnumArray": [
-                    {
-                        "Value": 0,
-                        "Name": "None",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 1,
-                        "Name": "One",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 2,
-                        "Name": "Two",
-                        "Describe": ""
-                    },
-                    {
-                        "Value": 3,
-                        "Name": "OnePointFive",
-                        "Describe": ""
-                    }
-                ],
-                "ObjArray": null
+                "Value": 3,
+                "Name": "OnePointFive",
+                "Describe": ""
             }
-        ]
+        ],
+        "ObjArray": null
     },
     {
         "Name": "SleepTime",

+ 56 - 196
src/YSAI.DAQ/YSAI.Modbus/client/ModbusClientData.cs

@@ -5,6 +5,7 @@ using System.ComponentModel;
 using System.IO.Ports;
 using YSAI.Core.data;
 using YSAI.Core.subscription;
+using static YSAI.Modbus.client.ModbusClientData;
 
 namespace YSAI.Modbus.client
 {
@@ -200,175 +201,12 @@ namespace YSAI.Modbus.client
             [Description("UdpParam")]
             Udp
         }
-        /// <summary>
-        /// TCP 连接参数
-        /// </summary>
-        public class TcpParam
-        {
-            /// <summary>
-            /// IP
-            /// </summary>
-            [Description("IP")]
-            public string? Ip { get; set; } = "127.0.0.1";
-            /// <summary>
-            /// 端口
-            /// </summary>
-            [Description("端口")]
-            public int Port { get; set; } = 502;
-            /// <summary>
-            /// 连接超时时间
-            /// </summary>
-            [Description("连接超时时间")]
-            public int ConnectTimeOut { get; set; } = 5000;
-
-            /// <summary>
-            /// 重写基类中的Equals方法
-            /// </summary>
-            /// <param name="obj"></param>
-            /// <returns></returns>
-            public override bool Equals(object obj)
-            {
-                if (obj == null)
-                {
-                    return false;
-                }
-                TcpParam? Obj = obj as TcpParam;
-                if (Obj == null)
-                {
-                    return false;
-                }
-                else
-                {
-                    if (Ip == Obj.Ip &&
-                    Port == Obj.Port &&
-                    ConnectTimeOut == Obj.ConnectTimeOut)
-                    {
-                        return true;
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-            }
-        }
-        /// <summary>
-        /// UDP 连接参数
-        /// </summary>
-        public class UdpParam
-        {
-            /// <summary>
-            /// IP
-            /// </summary>
-            [Description("IP")]
-            public string? Ip { get; set; } = "127.0.0.1";
-            /// <summary>
-            /// 端口
-            /// </summary>
-            [Description("端口")]
-            public int Port { get; set; } = 502;
-
-            /// <summary>
-            /// 重写基类中的Equals方法
-            /// </summary>
-            /// <param name="obj"></param>
-            /// <returns></returns>
-            public override bool Equals(object obj)
-            {
-                if (obj == null)
-                {
-                    return false;
-                }
-                UdpParam? Obj = obj as UdpParam;
-                if (Obj == null)
-                {
-                    return false;
-                }
-                else
-                {
-                    if (Ip == Obj.Ip &&
-                    Port == Obj.Port)
-                    {
-                        return true;
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-            }
-        }
-        /// <summary>
-        /// RTU 连接参数
-        /// </summary>
-        public class SerialPortParam
-        {
-            /// <summary>
-            /// 串口号
-            /// </summary>
-            [Description("串口号")]
-            public string? PortName { get; set; }
-            /// <summary>
-            /// 波特率
-            /// </summary>
-            [Description("波特率")]
-            public int BaudRate { get; set; } = 19200;
-            /// <summary>
-            /// 校验位
-            /// </summary>
-            [Description("校验位")]
-            [JsonConverter(typeof(StringEnumConverter))]
-            public Parity ParityBit { get; set; } = Parity.Even;
-            /// <summary>
-            /// 数据位
-            /// </summary>
-            [Description("数据位")]
-            public int DataBit { get; set; } = 8;
-            /// <summary>
-            /// 停止位
-            /// </summary>
-            [Description("停止位")]
-            [JsonConverter(typeof(StringEnumConverter))]
-            public StopBits StopBit { get; set; } = StopBits.One;
 
-            /// <summary>
-            /// 重写基类中的Equals方法
-            /// </summary>
-            /// <param name="obj"></param>
-            /// <returns></returns>
-            public override bool Equals(object obj)
-            {
-                if (obj == null)
-                {
-                    return false;
-                }
-                SerialPortParam? Obj = obj as SerialPortParam;
-                if (Obj == null)
-                {
-                    return false;
-                }
-                else
-                {
-                    if (PortName == Obj.PortName &&
-                    BaudRate == Obj.BaudRate &&
-                    ParityBit == Obj.ParityBit &&
-                    DataBit == Obj.DataBit &&
-                    StopBit == Obj.StopBit)
-                    {
-                        return true;
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-            }
-        }
 
         /// <summary>
         /// 基础数据
         /// </summary>
-        public class Basics: SubscribeData.SCData
+        public class Basics : SubscribeData.SCData
         {
             /// <summary>
             /// 唯一标识符
@@ -412,23 +250,52 @@ namespace YSAI.Modbus.client
             [Description("写入超时时间")]
             public int WriteTimeOut { get; set; } = 2000;
 
+
             /// <summary>
-            /// TCP参数
+            /// IP
             /// </summary>
-            [Description("TCP参数")]
-            public TcpParam? TcpParam { get; set; }
-
+            [Description("IP")]
+            public string? Ip { get; set; } = "127.0.0.1";
             /// <summary>
-            /// UDP参数
+            /// 端口
+            /// </summary>
+            [Description("端口")]
+            public int Port { get; set; } = 502;
+            /// <summary>
+            /// 连接超时时间
             /// </summary>
-            [Description("UDP参数")]
-            public UdpParam? UdpParam { get; set; }
+            [Description("连接超时时间")]
+            public int ConnectTimeOut { get; set; } = 5000;
+
 
             /// <summary>
-            /// 串口参数
+            /// 串口号
+            /// </summary>
+            [Description("串口号")]
+            public string? PortName { get; set; }
+            /// <summary>
+            /// 波特率
             /// </summary>
-            [Description("串口参数")]
-            public SerialPortParam? SerialPortParam { get; set; }
+            [Description("波特率")]
+            public int BaudRate { get; set; } = 19200;
+            /// <summary>
+            /// 校验位
+            /// </summary>
+            [Description("校验位")]
+            [JsonConverter(typeof(StringEnumConverter))]
+            public Parity ParityBit { get; set; } = Parity.Even;
+            /// <summary>
+            /// 数据位
+            /// </summary>
+            [Description("数据位")]
+            public int DataBit { get; set; } = 8;
+            /// <summary>
+            /// 停止位
+            /// </summary>
+            [Description("停止位")]
+            [JsonConverter(typeof(StringEnumConverter))]
+            public StopBits StopBit { get; set; } = StopBits.One;
+
 
             /// <summary>
             /// 重写基类中的Equals方法
@@ -448,28 +315,22 @@ namespace YSAI.Modbus.client
                 }
                 else
                 {
-                    if (SleepTime == Obj.SleepTime &&
-                        SameDataOut == Obj.SameDataOut &&
-                        DataChangeOut == Obj.DataChangeOut &&
-                        ProtocolType == Obj.ProtocolType &&
-                        ReadTimeOut == Obj.ReadTimeOut &&
-                        WriteTimeOut == Obj.WriteTimeOut)
+                    if (PortName == Obj.PortName &&
+                    BaudRate == Obj.BaudRate &&
+                    ParityBit == Obj.ParityBit &&
+                    DataBit == Obj.DataBit &&
+                    StopBit == Obj.StopBit &&
+                    Ip == Obj.Ip &&
+                    Port == Obj.Port &&
+                    ConnectTimeOut == Obj.ConnectTimeOut &&
+                    SleepTime == Obj.SleepTime &&
+                    SameDataOut == Obj.SameDataOut &&
+                    DataChangeOut == Obj.DataChangeOut &&
+                    ProtocolType == Obj.ProtocolType &&
+                    ReadTimeOut == Obj.ReadTimeOut &&
+                    WriteTimeOut == Obj.WriteTimeOut)
                     {
-                        bool State = false;
-                        switch (ProtocolType)
-                        {
-                            case ProtocolType.Ascii:
-                            case ProtocolType.Rtu:
-                                State = SerialPortParam.Equals(Obj.SerialPortParam);
-                                break;
-                            case ProtocolType.Tcp:
-                                State = TcpParam.Equals(Obj.TcpParam);
-                                break;
-                            case ProtocolType.Udp:
-                                State = UdpParam.Equals(Obj.UdpParam);
-                                break;
-                        }
-                        return State;
+                        return true;
                     }
                     else
                     {
@@ -477,7 +338,6 @@ namespace YSAI.Modbus.client
                     }
                 }
             }
-
         }
 
         /// <summary>

+ 11 - 11
src/YSAI.DAQ/YSAI.Modbus/client/ModbusClientOperate.cs

@@ -215,17 +215,17 @@ namespace YSAI.Modbus.client
                     case ModbusClientData.ProtocolType.Rtu:
                     case ModbusClientData.ProtocolType.Ascii:
 
-                        if (string.IsNullOrWhiteSpace(basics.SerialPortParam.PortName))
+                        if (string.IsNullOrWhiteSpace(basics.PortName))
                         {
                             return Break("On", false, $"串口号不能为空");
                         }
-                        if (basics.SerialPortParam.BaudRate <= 0)
+                        if (basics.BaudRate <= 0)
                         {
                             return Break("On", false, $"波特率输入有误");
                         }
 
                         //创建串口对象
-                        SerialPort serialPort = new SerialPort(basics.SerialPortParam.PortName, basics.SerialPortParam.BaudRate, basics.SerialPortParam.ParityBit, basics.SerialPortParam.DataBit, basics.SerialPortParam.StopBit)
+                        SerialPort serialPort = new SerialPort(basics.PortName, basics.BaudRate, basics.ParityBit, basics.DataBit, basics.StopBit)
                         {
                             ReadTimeout = basics.ReadTimeOut,
                             WriteTimeout = basics.WriteTimeOut
@@ -249,15 +249,15 @@ namespace YSAI.Modbus.client
                         }
                         break;
                     case ModbusClientData.ProtocolType.Tcp:
-                        if (string.IsNullOrWhiteSpace(basics.TcpParam.Ip))
+                        if (string.IsNullOrWhiteSpace(basics.Ip))
                         {
                             return Break("On", false, $"IP不能为空");
                         }
-                        if (basics.TcpParam.Port <= 0)
+                        if (basics.Port <= 0)
                         {
                             return Break("On", false, $"端口输入有误");
                         }
-                        if (basics.TcpParam.ConnectTimeOut <= 0)
+                        if (basics.ConnectTimeOut <= 0)
                         {
                             return Break("On", false, $"连接超时时间输入有误");
                         }
@@ -268,20 +268,20 @@ namespace YSAI.Modbus.client
                             SendTimeout = basics.WriteTimeOut
                         };
                         //连接
-                        if (!tcpClient.ConnectAsync(basics.TcpParam.Ip, basics.TcpParam.Port).Wait(basics.TcpParam.ConnectTimeOut))
+                        if (!tcpClient.ConnectAsync(basics.Ip, basics.Port).Wait(basics.ConnectTimeOut))
                         {
                             tcpClient.Dispose();
-                            return Break("On", false, $"连接{basics.TcpParam.Ip}:{basics.TcpParam.Port}超时");
+                            return Break("On", false, $"连接{basics.Ip}:{basics.Port}超时");
                         }
                         //创建对象
                         modbusMaster = modbusFactory.CreateMaster(tcpClient);
                         break;
                     case ModbusClientData.ProtocolType.Udp:
-                        if (string.IsNullOrWhiteSpace(basics.UdpParam.Ip))
+                        if (string.IsNullOrWhiteSpace(basics.Ip))
                         {
                             return Break("On", false, $"IP不能为空");
                         }
-                        if (basics.UdpParam.Port <= 0)
+                        if (basics.Port <= 0)
                         {
                             return Break("On", false, $"端口输入有误");
                         }
@@ -290,7 +290,7 @@ namespace YSAI.Modbus.client
                         udpClient.Client.ReceiveTimeout = basics.ReadTimeOut;
                         udpClient.Client.SendTimeout = basics.WriteTimeOut;
                         //连接
-                        udpClient.Connect(basics.UdpParam.Ip, basics.UdpParam.Port);
+                        udpClient.Connect(basics.Ip, basics.Port);
                         //创建对象
                         modbusMaster = modbusFactory.CreateMaster(udpClient);
                         break;