WIN-GH9CEESPLTB\Administrator 1 месяц назад
Родитель
Сommit
5039fbe703

+ 51 - 45
MainForm/ClassFile/ProjectClass/GlobalContext.cs

@@ -62,32 +62,33 @@ namespace MainForm
         public static string S2_work_station;   // [S2] ⼯站
         public static string S2_device_code;    // [S2] 装备编码
         public static string S2_station;        // [S2] ⼯位Id
-        public static string S3_work_station;   // [S3] ⼯站
-        public static string S3_device_code;    // [S3] 装备编码
-        public static string S3_station;        // [S3] ⼯位Id
-        public static string S4_1_work_station; // [S4_1] ⼯站
-        public static string S4_1_device_code;  // [S4_1] 装备编码
-        public static string S4_1_station;      // [S4_1] ⼯位Id
-        public static string S4_3_work_station; // [S4_3] ⼯站
-        public static string S4_3_device_code;  // [S4_3] 装备编码
-        public static string S4_3_station;      // [S4_3] ⼯位Id
-        public static string S4_4_work_station; // [S4_4] ⼯站
-        public static string S4_4_device_code;  // [S4_4] 装备编码
-        public static string S4_4_station;      // [S4_4] ⼯位Id
-        public static string S4_5_work_station; // [S4_5] ⼯站
-        public static string S4_5_device_code;  // [S4_5] 装备编码
-        public static string S4_5_station;      // [S4_5] ⼯位Id
-        public static string S5_work_station;   // [S5] ⼯站
-        public static string S5_device_code;    // [S5] 装备编码
-        public static string S5_station;        // [S5] ⼯位Id
-        public static string S6_device_code;    // [S5] 装备编码
-        public static string S6_station;        // [S5] ⼯位Id
-        public static string S7_device_code;    // [S5] 装备编码
-        public static string S7_station;        // [S5] ⼯位Id
-        public static string S8_device_code;    // [S5] 装备编码
-        public static string S8_station;        // [S5] ⼯位Id
-        public static string S9_device_code;    // [S5] 装备编码
-        public static string S9_station;        // [S5] ⼯位Id
+        public static string s3_1_work_station;   // [S3] ⼯站
+        public static string s3_1_device_code;    // [S3] 装备编码
+        public static string s3_1_station;        // [S3] ⼯位Id
+        public static string s3_2_work_station; // [S4_1] ⼯站
+        public static string s3_2_device_code;  // [S4_1] 装备编码
+        public static string s3_2_station;      // [S4_1] ⼯位Id
+        public static string s4_work_station; // [S4_3] ⼯站
+        public static string s4_device_code;  // [S4_3] 装备编码
+        public static string s4_station;      // [S4_3] ⼯位Id
+        public static string s5_work_station; // [S4_4] ⼯站
+        public static string s5_device_code;  // [S4_4] 装备编码
+        public static string s5_station;      // [S4_4] ⼯位Id
+        public static string s6_work_station; // [S4_5] ⼯站
+        public static string s6_device_code;  // [S4_5] 装备编码
+        public static string s6_station;      // [S4_5] ⼯位Id
+        public static string s7_1_work_station;   // [S5] ⼯站
+        public static string s7_1_device_code;    // [S5] 装备编码
+        public static string s7_1_station;        // [S5] ⼯位Id
+        public static string s7_2_work_station;    // [S5] 装备编码
+        public static string s7_2_device_code;        // [S5] ⼯位Id
+        public static string s7_2_station;    // [S5] 装备编码
+        public static string s8_work_station;        // [S5] ⼯位Id
+        public static string s8_device_code;    // [S5] 装备编码
+        public static string s8_station;        // [S5] ⼯位Id
+        public static string s9_work_station;    // [S5] 装备编码
+        public static string s9_device_code;        // [S5] ⼯位Id
+        public static string s9_station;        // [S5] ⼯位Id
 
         // 设备
         //public static string PCAddress="192.168.1.244";
@@ -290,25 +291,30 @@ namespace MainForm
                 S2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_work_station", "");  // [S2] ⼯站
                 S2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s2_device_code", "");    // [S2] 装备编码
                 S2_station = IniFile.INIGetStringValue(FilePath, "Station", "s2_station", "");            // [S2] ⼯位Id
