Browse Source

数据库跨月bug、三点激光、请求字符串中文转换、上抛装备配置参数

WIN-GH9CEESPLTB\Administrator 3 months ago
parent
commit
cbedfcec20

+ 20 - 17
MainForm/ClassFile/ProjectClass/SQLHelper.cs

@@ -31,7 +31,7 @@ namespace MainForm
         /// SQL连接
         /// </summary>
         private static SqlConnection connection = null;
-
+        public static string dataBaseName = string.Empty;
         public static string connString = "";
 
         public static SqlSugarClient Db
@@ -63,7 +63,7 @@ namespace MainForm
         {
             //以月为单位存
             string subDir = DateTime.Now.ToString("yyyyMM");
-            string dataBaseName = "Db" + subDir;
+            dataBaseName = "Db" + subDir;
             connString =
                 @"server= " + GlobalContext.Server +
                 ";database= " + dataBaseName +
@@ -164,23 +164,25 @@ namespace MainForm
                 //DBInitWork();
                 try
                 {
-                    if (connection == null)//如果没有创建连接,则先创建
-                    {
-                        //从配置文件中获取SQL连接字段
-                        //string connStr = ConfigurationManager.ConnectionStrings["ConnetcionNmae"].ToString();
-
-                        connection = new SqlConnection(connString);//创建连接
-                        connection.Open();//打开连接
-                    }
-                    else if (connection.State == ConnectionState.Broken)//如果连接中断,则重现打开
+                    if (connection != null && connection.State == ConnectionState.Open)//如果没有创建连接,则先创建 
                     {
+                        //    //从配置文件中获取SQL连接字段
+                        //    //string connStr = ConfigurationManager.ConnectionStrings["ConnetcionNmae"].ToString();
+
+                        //    connection = new SqlConnection(connString);//创建连接
+                        //    connection.Open();//打开连接
+                        //}
+                        //else if (connection.State == ConnectionState.Broken)//如果连接中断,则重现打开
+                        //{
                         connection.Close();
-                        connection.Open();
-                    }
-                    else if (connection.State == ConnectionState.Closed)//如果关闭,则打开
-                    {
-                        connection.Open();
+                        //    connection.Open();
+                        //}
+                        //else if (connection.State == ConnectionState.Closed)//如果关闭,则打开
+                        //{
+                        //    connection.Open();
                     }
+                    connection = new SqlConnection(connString);//创建连接
+                    connection.Open();//打开连接
                     return connection;
                 }
                 catch (Exception ex)
@@ -686,7 +688,8 @@ EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单信息
             var CarrierBind_sumRecord = new CarrierBind
             {
                 CarrierCode = carrierCode,
-                ProductBarcode = productBarcode
+                ProductBarcode = productBarcode,
+                PCBBarcode = ""
             };
 
             // 检查记录是否已经存在

+ 8 - 8
MainForm/ClassFile/XiaomiAPI_MES/XiaomiMESEnum_ProcessData.cs

@@ -32,7 +32,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP20]上盖板上料装备
         /// </summary>
-        enum Enum_20_ProcessData
+        public enum Enum_20_ProcessData
         {
             [Description("抛料次数")]
             nThrowCount,
@@ -43,7 +43,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP30]点散热胶装备
         /// </summary>
-        enum Enum_30_ProcessData
+        public enum Enum_30_ProcessData
         {
             [Description("供胶速度")]
             fGlueSupplySpeed,
@@ -62,7 +62,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP40]胶线检测
         /// </summary>
-        enum Enum_40_ProcessData
+        public enum Enum_40_ProcessData
         {
             [Description("胶线位置X偏差")]
             fGluePosX,
@@ -79,7 +79,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP50]ADD板上料组装装备
         /// </summary>
-        enum Enum_50_ProcessData
+        public enum Enum_50_ProcessData
         {
             [Description("是否组装到位")]
             nIsAddPCBAsmOK,
@@ -95,7 +95,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP60]组上盖板
         /// </summary>
