Parcourir la source

Merge branch 'refs/heads/master' into dev20250218_IOT开发

# Conflicts:
#	MainForm/FaForm/Form_Home.resx
WIN-GH9CEESPLTB\Administrator il y a 1 mois
Parent
commit
53e0fb35bd

+ 5 - 0
MainForm/ClassFile/ProjectClass/GlobalContext.cs

@@ -155,6 +155,9 @@ namespace MainForm
         public static bool IsSendAlarmData;      // 启用上传报警
         public static bool IsUseMESRoute;   // 启用边线MES软件
         public static bool MESIsConnect;  // MES是否正常连接
+        public static string MESLaserLPath;   // 三点激光数据本地存放地址
+        public static string MESLaserRPath;   // 三点激光数据本地存放地址
+
 
         // IOT - MQTT
         public static bool IsUseIot;  // 是否 启用IOT
@@ -279,6 +282,8 @@ namespace MainForm
                 LineCode = IniFile.INIGetStringValue(FilePath, "Product", "LineCode", ConstLineCode);
                 LineName = IniFile.INIGetStringValue(FilePath, "Product", "LineName", ConstLineName);
                 ProgramName = IniFile.INIGetStringValue(FilePath, "Product", "ProgramName", ConstProgramName);
+                MESLaserLPath = IniFile.INIGetStringValue(FilePath, "MES", "MESLaserLPath", "");
+                MESLaserRPath = IniFile.INIGetStringValue(FilePath, "MES", "MESLaserRPath", "");
 
                 WorkOrderCode = IniFile.INIGetStringValue(FilePath, "Product", "WorkOrderCode", ConstWorkOrderCode);  // 车间订单号
                 BatchNumber = IniFile.INIGetStringValue(FilePath, "Product", "BatchNumber", ConstBatchNumber);        // 批次号(splcode)

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

@@ -30,10 +30,10 @@
         {
             this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form_Home));
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = 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();
@@ -599,14 +599,14 @@
             this.systemLog.AllowUserToResizeRows = false;
             this.systemLog.BackgroundColor = System.Drawing.Color.White;
             this.systemLog.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
-            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
-            dataGridViewCellStyle1.BackColor = System.Drawing.Color.WhiteSmoke;
-            dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.systemLog.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
+            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle5.BackColor = System.Drawing.Color.WhiteSmoke;
+            dataGridViewCellStyle5.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.systemLog.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle5;
             this.systemLog.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.systemLog.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.colDate,
@@ -618,19 +618,19 @@
             this.systemLog.Location = new System.Drawing.Point(3, 32);
             this.systemLog.Name = "systemLog";
             this.systemLog.ReadOnly = true;
-            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
-            dataGridViewCellStyle3.BackColor = System.Drawing.Color.WhiteSmoke;
-            dataGridViewCellStyle3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.systemLog.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
+            dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle7.BackColor = System.Drawing.Color.WhiteSmoke;
+            dataGridViewCellStyle7.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.systemLog.RowHeadersDefaultCellStyle = dataGridViewCellStyle7;
             this.systemLog.RowHeadersVisible = false;
             this.systemLog.RowHeadersWidth = 51;
             this.systemLog.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
-            dataGridViewCellStyle4.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.systemLog.RowsDefaultCellStyle = dataGridViewCellStyle4;
+            dataGridViewCellStyle8.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.systemLog.RowsDefaultCellStyle = dataGridViewCellStyle8;
             this.systemLog.RowTemplate.Height = 27;
             this.systemLog.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
             this.systemLog.Size = new System.Drawing.Size(1533, 435);
@@ -638,8 +638,8 @@
             // 
             // colDate
             // 
-            dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.colDate.DefaultCellStyle = dataGridViewCellStyle2;
+            dataGridViewCellStyle6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.colDate.DefaultCellStyle = dataGridViewCellStyle6;
             this.colDate.HeaderText = "日期";
             this.colDate.MinimumWidth = 6;
             this.colDate.Name = "colDate";