-                S3_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_work_station", "");  // [S3] ⼯站
-                S3_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s3_device_code", "");    // [S3] 装备编码
-                S3_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_station", "");            // [S3] ⼯位Id
-                S4_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_work_station", "");  // [S4_1] ⼯站
-                S4_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_device_code", "");    // [S4_1] 装备编码
-                S4_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_1_station", "");            // [S4_1] ⼯位Id
-                S4_3_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_work_station", "");  // [S4_3] ⼯站
-                S4_3_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_device_code", "");    // [S4_3] 装备编码
-                S4_3_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_3_station", "");            // [S4_3] ⼯位Id
-                S4_4_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_work_station", "");  // [S4_4] ⼯站
-                S4_4_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_device_code", "");    // [S4_4] 装备编码
-                S4_4_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_4_station", "");            // [S4_4] ⼯位Id
-                S4_5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_work_station", "");  // [S4_5] ⼯站
-                S4_5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_device_code", "");    // [S4_5] 装备编码
-                S4_5_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_5_station", "");            // [S4_5] ⼯位Id
-                S5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", "");  // [S5] ⼯站
-                S5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", "");    // [S5] 装备编码
-                S5_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", "");            // [S5] ⼯位Id
-
+                s3_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_work_station", "");  // [S3] ⼯站
+                s3_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_device_code", "");    // [S3] 装备编码
+                s3_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s3_1_station", "");            // [S3] ⼯位Id
+                s4_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_work_station", "");  // [S4_1] ⼯站
+                s4_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_device_code", "");    // [S4_1] 装备编码
+                s4_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_station", "");            // [S4_1] ⼯位Id
+                s4_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_work_station", "");  // [S4_3] ⼯站
+                s4_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s4_device_code", "");    // [S4_3] 装备编码
+                s4_station = IniFile.INIGetStringValue(FilePath, "Station", "s4_station", "");            // [S4_3] ⼯位Id
+                s5_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_work_station", "");  // [S4_4] ⼯站
+                s5_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s5_device_code", "");    // [S4_4] 装备编码
+                s5_station = IniFile.INIGetStringValue(FilePath, "Station", "s5_station", "");            // [S4_4] ⼯位Id
+                s6_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s6_work_station", "");  // [S4_5] ⼯站
+                s6_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s6_device_code", "");    // [S4_5] 装备编码
+                s6_station = IniFile.INIGetStringValue(FilePath, "Station", "s6_station", "");            // [S4_5] ⼯位Id
+                s7_1_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_work_station", "");  // [S5] ⼯站
+                s7_1_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_device_code", "");    // [S5] 装备编码
+                s7_1_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_1_station", "");            // [S5] ⼯位Id
+                s7_2_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_work_station", "");  // [S4_5] ⼯站
+                s7_2_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_device_code", "");    // [S4_5] 装备编码
+                s7_2_station = IniFile.INIGetStringValue(FilePath, "Station", "s7_2_station", "");            // [S4_5] ⼯位Id
+                s8_work_station = IniFile.INIGetStringValue(FilePath, "Station", "s8_work_station", "");  // [S4_5] ⼯站
+                s8_device_code = IniFile.INIGetStringValue(FilePath, "Station", "s8_device_code", "");    // [S4_5] 装备编码
+                s8_station = IniFile.INIGetStringValue(FilePath, "Station", "s8_station", "");            // [S4_5] ⼯位Id
                 // 设备
                 IsUsePLC1 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC1", "false"));
                 IsUsePLC2 = bool.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "IsUsePLC2", "false"));

+ 9 - 1
MainForm/ClassFile/XiaomiAPI_IOT/Extend/XiaomiMqttClient_DeviceStateData.cs

@@ -92,5 +92,13 @@ namespace MainForm.ClassFile.XiaomiAPI
             /// </summary>
             public string fault_tm { get; set; } = string.Empty;
         }
+        /// <summary>
+        /// 包含左右工位的设备
+        /// </summary>
+        public struct DeviceStateDataRequest2Station
+        {
+            public DeviceStateDataRequest left;
+            public DeviceStateDataRequest right;
+        }
     }
-}
+ }

+ 18 - 14
MainForm/ClassFile/XiaomiAPI_IOT/XiaomiDeviceState.cs

@@ -7,32 +7,36 @@ namespace MainForm.ClassFile.XiaomiAPI
     public enum XiaomiDeviceState
     {
         /// <summary>
-        /// 未初始化状态(未初始状态,需先初始化装备才能运行)
+        /// 0未知状态
         /// </summary>
-        Uninitialized,
+        Unknown = 0,
         /// <summary>
-        /// 初始化状态(初始化进行中
+        /// 1未初始化状态(未初始状态,需先初始化装备才能运行
         /// </summary>
-        Initializing,
+        Uninitialized = 1,
         /// <summary>
-        /// 初始化完成状态(初始化完成
+        /// 2初始化状态(初始化进行中
         /// </summary>
-        Initialized,
+        Initializing = 2,
         /// <summary>
-        /// 运行状态(正常运行中
+        /// 3初始化完成状态(初始化完成
         /// </summary>
-        Running,
+        Initialized = 3,
         /// <summary>
-        /// 暂停状态(设备运行中人工操作暂停,进入此状态
+        /// 4运行状态(正常运行中
         /// </summary>
-        Paused,
+        Running = 4,
         /// <summary>
-        /// 故障状态(发生故障后进入此状态,同时停止运行
+        /// 5暂停状态(设备运行中人工操作暂停,进入此状态
         /// </summary>
-        Fault,
+        Paused = 5,
         /// <summary>
-        /// 警报状态(产生报警后进入此状态,同时停止运行)
+        /// 6故障状态(发生故障后进入此状态,同时停止运行)
         /// </summary>
-        Alarm,
+        Fault = 6,
+        /// <summary>
+        /// 7警报状态(产生报警后进入此状态,同时停止运行)
+        /// </summary>
+        Alarm = 7,
     }
 }

+ 16 - 4
MainForm/ClassFile/XiaomiAPI_IOT/XiaomiMqttLoginParam.cs

@@ -22,6 +22,18 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// 方法参数
         /// </summary>
         public XiaomiMqttLoginParam parameter { get; set; } = new XiaomiMqttLoginParam();