-        enum Enum_60_ProcessData
+        public enum Enum_60_ProcessData
         {
             [Description("是否组装到位")]
             nIsTopCoverAsmOK,
@@ -109,7 +109,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP70]上盖板锁螺丝
         /// </summary>
-        enum Enum_70_ProcessData
+        public enum Enum_70_ProcessData
         {
             [Description("锁附时间")]
             fScrewTimes,
@@ -124,7 +124,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP80]NG下料
         /// </summary>
-        enum Enum_80_ProcessData
+        public enum Enum_80_ProcessData
         {
             [Description("螺丝高度")]
             fScrewHeights,
@@ -135,7 +135,7 @@ namespace MainForm.ClassFile.XiaomiAPI
         /// <summary>
         /// [OP90]半成品下料
         /// </summary>
-        enum Enum_90_ProcessData
+        public enum Enum_90_ProcessData
         {
             [Description("抛料次数")]
             nThrowCount,

+ 446 - 57
MainForm/FaForm/Form_Home.cs

@@ -1300,15 +1300,16 @@ namespace MainForm
             }
         }
 
-
-        public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
+        /// <summary>
+        /// 解析三点激光存储的文本
+        /// </summary>
+        /// <param name="path">文本路径</param>
+        /// <returns></returns>
+        public string GetLastLineCompensation(string path)
         {
-            // 创建字典存储补偿点及其对应的值
-            Dictionary<string, string> compensationDict = new Dictionary<string, string>();
-
+            string result = "";
             try
             {
-                //string path = GlobalContext.MESLaserRPath;
                 // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
                 string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
                 string filename = $"Laser-{currentDate}-W0.txt";
@@ -1334,22 +1335,18 @@ namespace MainForm
                                 break;
                             }
                         }
-
                         // 将最后一行按逗号分隔
                         string[] values = lastLine.Split(',');
-                        values[1] = sn;
 
-                        string key = "三点激光_" + direction; // 构造键名
-                        string value = string.Join(",", values); // 获取值并去除多余空格
-                        compensationDict[key] = value;
-
-                        //// 提取“1点补偿”到“6点补偿”的值
-                        //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
-                        //{
-                        //    string key = $"{i - 1}点补偿"; // 构造键名
-                        //    string value = values[i].Trim(); // 获取值并去除多余空格
-                        //    compensationDict[key] = value;
-                        //}
+                        // 跳过前两个元素并转换为新的数组
+                        string[] newValues = values.Skip(0).Skip(1).ToArray();
+                        string value = string.Join(",", newValues); // 获取值并去除多余空格
+                        value = value.Replace(" ", "").Replace("\t", "").TrimStart(',');
+                        if (value.StartsWith(","))
+                        {
+                            value = value.Substring(1);
+                        }
+                        result = value;
                     }
                 }
                 else
@@ -1363,7 +1360,7 @@ namespace MainForm
                 Console.WriteLine($"发生错误: {ex.Message}");
             }
 
-            return compensationDict;
+            return result;
         }
 
         public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
@@ -1707,33 +1704,6 @@ namespace MainForm
                             }); // 设备数据 - 部件码
                     }
 
-                    //OP30站读txt数据
-                    if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
-                    {
-                        string path = "";
-                        if (direction == "Left")
-                        {
-                            string pathStr = GlobalContext.MESLaserLPath;
-                            path = DecFileName(pathStr);
-                        }
-                        else {
-                            string pathStr = GlobalContext.MESLaserRPath;
-                            path = DecFileName(pathStr);
-                        }
-
-                        //字典存储数据
-                        Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
-                        foreach (var kvp in compensationDict)
-                        {
-                            outRequest_Body.unitData.processData.Add(
-                                new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
-                                {
-                                    dataName = kvp.Key.ToString(),
-                                    dataValue = kvp.Value.ToString()
-                                });
-                        }
-                    }
-
                     //过站明细
                     if (GlobalContext.IsSendProcessDetail)
                     {
@@ -1756,6 +1726,29 @@ namespace MainForm
                         }
                     }
 