+ 100 - 7
MainForm/FaForm/Form_Home.cs

@@ -1241,6 +1241,73 @@ namespace MainForm
             }
         }
 
+
+        public Dictionary<string, string> GetLastLineCompensation(string path,string direction,string sn)
+        {
+            // 创建字典存储补偿点及其对应的值
+            Dictionary<string, string> compensationDict = new Dictionary<string, string>();
+
+            try
+            {
+                //string path = GlobalContext.MESLaserRPath;
+                // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
+                string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
+                string filename = $"Laser-{currentDate}-W0.txt";
+                // 拼接完整路径
+                string fullPath = Path.Combine(path, filename);
+                string lastNonEmptyLine = "";
+
+                // 判断文件是否存在
+                if (File.Exists(fullPath))
+                {
+                    //读取文件内容
+                    string[] lines = File.ReadAllLines(fullPath);
+
+                    // 获取最后一行数据(忽略标题行)
+                    if (lines.Length > 1)
+                    {
+                        string lastLine = "";
+                        for (int i = lines.Length - 1; i > 0; i--)
+                        {
+                            if (!string.IsNullOrEmpty(lines[i]))
+                            {
+                                lastLine = lines[i];
+                                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;
+                        //}
+                    }
+                }
+                else
+                {
+                    Console.WriteLine($"文件不存在: {fullPath}");
+                }
+            }
+            catch (Exception ex)
+            {
+                // 捕获异常并输出错误信息
+                Console.WriteLine($"发生错误: {ex.Message}");
+            }
+
+            return compensationDict;
+        }
+
+
         /// <summary>
         /// 调用进站接口并保存进站数据
         /// </summary>
@@ -1346,10 +1413,10 @@ namespace MainForm
         /// <returns>上传成功时返回1;失败返回0</returns>
         private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
             string workorder_code, string batch_num, string mtltmrk, string proDate,
-            string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
+            string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string direction="")
         {
             return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
-                proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
+                proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, direction);
         }
 
         /// <summary>
@@ -1367,7 +1434,7 @@ namespace MainForm
         /// <returns>上传成功时返回1;失败返回0</returns>
         public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
             string processItem, string workorder_code, string batch_num, string mtltmrk,
-            string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
+            string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string direction="")
         {
             int upload = 0;
             int result = 0;
@@ -1417,6 +1484,27 @@ namespace MainForm
                         });  // 设备数据 - 部件码
                     }
 
+                    //OP30站读txt数据
+                    if (stationNameStr.Contains("OP30"))
+                    {
+                        string path = "";
+                        if (direction == "Left")
+                            path = GlobalContext.MESLaserLPath;
+                        else
+                            path= GlobalContext.MESLaserRPath;  
+                        //字典存储数据
+                        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()
+                                });
+                        }
+                    }
+
                     string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
 
                     if (GlobalContext.IsSendProcessData)
@@ -1428,7 +1516,10 @@ namespace MainForm
                         {
                             response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
                             if (response != null && response.header.code == "200")
+                            {
+                                OnMessage(LogType.Error, "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" + JsonConvert.SerializeObject(response.body));
                                 break;
+                            }
                             else if (!mesRet.Contains("1009"))  // 1009是未知错误
                                 i++;
 
@@ -2776,6 +2867,7 @@ namespace MainForm
                     AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                 }
                 sn = strProductBarcode;
+                sn = "AB123456789";
                 AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
 
                 List<TestItem> items = new List<TestItem>();
@@ -2793,11 +2885,12 @@ namespace MainForm
                 });
 
                 int result1 = 1;
-                if (direction == "Right")
-                { 
+                //if (direction == "Right")
+                //{ 
                      result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
-   , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
-                }
+   , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", direction);
+                //}
+
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
 

Fichier diff supprimé car celui-ci est trop grand
+ 8317 - 8029
MainForm/FaForm/Form_Home.resx