+
+    }
+
+    /// <summary>
+    /// 小米登录用 方法与参数
+    /// 设置参数函数
+    /// </summary>
+    public class XiaomiMqttLoginFunAndParam2Station
+    {
+        public XiaomiMqttLoginFunAndParam left;
+        public XiaomiMqttLoginFunAndParam right;
+
     }
 
     /// <summary>
@@ -51,10 +63,10 @@ namespace MainForm.ClassFile.XiaomiAPI
         public XmMqttLoginParamOther other { get; set; } = new XmMqttLoginParamOther();
     }
 
-    /// <summary>
-    /// 小米登录用 参数 - fds配置
-    /// </summary>
-    public class XmMqttLoginParamFds
+        /// <summary>
+        /// 小米登录用 参数 - fds配置
+        /// </summary>
+        public class XmMqttLoginParamFds
     {
         /// <summary>
         /// fds地址

+ 28 - 28
MainForm/FaForm/Form_Home.Designer.cs

@@ -36,6 +36,8 @@
             System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
             this.panel1 = new System.Windows.Forms.Panel();
             this.groupBox3 = new System.Windows.Forms.GroupBox();
+            this.lblDeviceStates = new Sunny.UI.UILabel();
+            this.uiLabel2 = new Sunny.UI.UILabel();
             this.txt_CurSupplierCode = new System.Windows.Forms.TextBox();
             this.label20 = new System.Windows.Forms.Label();
             this.currentMtltmrk = new System.Windows.Forms.TextBox();
@@ -77,8 +79,6 @@
             this.colTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.colMessage = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.imageListState = new System.Windows.Forms.ImageList(this.components);
-            this.uiLabel2 = new Sunny.UI.UILabel();
-            this.lblDeviceStates = new Sunny.UI.UILabel();
             this.panel1.SuspendLayout();
             this.groupBox3.SuspendLayout();
             this.panel2.SuspendLayout();
@@ -143,6 +143,32 @@
             this.groupBox3.TabStop = false;
             this.groupBox3.Text = "当前加工订单信息";
             // 
+            // lblDeviceStates
+            // 
+            this.lblDeviceStates.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.lblDeviceStates.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.lblDeviceStates.ForeColor = System.Drawing.Color.Blue;
+            this.lblDeviceStates.Location = new System.Drawing.Point(1134, 48);
+            this.lblDeviceStates.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.lblDeviceStates.Name = "lblDeviceStates";
+            this.lblDeviceStates.Size = new System.Drawing.Size(261, 50);
+            this.lblDeviceStates.TabIndex = 97;
+            this.lblDeviceStates.Text = "未初始状态";
+            this.lblDeviceStates.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // uiLabel2
+            // 
+            this.uiLabel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.uiLabel2.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.uiLabel2.ForeColor = System.Drawing.SystemColors.InfoText;
+            this.uiLabel2.Location = new System.Drawing.Point(976, 48);
+            this.uiLabel2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.uiLabel2.Name = "uiLabel2";
+            this.uiLabel2.Size = new System.Drawing.Size(177, 50);
+            this.uiLabel2.TabIndex = 96;
+            this.uiLabel2.Text = "设备状态:";
+            this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
             // txt_CurSupplierCode
             // 
             this.txt_CurSupplierCode.Enabled = false;
@@ -647,32 +673,6 @@
             this.imageListState.Images.SetKeyName(1, "light_green.png");
             this.imageListState.Images.SetKeyName(2, "light_red.png");
             // 
-            // uiLabel2
-            // 
-            this.uiLabel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.uiLabel2.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.uiLabel2.ForeColor = System.Drawing.SystemColors.InfoText;
-            this.uiLabel2.Location = new System.Drawing.Point(1093, 48);
-            this.uiLabel2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.uiLabel2.Name = "uiLabel2";
-            this.uiLabel2.Size = new System.Drawing.Size(177, 50);
-            this.uiLabel2.TabIndex = 96;
-            this.uiLabel2.Text = "设备状态:";
-            this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-            // 
-            // lblDeviceStates
-            // 
-            this.lblDeviceStates.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.lblDeviceStates.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblDeviceStates.ForeColor = System.Drawing.Color.Blue;
-            this.lblDeviceStates.Location = new System.Drawing.Point(1249, 48);
-            this.lblDeviceStates.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.lblDeviceStates.Name = "lblDeviceStates";
-            this.lblDeviceStates.Size = new System.Drawing.Size(261, 50);
-            this.lblDeviceStates.TabIndex = 97;
-            this.lblDeviceStates.Text = "未初始状态";
-            this.lblDeviceStates.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-            // 
             // Form_Home
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);

+ 111 - 40
MainForm/FaForm/Form_Home.cs

@@ -300,6 +300,7 @@ namespace MainForm
                             //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
                             // 配置参数
                             XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
+                            XiaomiMqttLoginFunAndParam2Station param2 = new XiaomiMqttLoginFunAndParam2Station();
                             // fds
                             param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
                             param.parameter.fds.appId = "Auto-Soft";
@@ -327,38 +328,42 @@ namespace MainForm
                             }
                             if (GlobalContext.IsUsePLC3)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S3_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S3_station;     // ⼯位Id