+                    //OP30站读txt数据
+                    if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
+                    {
+                        string path = "";
+                        if (direction == "Left")
+                        {
+                            string pathStr = GlobalContext.MESLaserLPath;
+                            path = DecFileName(pathStr);
+                        }
+                        else
+                        {
+                            string pathStr = GlobalContext.MESLaserRPath;
+                            path = DecFileName(pathStr);
+                        }
+                        outRequest_Body.unitData.processData.Add(
+                            new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
+                            {
+                                dataName = "fMesHeightInfos",
+                                dataValue = GetLastLineCompensation(path)
+                            });
+                      
+                    }
+
                     if (GlobalContext.MESIsSendUpFile)
                     {
                         foreach (var item in fileUploadData.fileData)
@@ -2841,7 +2834,7 @@ namespace MainForm
                 bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
                 (short, string) result = (0, "");
 
-                // 上传开始节拍
+                // 上传开始节拍 节拍只需要PLC传1、3、4、5
                 result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
                 //上传结束节拍
                 switch (oEEType)
@@ -2858,7 +2851,6 @@ namespace MainForm
 
                 if (result.Item1 == 1)
                 {
-
                     OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
                     //写入PLC
                     IoT_DataSet_t iotData = new IoT_DataSet_t();
@@ -2937,6 +2929,224 @@ namespace MainForm
         /// [S1] 壳体清洁上料装备
         /// </summary>
         /// <param name="plcNo">PLC编号</param>
+        //private void ReadStation_S1(int plcNo)
+        //{
+        //    string stationCode = "[OP10]";
+        //    string stationName = "壳体清洁上料";
+        //    string stationNameStr = stationCode + stationName;
+        //    string tagBaseName = "g_OP10_MES"; //标签变量名称
+        //    string tagMesCommName = "mesCommToPC"; //标签变量名称
+        //    string tagAgvCommName = "agvCommFrmPC";
+        //    string tagiotComnName = "iotData";
+        //    string tagBarsetName = "BarcodeSet";
+
+        //    string CarrierBarcode = "";
+        //    string ProductBarcode = "";
+
+        //    // 触发信号字典
+        //    //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0);             // PLC_FLAG 节拍接口
+        //    s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入) 
+
+        //    // PLC数据字典 赋值 
+        //    s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入) 
+        //    s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入) 
+
+        //    OP10_MesData_t stPLC_MesData; //PLC的MES数据
+        //    (int, string) result;
+
+        //    while (true)
+        //    {
+        //        try
+        //        {
+        //            if (!GlobalContext._IsCon_Funs1)
+        //            {
+        //                UpdatePLCMonitor(1, plcNo, 0);
+        //                continue;
+        //            }
+
+        //            if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
+        //            {
+        //                Stopwatch stopwatch1 = new Stopwatch();
+        //                Stopwatch stopwatch2 = new Stopwatch();
+        //                stopwatch1.Start();
+
+        //                stopwatch2.Start();
+
+        //                #region 一次性读取所有数据
+
+        //                // 一次性读取所有数据
+        //                result = FunsEip[plcNo]
+        //                    .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
+        //                if (result.Item1 != 0)
+        //                {
+        //                    //richTextBox1.AppendText("\n" + strRet);
+        //                }
+        //                else
+        //                {
+        //                    //richTextBox1.AppendText("\n" + "读取成功");
+        //                    stPLC_MesData.BarcodeSet.strProductBarcode =
+        //                        FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+        //                    stPLC_MesData.BarcodeSet.strPartBarcode =
+        //                        FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+        //                    stPLC_MesData.BarcodeSet.strCarrierBarcode =
+        //                        FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+        //                    stPLC_MesData.BarcodeSet.strPCBBarcode =
+        //                        FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
+
+        //                    //设备状态
+        //                    int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
+        //                    xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
+        //                        ? XiaomiDeviceState.Unknown
+        //                        : (XiaomiDeviceState)xmDeviceStateInt;
+
+        //                    // 载具SN
+        //                    CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
+        //                    // 物料码(物料码还未绑定载具SN时必填)
+        //                    ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
+        //                    // 节拍
+        //                    s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
+        //                    //报警信息
+        //                    _FaultDatas = stPLC_MesData.iotData.fault_codes;
+        //                }
+
+        //                #endregion 一次性读取所有数据
+
+        //                stopwatch2.Stop();
+
+        //                #region 进站
+
+        //                try
+        //                {
+        //                    if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
+        //                    {
+        //                        lock (lockObj)
+        //                        {
+        //                            if (!ProgressState)
+        //                            {
+        //                                uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
+        //                                ProgressState = true;
+        //                                Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
+        //                                    tagBaseName + "." + tagMesCommName, out ProgressState));
+        //                            }
+        //                        }
+        //                    }
+        //                }
+        //                catch (Exception ex)
+        //                {
+        //                    ProgressState = false;
+        //                    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 进站
+
+        //                #region 出站
+
+        //                try
+        //                {
+        //                    if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
+        //                    {
+        //                        lock (lockObj)
+        //                        {
+        //                            if (!ProgressState)
+        //                            {
+        //                                ProgressState = true;
+        //                                Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
+        //                                    tagBaseName + "." + tagMesCommName, stationCode, stationName,
+        //                                    out ProgressState));
+        //                                stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
+        //                            }
+        //                        }
+        //                    }
+        //                }
+        //                catch (Exception ex)
+        //                {
+        //                    ProgressState = false;
+        //                    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 出站
+
+
+        //                #region 节拍接口
+
+        //                try
+        //                {
+        //                    if (stPLC_MesData.iotData.beatAction > 0)
+        //                    {
+        //                        int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
+        //                        int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
+
+        //                        if (a1OEEType != a1OEETypeGOld)
+        //                        {
+        //                            s1PLCData["OEETypeFlag"] = "1";
+        //                        }
+        //                        else
+        //                        {
+        //                            s1PLCData["OEETypeFlag"] = "0";
+        //                        }
+        //                        if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
+        //                        {
+        //                            通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
+        //                            if (res == 1)
+        //                            {
+        //                                s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
+        //                            }
+        //                            else { 
+        //                                s1PLCSignal_Old["a1OEEType"] = 0;
+        //                            }
+        //                        }
+        //                    }
+        //                    else {
+        //                        s1PLCSignal_Old["a1OEEType"] = 0;
+        //                    }
+        //                }
+        //                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();
+        //                //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
+        //            }
+        //            else
+        //            {
+        //                UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
+        //                AddMessage_Station(stationNameStr, LogType.Info,
+        //                    "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
+
+        //                FunsEip[plcNo].Connect(); // 重连
+        //            }
+        //        }
+        //        catch (Exception ex)
+        //        {
+        //            UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
+        //            AddMessage_Station(stationNameStr, LogType.Error,
+        //                $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
+        //        }
+
+        //        Thread.Sleep(IntervalReadPLC);
+        //    }
+        //}
+
+
+
+        /// <summary>
+        /// [S1] 壳体清洁上料装备(临时方案)
+        /// </summary>
+        /// <param name="plcNo">PLC编号</param>
         private void ReadStation_S1(int plcNo)
         {
             string stationCode = "[OP10]";
@@ -3025,6 +3235,26 @@ namespace MainForm
 
                         try
                         {
+                            if (OpenDailogFalg)
+                            {
+                                using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
+                                {
+                                    var rs = dialog.ShowDialog();
+                                    if (rs == DialogResult.OK)
+                                    {
+                                        AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
+                                        OpenDailogFalg = false; //关闭扫码
+                                        StopWhile = false;//开启while循环
+                                    }
+                                    else
+                                    {
+                                        ProgressState = false;
+                                        return;
+                                    }
+                                }
+                            }
+
+
                             if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
                             {
                                 lock (lockObj)
@@ -3105,12 +3335,14 @@ namespace MainForm
                                     {
                                         s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
                                     }
-                                    else { 
+                                    else
+                                    {
                                         s1PLCSignal_Old["a1OEEType"] = 0;
                                     }
                                 }
                             }
-                            else {
+                            else
+                            {
                                 s1PLCSignal_Old["a1OEEType"] = 0;
                             }
                         }
@@ -3149,7 +3381,6 @@ namespace MainForm
             }
         }
 
-
         /// <summary>
         /// [S1] 壳体清洁上料 - 进站
         /// </summary>
@@ -3256,7 +3487,6 @@ namespace MainForm
         {
             Stopwatch stopwatch1 = new Stopwatch();
             Stopwatch stopwatch2 = new Stopwatch();
-            
 
             try
             {
@@ -3317,7 +3547,7 @@ namespace MainForm
                     string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
                         typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
                     //获取过站明细的值
-                    object valueObj = field.GetValue(stPLC_MesData.mesData);
+                    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
                     dic.Add(name, valueObj.ToString());
                 }
 
@@ -3762,8 +3992,28 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP20_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_20_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+
+                //string paramJson = JsonConvert.SerializeObject(dic);
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
 
+
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
                     MachineId, StationId, PartBarcode, paramJson);
@@ -4373,9 +4623,27 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
+                #region 转换过站明细字符串
+                //创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP30_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_30_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+                //string paramJson = JsonConvert.SerializeObject(dic);
+                #endregion
+                string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
                 //if (direction == "Right")
                 //{ 
-                string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,slot,
                     MachineId, StationId, "", paramJson, direction);
@@ -4814,6 +5082,8 @@ namespace MainForm
                 }
 
                 sn = strProductBarcode;
+                stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
+
                 AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
 
                 List<TestItem> items = new List<TestItem>();
@@ -4831,7 +5101,6 @@ namespace MainForm
                 });
 
                 #region 上传图片
-
                 if (GlobalContext.MQTTIsSendUpFile)
                 {
                     string[] urlarry = GlobalContext.UpFilePath.Split(",");
@@ -4850,8 +5119,26 @@ namespace MainForm
 
                 #endregion
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
 
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+                //string paramJson = JsonConvert.SerializeObject(dic);
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
                     "01-SLOT-01", MachineId, StationId, "", paramJson);
@@ -5351,8 +5638,28 @@ namespace MainForm
 
                 #endregion
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP50_DataSet_t).GetFields();
 
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_50_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+
+                //string paramJson = JsonConvert.SerializeObject(dic);
+
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 int result1 = 0;
                 byte mesResultFrmWeb = 0;
                 if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
@@ -5877,7 +6184,28 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP60_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_60_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+
+                //string paramJson = JsonConvert.SerializeObject(dic);
+
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
                     MachineId, StationId, "", paramJson);
@@ -6500,9 +6828,29 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP70_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_70_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+                //string paramJson = JsonConvert.SerializeObject(dic);
+
+                #endregion
+                string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 //if (direction == "Right")
                 //{ 