+                                param2.left.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code;  // 装备编码
+                                param2.left.parameter.equipment.stationCode = GlobalContext.s3_1_station;     // ⼯位Id
+                                param2.right.parameter.equipment.deviceCode = GlobalContext.s3_2_device_code;  // 装备编码
+                                param2.right.parameter.equipment.stationCode = GlobalContext.s3_2_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC4)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S4_1_station;     // ⼯位Id
+                                param.parameter.equipment.deviceCode = GlobalContext.s4_device_code;  // 装备编码
+                                param.parameter.equipment.stationCode = GlobalContext.s4_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC5)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S5_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S5_station;     // ⼯位Id
+                                param.parameter.equipment.deviceCode = GlobalContext.s5_device_code;  // 装备编码
+                                param.parameter.equipment.stationCode = GlobalContext.s5_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC6)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S6_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S6_station;     // ⼯位Id
+                                param.parameter.equipment.deviceCode = GlobalContext.s6_device_code;  // 装备编码
+                                param.parameter.equipment.stationCode = GlobalContext.s6_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC7)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S7_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S7_station;     // ⼯位Id
+                                param2.left.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code;  // 装备编码
+                                param2.left.parameter.equipment.stationCode = GlobalContext.s7_1_station;     // ⼯位Id
+                                param2.right.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code;  // 装备编码
+                                param2.right.parameter.equipment.stationCode = GlobalContext.s7_1_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC8)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S8_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S8_station;     // ⼯位Id
+                                param.parameter.equipment.deviceCode = GlobalContext.s8_device_code;  // 装备编码
+                                param.parameter.equipment.stationCode = GlobalContext.s8_station;     // ⼯位Id
                             }
                             if (GlobalContext.IsUsePLC9)
                             {
-                                param.parameter.equipment.deviceCode = GlobalContext.S9_device_code;  // 装备编码
-                                param.parameter.equipment.stationCode = GlobalContext.S9_station;     // ⼯位Id
+                                param.parameter.equipment.deviceCode = GlobalContext.s9_device_code;  // 装备编码
+                                param.parameter.equipment.stationCode = GlobalContext.s9_station;     // ⼯位Id
                             }
 
                             param.parameter.equipment.project = GlobalContext.Project_Code;
@@ -1819,7 +1824,6 @@ namespace MainForm
             }
         }
 
-
         #endregion
 
         #region S1
@@ -1837,6 +1841,16 @@ namespace MainForm
             string tagAgvCommName = "agvCommFrmPC";
             string tagBarsetName = "BarcodeSet";
 
+            // 触发信号字典
+            //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0);             // PLC_FLAG 节拍接口
+            s1PLCSignal_Old.Add("a1OEEType", 0);          // 节拍类型(plc写入) 
+
+            // PLC数据字典 赋值 
+            //s1PLCData.Add("a1OEEPLC_FLAG", 0);      // PLC_FLAG 节拍接口
+            s1PLCData.Add("a1OEEType", 0);          // 节拍类型(plc写入) 
+            s1PLCData.Add("a1OEEPartNo", "");       // 物料码(物料码还未绑定载具SN时必填)
+            s1PLCData.Add("a1OEEVehicleCode", "");  // 载具SN
+
             OP10_MesData_t stPLC_MesData;        //PLC的MES数据
             (int, string) result;
 
@@ -1866,6 +1880,14 @@ namespace MainForm
                         else
                         {
                             //richTextBox1.AppendText("\n" + "读取成功");
+                            //设备状态
+                            int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
+                            xmDeviceState = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7) ? XiaomiDeviceState.Unknown : (XiaomiDeviceState)xmDeviceStateInt;
+
+                            s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode;  // 物料码(物料码还未绑定载具SN时必填)
+                            s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具SN
+                            s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;  // 节拍
+
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -1917,6 +1939,26 @@ namespace MainForm
                         #endregion 进站
 
 
+                        #region 节拍接口
+                        try
+                        {
+                            int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEType"];
+                            int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEType"];
+                            if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
+                            {
+                                if (a1OEEPLC_FLAG == 1)
+                                    Task.Run(() => S1节拍接口(plcNo, stationNameStr, tagBaseName, stPLC_MesData));  // MreTasks[4].Set();
+
+                                s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            string str = ex.StackTrace;
+                            AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
+                        }
+                        #endregion
+
                         UpdatePLCMonitor(1, plcNo, 1);  // 更新PLC状态的UI  // 更新PLC状态的UI
 
                         stopwatch1.Stop();
@@ -1960,6 +2002,7 @@ namespace MainForm
                 string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码;
                 string MachineId = GlobalContext.S1_MachineId;  // 装备ID(可配置)
                 string StationId = GlobalContext.S1_StationId;  // 工位ID(可配置)
+
                 if (string.IsNullOrEmpty(sn))
                 {
                     ProgressState = false;
@@ -5502,10 +5545,11 @@ namespace MainForm
         /// </summary>
         /// <param name="plcNo">PLC编号</param>
         /// <param name="stationNameStr">工站全称</param>
-        private void S1节拍接口(int plcNo, string stationNameStr)
+        private void S1节拍接口(int plcNo, string stationNameStr,string tagMesCommName, OP10_MesData_t stPLC_MesData)
         {
             Stopwatch stopwatch1 = new Stopwatch();
             Stopwatch stopwatch2 = new Stopwatch();
+            IoT_DataSet_t iot_data;
 
             string resultStr = string.Empty;
             try
@@ -5516,42 +5560,71 @@ namespace MainForm
                 a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
                 string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"];    // 载具SN
                 a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
-                string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString();  // 穴位号
-                a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
+                //string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString();  // 穴位号
+                //a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
 
                 bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
                 if (!actionBool)
                 {
                     stopwatch2.Start();
-                    // MES_Flag
-                    //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1);  // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
-                    WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
-                    writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
-                    writeToPLC_Flag1.Adress = 2254;
-                    writeToPLC_Flag1.Value = (short)1;
-                    SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
+                    //写入PLC
+                    iot_data.machineState = stPLC_MesData.iotData.machineState;
+                    iot_data.work_type = stPLC_MesData.iotData.work_type;
+                    iot_data.testStatus = stPLC_MesData.iotData.testStatus;
+                    iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
+                    iot_data.beatReturn = 2;//NG
+                    iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
+                    WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
+                   
                     stopwatch2.Stop();
                     AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
                     return;
                 }
-
-                if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
+                //作业开始后要有物料和载具信息
+                if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) && Convert.ToInt32(oEEType) > 2)
                 {
                     stopwatch2.Start();
-                    // MES_Flag
-                    //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1);  // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
-                    WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
-                    writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
-                    writeToPLC_Flag2.Adress = 2254;
-                    writeToPLC_Flag2.Value = (short)1;
-                    SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
+                    //写入PLC
+                    iot_data.machineState = stPLC_MesData.iotData.machineState;
+                    iot_data.work_type = stPLC_MesData.iotData.work_type;
+                    iot_data.testStatus = stPLC_MesData.iotData.testStatus;
+                    iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
+                    iot_data.beatReturn = 2;//NG
+                    iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
+                    WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
                     stopwatch2.Stop();
-                    AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
+                    AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
                     return;
                 }
-                else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
-                {  // 查产品SN
-                    a1OEEPartNo = "Test";  // ZS
+                else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
+                {
+                    stopwatch2.Start();
+                    //写入PLC
+                    iot_data.machineState = stPLC_MesData.iotData.machineState;
+                    iot_data.work_type = stPLC_MesData.iotData.work_type;
+                    iot_data.testStatus = stPLC_MesData.iotData.testStatus;
+                    iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
+                    iot_data.beatReturn = 2;//NG
+                    iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
+                    WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
+                    stopwatch2.Stop();
+                    AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
+                    return;
+                }
+                else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
+                {
+                    stopwatch2.Start();
+                    //写入PLC
+                    iot_data.machineState = stPLC_MesData.iotData.machineState;
+                    iot_data.work_type = stPLC_MesData.iotData.work_type;
+                    iot_data.testStatus = stPLC_MesData.iotData.testStatus;
+                    iot_data.BeatAction = stPLC_MesData.iotData.BeatAction;
+                    iot_data.beatReturn = 2;//NG
+                    iot_data.fault_codes = stPLC_MesData.iotData.fault_codes;
+                    WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
+                    stopwatch2.Stop();
+                    AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
+                    return;
                 }
 
                 short a1OEEMES_FLAG = 0;
@@ -5562,8 +5635,6 @@ namespace MainForm
                 resultStr = result.Item2;
 
                 stopwatch2.Start();
-                // MES_Flag
-                //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG);  // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
                 WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
                 writeToPLC_Flag.Name = "a1OEEMES_FLAG";
                 writeToPLC_Flag.Adress = 2254;

+ 1 - 1
MainForm/FaForm/Form_Home.resx

@@ -8367,7 +8367,7 @@
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACQ
-        PgAAAk1TRnQBSQFMAgEBAwEAAcABCAHAAQgBIAEAASABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAGA
+        PgAAAk1TRnQBSQFMAgEBAwEAAcgBCAHIAQgBIAEAASABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAGA
         AwABIAMAAQEBAAEgBgABQP8A/wA8AAP5Af8DzgH/A6gB/wOLAf8DeAH/A3EB/wNxAf8DeAH/A4sB/wOo
         Af8DzwH/A/kB/1AAAfcB+wH3Af8BuwHgAbYB/wGGAcgBfAH/AV0BtQFQAf8BQgGpATMB/wE5AaUBKQH/
         ATkBpQEpAf8BQwGqATQB/wFdAbYBUAH/AYUByAF7Af8BvAHhAbcB/wH3AfsB9wH/UAAB9gH1AfsB/wGw

+ 140 - 90
MainForm/FaForm/Form_Home_SaveData.cs

@@ -13,6 +13,7 @@ using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
 using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
 using System.IO;
 using MainForm.ClassFile.FALibraryClass;
+using NPOI.SS.Formula.Functions;
 
 namespace MainForm
 {
@@ -351,37 +352,37 @@ namespace MainForm
                             passStaResultRequ.device_code = GlobalContext.S2_device_code;    // 装备编码
                             passStaResultRequ.station = GlobalContext.S2_station;            // ⼯位Id
                             break;
-                        case "[S3]值板机":
-                            passStaResultRequ.work_station = GlobalContext.S3_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S3_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S3_station;            // ⼯位Id
-                            break;
-                        case "[S4_1]载具下线装备":
-                            passStaResultRequ.work_station = GlobalContext.S4_1_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S4_1_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S4_1_station;            // ⼯位Id
-                            break;
-                        case "[S4_3]提升机1":
-                            passStaResultRequ.work_station = GlobalContext.S4_3_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S4_3_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S4_3_station;            // ⼯位Id
-                            break;
-                        case "[S4_4]提升机2":
-                            passStaResultRequ.work_station = GlobalContext.S4_4_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S4_4_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S4_4_station;            // ⼯位Id
-                            break;
-                        case "[S4_5]载具上线装备":
-                            passStaResultRequ.work_station = GlobalContext.S4_5_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S4_5_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S4_5_station;            // ⼯位Id
-                            break;
-                        case "[S5]Tray盘下料装备":
-                            passStaResultRequ.work_station = GlobalContext.S5_work_station;  // ⼯站
-                            passStaResultRequ.device_code = GlobalContext.S5_device_code;    // 装备编码
-                            passStaResultRequ.station = GlobalContext.S5_station;            // ⼯位Id
-                            break;
-                        default:
+                        //case "[S3]值板机":
+                        //    passStaResultRequ.work_station = GlobalContext.S3_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S3_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S3_station;            // ⼯位Id
+                        //    break;
+                        //case "[S4_1]载具下线装备":
+                        //    passStaResultRequ.work_station = GlobalContext.S4_1_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S4_1_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S4_1_station;            // ⼯位Id
+                        //    break;
+                        //case "[S4_3]提升机1":
+                        //    passStaResultRequ.work_station = GlobalContext.S4_3_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S4_3_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S4_3_station;            // ⼯位Id
+                        //    break;
+                        //case "[S4_4]提升机2":
+                        //    passStaResultRequ.work_station = GlobalContext.S4_4_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S4_4_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S4_4_station;            // ⼯位Id
+                        //    break;
+                        //case "[S4_5]载具上线装备":
+                        //    passStaResultRequ.work_station = GlobalContext.S4_5_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S4_5_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S4_5_station;            // ⼯位Id
+                        //    break;
+                        //case "[S5]Tray盘下料装备":
+                        //    passStaResultRequ.work_station = GlobalContext.S5_work_station;  // ⼯站
+                        //    passStaResultRequ.device_code = GlobalContext.S5_device_code;    // 装备编码
+                        //    passStaResultRequ.station = GlobalContext.S5_station;            // ⼯位Id
+                        //    break;
+                        //default:
                             break;
                     }
                     passStaResultRequ.process_time = processData.Test_time;  // 过站时间
@@ -721,6 +722,7 @@ namespace MainForm
         /// 记录上次保存 设备状态数据CSV 的时间
         /// </summary>
         private DateTime dtSaveDeviceStateCSV_Old = DateTime.Now.AddMinutes(-5);
+
         /// <summary>
         /// 上传设备状态数据
         /// 上传IOT + 5分钟记录一次数据到txt中
@@ -730,7 +732,6 @@ namespace MainForm
         /// <param name="fault_code">故障编码</param>
         /// <param name="fault_tm">故障发⽣时间</param>
         /// <returns>上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;</returns>
-
         public (int, string) SaveDeviceStateData(string stationNameStr, XiaomiDeviceState deviceState, string fault_code = "A40000", string fault_tm = "")
         {
             int result = 0;
@@ -743,20 +744,28 @@ namespace MainForm
                 if (GlobalContext.IsUseIot && GlobalContext.IsMqttDeviceState)
                 {
                     DeviceStateDataRequest request = new DeviceStateDataRequest();
+                    DeviceStateDataRequest2Station request2 = new DeviceStateDataRequest2Station();
+
                     if (GlobalContext.IsUsePLC1)
                         request.station = GlobalContext.S1_station;    // 工位ID(可配置)
                     if (GlobalContext.IsUsePLC2)
                         request.station = GlobalContext.S2_station;    // 工位ID(可配置)
                     if (GlobalContext.IsUsePLC3)
-                        request.station = GlobalContext.S3_station;    // 工位ID(可配置)
+                        request2.left.station = GlobalContext.s3_1_station;    // 工位ID(可配置)
+                        request2.left.station = GlobalContext.s3_2_station;  // ⼯位ID(可配置)
                     if (GlobalContext.IsUsePLC4)
-                        request.station = GlobalContext.S4_1_station;  // ⼯位ID(可配置)
+                        request.station = GlobalContext.s4_station;    // 工位ID(可配置)
                     if (GlobalContext.IsUsePLC5)
-                        request.station = GlobalContext.S5_station;    // 工位ID(可配置)
+                        request.station = GlobalContext.s5_station;    // 工位ID(可配置)
                     if (GlobalContext.IsUsePLC6)
-                        request.station = GlobalContext.S6_station;    // 工位ID(可配置)
+                        request.station = GlobalContext.s6_station;    // 工位ID(可配置)
                     if (GlobalContext.IsUsePLC7)
-                        request.station = GlobalContext.S7_station;  // ⼯位ID(可配置)
+                        request2.left.station = GlobalContext.s7_1_station;  // ⼯位ID(可配置)
+                        request2.right.station = GlobalContext.s7_2_station;  // ⼯位ID(可配置)
+                    if (GlobalContext.IsUsePLC8)
+                        request.station = GlobalContext.s8_station;  // ⼯位ID(可配置)
+                    if (GlobalContext.IsUsePLC9)
+                        request.station = GlobalContext.s9_station;  // ⼯位ID(可配置)
 
                     request.state = deviceState.ToString();  // 设备状态
                     request.time = dtNow.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 状态切换时的时间 2022-06-01 14:27:57.283
@@ -765,32 +774,27 @@ namespace MainForm
                         request.fault_code = fault_code;  // 对应的故障编码
                         request.fault_tm = fault_tm;      // 故障发⽣时间(需要实际的发生时间)
                     }
-
                     // 上传
-                    (int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
-
-                    result = iotResult.Item1 == 0 ? 1 : 2;
-                    msg = $"[{iotResult.Item1}]{iotResult.Item2}";
-
-                    // 5分钟记录一次数据到txt中
-                    if (dtSaveDeviceStateCSV_Old < dtNow)
+                    if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
                     {
-                        string fileDir = GlobalContext.MqttDeviceStateDir + dtNow.ToString("yyyy_MM");  // 文件夹路径
-                        if (!Directory.Exists(fileDir))
-                            Directory.CreateDirectory(fileDir);
-
-                        string filePath = fileDir + dtNow.ToString("yyyy_MM_dd");                       // 文件路径
+                        (int, string) iotResultL = XiaomiMqttClient_Extend.Write_DeviceStateData(request2.left);
+                        (int, string) iotResultR = XiaomiMqttClient_Extend.Write_DeviceStateData(request2.right);
 
-                        StringBuilder sbData = new StringBuilder();
-                        if (!File.Exists(filePath))
-                            sbData.AppendLine("工位ID,设备状态,状态切换时的时间,故障编码,故障发生时间,上传结果");
+                        if (iotResultL.Item1 == 0 || iotResultR.Item1 == 0)
+                            result = 1;
+                        else 
+                            result = 2;
 
-                        string iotResultMsg = $"[{iotResult.Item1}]{iotResult.Item2}";
-                        sbData.AppendLine($"{request.station},{request.state},{request.time},{request.fault_code},{request.fault_tm},{iotResultMsg}");  // 文件内容
-
-                        // 保存到CSV文件中
-                        string newLineData = sbData.ToString();  // 文件内容
-                        CSVHelper.CSVFile_AddLog(filePath, newLineData);
+                        msg = $"[{iotResultL.Item1}]{iotResultL.Item2};[{iotResultR.Item1}]{iotResultR.Item2}";
+                        SaveDeviceStateDataLog(iotResultL, request, dtNow);
+                        SaveDeviceStateDataLog(iotResultR, request, dtNow);
+                    }
+                    else
+                    {
+                       (int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
+                       result = iotResult.Item1 == 0 ? 1 : 2;
+                       msg = $"[{iotResult.Item1}]{iotResult.Item2}";
+                       SaveDeviceStateDataLog(iotResult, request, dtNow);
                     }
                 }
                 else
@@ -805,6 +809,33 @@ namespace MainForm
             }
             return (result, msg);
         }
+        /// <summary>
+        /// 5分钟记录一次数据到txt中
+        /// </summary>
+        /// <param name="iotResult"></param>
+        /// <param name="request"></param>
+        private void SaveDeviceStateDataLog((int, string) iotResult, DeviceStateDataRequest request,DateTime dtNow) {
+            if (dtSaveDeviceStateCSV_Old < dtNow)
+            {
+                string fileDir = GlobalContext.MqttDeviceStateDir + dtNow.ToString("yyyy_MM");  // 文件夹路径
+                if (!Directory.Exists(fileDir))
+                    Directory.CreateDirectory(fileDir);
+
+                string filePath = fileDir + dtNow.ToString("yyyy_MM_dd");                       // 文件路径
+
+                StringBuilder sbData = new StringBuilder();
+                if (!File.Exists(filePath))
+                    sbData.AppendLine("工位ID,设备状态,状态切换时的时间,故障编码,故障发生时间,上传结果");
+
+                string iotResultMsg = $"[{iotResult.Item1}]{iotResult.Item2}";
+                sbData.AppendLine($"{request.station},{request.state},{request.time},{request.fault_code},{request.fault_tm},{iotResultMsg}");  // 文件内容
+
+                // 保存到CSV文件中
+                string newLineData = sbData.ToString();  // 文件内容
+                CSVHelper.CSVFile_AddLog(filePath, newLineData);
+            }
+        }
+
         #endregion 设备状态数据
 
         #region 报警数据
@@ -834,8 +865,18 @@ namespace MainForm
         /// <summary>
         /// 上传节拍数据
         /// </summary>
-        /// <returns></returns>
-        public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEProductSN)
+        /// <param name="plcNo"></param>
+        /// <param name="stationNameStr"></param>
+        /// <param name="deviceOEE"></param>
+        /// <param name="oEEPartNo"></param>
+        /// <param name="oEEVSN"></param>
+        /// <param name="extra"></param>
+        /// <param name="class_level_1"></param>
+        /// <param name="class_level_2"></param>
+        /// <param name="class_level_3"></param>
+        /// <returns>上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;</returns>
+        public (short, string) SaveOEEData(int plcNo, string stationNameStr, XiaomiDeviceOEE deviceOEE, string oEEPartNo, string oEEVSN, string extra = ""
+            , string class_level_1 = "beat_log", string class_level_2 = "business", string class_level_3 = "OEE")
         {
             // 上传OEE
             if (GlobalContext.IsMqttStationInputBegin)
@@ -848,52 +889,61 @@ namespace MainForm
                         oee.action = deviceOEE.ToString();  // 节拍动作(XiaomiDeviceOEE)
                         oee.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 节拍发⽣时间
                         oee.action_subject = oEEPartNo;            // 该动作操作的⽬标对象(SN) 
-                        oee.action_subject_parent = oEEProductSN;  // ⼤板SN/载具SN
-                        oee.action_location = GlobalContext.S1_station;  // 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
+                        oee.action_subject_parent = oEEVSN;        // ⼤板SN/载具SN
                         switch (stationNameStr)
                         {
-                            case "[S1]Tray盘上料装备":
+                            case "[OP10]壳体清洁上料":
                                 oee.action_location = GlobalContext.S1_station;
                                 break;
-                            case "[S2]FCT":
+                            case "[OP20]上盖板上料装备":
                                 oee.action_location = GlobalContext.S2_station;
                                 break;
-                            case "[S3]值板机":
-                                oee.action_location = GlobalContext.S3_station;
+                            case "[OP30]点散热胶装备_Left":
+                                oee.action_location = GlobalContext.s3_1_station;
+                                break;
+                            case "[OP30]点散热胶装备_Right":
+                                oee.action_location = GlobalContext.s3_2_station;
+                                break;
+                            case "[OP40]胶线检测":
+                                oee.action_location = GlobalContext.s4_station;
+                                break;
+                            case "[OP50]ADD板上料组装装备":
+                                oee.action_location = GlobalContext.s5_station;
                                 break;
-                            case "[S4_1]载具下线装备":
-                                oee.action_location = GlobalContext.S4_1_station;
+                            case "[OP60]组上盖板":
+                                oee.action_location = GlobalContext.s6_station;
                                 break;
-                            case "[S4_3]提升机1":
-                                oee.action_location = GlobalContext.S4_3_station;
+                            case "[OP70]上盖板锁螺丝_Left":
+                                oee.action_location = GlobalContext.s7_1_station;
                                 break;
-                            case "[S4_4]提升机2":
-                                oee.action_location = GlobalContext.S4_4_station;
+                            case "[OP70]上盖板锁螺丝_Right":
+                                oee.action_location = GlobalContext.s7_2_station;
                                 break;
-                            case "[S4_5]载具上线装备":
-                                oee.action_location = GlobalContext.S4_5_station;
+                            case "[OP80]NG下料":
+                                oee.action_location = GlobalContext.s8_station;
                                 break;
-                            case "[S5]Tray盘下料装备":
-                                oee.action_location = GlobalContext.S5_station;
+                            case "[OP90]半成品下料":
+                                oee.action_location = GlobalContext.s8_station;
                                 break;
                         }
-                        oee.action_material = string.Empty;  // 该动作的物料信息
-                        oee.extra = string.Empty;            // 额外信息
-                        oee.class_level_1 = string.Empty;    // 分类层级1
-                        oee.class_level_2 = string.Empty;    // 分类层级2
-                        oee.class_level_3 = string.Empty;    // 分类层级3
-
-                        int result = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
-
-                        string msg = $"[{result}]";
-                        bool errCodeParse = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode);
-                        msg += errCodeParse ? errCode.ToString() : "ERR_UNKOWN";
-                        AddMessage(LogType.Info, stationNameStr + $"_异步上传节拍接口;接口结果:-- {msg}");
+                        oee.action_material = oee.action_location + "_1";  // 该动作的物料信息
+                        oee.extra = extra;                    // 额外信息
+                        oee.class_level_1 = class_level_1;    // 分类层级1
+                        oee.class_level_2 = class_level_2;    // 分类层级2
+                        oee.class_level_3 = class_level_3;    // 分类层级3
+
+                        var iotResult = XiaomiMqttClient_Extend.Write_StationInputBegin(oee);
+                        int result = iotResult.Item1;
+                        string msg = $"[{iotResult.Item1}]{iotResult.Item2}";
+                        if (result == 0)
+                            OnMessage(LogType.Info, stationNameStr + $"_异步上传Iot节拍数据[SN:{oEEPartNo}]成功!iot接口返回结果:{msg}");
+                        else
+                            AddMessage(LogType.Info, stationNameStr + $"_异步上传Iot节拍数据[SN:{oEEPartNo}]失败!iot接口返回结果:{msg}");
                     }
                     catch (Exception ex)
                     {
                         string str = ex.StackTrace;
-                        AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 异步上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
+                        AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr}_[{oEEPartNo}]异步上传Iot节拍数据失败!报错信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
                     }
                 });