-                string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
                     batch_num, mtltmrk, plcDate_YMD, supplierCode
                     , sn, pass, CarrierBarcode, slot, MachineId, StationId, "", paramJson);
@@ -6951,6 +7299,7 @@ namespace MainForm
                 }
 
                 sn = strProductBarcode;
+                stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
                 AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
                 List<TestItem> items = new List<TestItem>();
                 items.Add(new TestItem()
@@ -6986,8 +7335,27 @@ namespace MainForm
 
                 #endregion
 
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP80_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_80_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+                //string paramJson = JsonConvert.SerializeObject(dic);
 
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
                     MachineId, StationId, "", paramJson);
@@ -7413,7 +7781,28 @@ namespace MainForm
                     Parameter_value = sn,
                     Parameter_unit = ""
                 });
+
+                #region 转换过站明细字符串
+                ////创建字典
+                //var dic = new Dictionary<string, string>();
+                //// 获取结构体类型
+                //FieldInfo[] fields = typeof(OP90_DataSet_t).GetFields();
+
+                //// 遍历变量名转换成字典描述
+                //foreach (FieldInfo field in fields)
+                //{
+                //    //获取枚举描述
+                //    string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
+                //        typeof(XiaomiMESEnum_ProcessData.Enum_90_ProcessData));
+                //    //获取过站明细的值
+                //    object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
+                //    dic.Add(name, valueObj.ToString());
+                //}
+                //string paramJson = JsonConvert.SerializeObject(dic);
+
+                #endregion
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
+
                 int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
                     MachineId, StationId, "", paramJson);

+ 1 - 1
MainForm/FaForm/Form_Home.resx

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

+ 27 - 1
MainForm/FaForm/Form_Main.cs

@@ -182,6 +182,7 @@ namespace MainForm
                 button_Home.PerformClick();  // 模拟点击button_Home按钮
                 currentRole = "";            // 重置当前用户的角色
                 OnModeChanged();             // 模式更改事件
+                Task.Run(() => DBChanged());
 
                 #region 定时任务
                 ////timer1.Interval = 60000;  // 间隔一分钟
@@ -302,6 +303,31 @@ namespace MainForm
                 logNet.WriteError("定时检查加工数据漏传的任务执行出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
             }
         }
+
+        /// <summary>
+        /// 监控时间同步到数据库配置中
+        /// </summary>
+        /// <returns></returns>
+        private void DBChanged()
+        {
+            try
+            {
+                while (true)
+                {
+                    string dbNow = "DB" + DateTime.Now.ToString("yyyyMM");
+                    if (SQLHelper.dataBaseName != dbNow)
+                    {
+                        SQLHelper.DBInitWork();
+                    }
+
+                    Thread.Sleep(5000);
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteWorkLog(LogType.Error, "实时监听创建数据库出错!错误信息:" + ex.Message);
+            }
+        }
         #endregion 窗体基础事件
 
         #region 菜单栏按钮
@@ -470,7 +496,7 @@ namespace MainForm
             }
         }
     }
-
+    
     public enum LogType
     {
         Debug,

+ 15 - 11
MainForm/FaForm/Form_Other.cs

@@ -1,13 +1,16 @@
-using Newtonsoft.Json;
+using MathNet.Numerics.RootFinding;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
 
 namespace MainForm.FaForm
 {
@@ -160,16 +163,17 @@ namespace MainForm.FaForm
 
         private void button13_Click(object sender, EventArgs e)
         {
-
-            string jsonString = "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}";
-
-            // 将JSON字符串转换为对象
-            var obj = JsonConvert.DeserializeObject(jsonString);
-
-            // 将对象转换回JSON字符串
-            string newJsonString = JsonConvert.SerializeObject(obj);
-
-            Console.WriteLine(newJsonString);
+            XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
+            Form_Home home = new Form_Home();
+            string path=GlobalContext.MESLaserLPath;
+
+            outRequest_Body.unitData.processData.Add(
+                new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
+                {
+                    dataName = "fMesHeightInfos",
+                    dataValue = home.GetLastLineCompensation(path)
+                });
+            
         }
     }
 }

+ 2 - 1
MainForm/FaForm/Form_SystemSet.cs

@@ -409,7 +409,8 @@ namespace MainForm
             {
                 MessageBox.Show("参数保存成功!");
                 Form_Home home = new Form_Home();
-                home.ConnectToIOT();
+                home.ConnectToIOT();//上抛iot配置修改
+                home.deviceConfigToIot("project_name", GlobalContext.Project_Code);//上抛装备配置
                 GlobalContext.UpdateData();
             }
             catch (Exception)