فهرست منبع

优化键盘格数据判断功能,增加数据保存功能

zly 5 ماه پیش
والد
کامیت
20b685a75d
1فایلهای تغییر یافته به همراه170 افزوده شده و 86 حذف شده
  1. 170 86
      TeamAAS-VM/Core/Management.cs

+ 170 - 86
TeamAAS-VM/Core/Management.cs

@@ -99,7 +99,7 @@ namespace TeamAAS_VP.Core
         // 扫码完成事件
         private readonly ManualResetEventSlim _scanDoneEvent = new ManualResetEventSlim(false);
         //键盘数据
-        public Dictionary<string, double> keyData;
+        public Dictionary<string, double> keyData = new Dictionary<string, double>{};
         //键盘差值
         public bool isValueOk;
 
@@ -2726,7 +2726,12 @@ namespace TeamAAS_VP.Core
 
                                     }
                                     bool allSuccess = true;
-                                    bool ok = CheckKeyBoardValue(keyData, out string msg);
+                                    bool ok=false;
+                                    if (keyData != null)
+                                    {
+                                         ok = CheckKeyBoardValue(keyData, out string msg);
+                                    }
+                                    
                                     if (ok && resultIndex == 1 ? true : false && isValueOk)
                                     {
                                         ShowMes_Result = true;
@@ -2735,6 +2740,11 @@ namespace TeamAAS_VP.Core
                                     {
                                         ShowMes_Result = false;
                                     }
+                                    if (homeview.IsResultTrue == false)
+                                    {
+                                        ShowMes_Result = true;
+                                    }
+                                    keyData.Clear();
                                     // ShowMes_Result = resultIndex == 1 ? true : false;
                                     
                                     //(bool isSuccess, string response) = await _mesService.SubmitGetAsync(ProductMainSN, "", submitData.ToString(), resultIndex == 1 ? true : false, _LastMesCheckTime[i], serverTimeResult.Now);
@@ -2776,12 +2786,14 @@ namespace TeamAAS_VP.Core
                                     }
                                     await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
 
-
+                                    
                                     //是否保存当前的产品记录至CSV?
                                     if (stationConfig.SaveCsv)
                                     {
                                         string saveppid = "NA";
                                         if (stationConfig.SaveCsvPPID) saveppid = ppid;
+                                        Dictionary<string, double> adjacentDiffDict = GetAdjacentDiffDict(keyData);
+
                                         //判断锁付路径字符串是否为空,如果不为空则保存,否则不保存
                                         if (!string.IsNullOrEmpty(stationConfig.SaveCsvPath))
                                         {
@@ -2797,8 +2809,7 @@ namespace TeamAAS_VP.Core
                                                     {
                                                         item.PhotoName = "'=" + "_" + k.ToString();
                                                     }
-                                                }
-
+                                                }                                               
                                                 DFC.Add(new DataFormCtq
                                                 {
                                                     PPID = saveppid,
@@ -2823,10 +2834,41 @@ namespace TeamAAS_VP.Core
                                                     PD_ATTR_02 = item.MidLimit,
                                                     PD_ATTR_03 = "",
                                                     PD_ATTR_04 = code,
-                                                    PD_ATTR_05 = ""
-                                                });
+                                                    PD_ATTR_05 = "",
+                                                });                                      
                                             }
+                                            foreach (var items in adjacentDiffDict)
+                                            {
+                                                string pairkey = items.Key;
+                                                string diffvalue = items.Value.ToString("F3");
 
+                                                DFC.Add(new DataFormCtq
+                                                {
+                                                    PPID = saveppid,
+                                                    PROCESS_NAME = stationConfig.DataInfo.PROCESS_NAME,
+                                                    PROCESS_START_TIME = _LastMesCheckTime[i].ToString("o"),
+                                                    CTQ_NAME = pairkey,
+                                                    CTQ_VALUE = diffvalue,
+                                                    CTQ_LSL = "0",
+                                                    CTQ_USL = "0.3",
+                                                    PROCESS_END_TIME = serverTimeResult.Now.ToString("o"),
+                                                    SUPPLIER_NAME = stationConfig.DataInfo.SUPPLIER_NAME,
+                                                    COMMODITY_TYPE = stationConfig.DataInfo.COMMODITY_TYPE,
+                                                    REVISION = stage,//
+                                                    WO = wo,//
+                                                    MFG_LOT = stationConfig.DataInfo.MFG_LOT,//
+                                                    MFG_ASSY_LINE = stationConfig.DataInfo.MFG_ASSY_LINE,
+                                                    PROCESS_OUTCOME = ok ? "Pass":"FAIL",
+                                                    PROCESS_MACHINE_ID = stationConfig.DataInfo.PROCESS_MACHINE_ID,
+                                                    CTQ_UNIT_OF_MEASURE = "mm",
+                                                    ERROR_MESSAGE = ok ? "":$"{diffvalue}",
+                                                    PD_ATTR_01 = ProductMainSN,//
+                                                    PD_ATTR_02 = "",
+                                                    PD_ATTR_03 = "",
+                                                    PD_ATTR_04 = code,
+                                                    PD_ATTR_05 = "",
+                                                });
+                                            }
                                             bool recordResult = RecordStationResult(i, DFC, ProductMainSN, serverTimeResult.Now.Subtract(_LastMesCheckTime[i]).TotalSeconds, _LastMesCheckTime[i], stationConfig.SaveCsvPath);
                                             if (recordResult)
                                             {
@@ -3198,40 +3240,53 @@ namespace TeamAAS_VP.Core
                                     string[] strpoints1 = visionResult.Items[i].Split(',');
                                     string[] body1 = strpoints1[1].Split(";");
 
-                                    string keyName = strpoints1[0].Split('-').Last().Trim();
-                                    List<double> list = new List<double>();
+                                    if (body1.Length >= 5)
+                                    {                                        
+                                        string keyName = strpoints1[0].Split('-').Last().Trim();
+                                        List<double> list = new List<double>();
 
-                                    foreach (string v in body1)
-                                    {
-                                        if (double.TryParse(v.Trim(), out double num))
+                                        foreach (string v in body1)
                                         {
-                                            if (num == 999)
+                                            if (double.TryParse(v.Trim(), out double num))
                                             {
-                                                continue;
+                                                if (num == 999)
+                                                {
+                                                    continue;
+                                                }
+                                                list.Add(num);
                                             }
-                                            list.Add(num);
                                         }
-                                    }
-                                    if (list.Count == 0)
-                                    {
-                                        continue;
-                                    }
+                                        if (list.Count == 0)
+                                        {
+                                            continue;
+                                        }
 
-                                    double max = list.Max();
-                                    double min = list.Min();
+                                        double max = list.Max();
+                                        double min = list.Min();
 
-                                    if (max - min <= 0.3)
-                                    {
-                                        isValueOk = true;
-                                    }
-                                    else
-                                    {
-                                        SendTaskMessage($"键盘格{keyName}最大值{max}与最小值{min}相差大于0.3!",MessageLevel.Error);
+                                        if (max - min <= 0.3)
+                                        {
+                                            isValueOk = true;
+                                        }
+                                        else
+                                        {
+                                            SendTaskMessage($"键盘格{keyName}最大值{max}与最小值{min}相差大于0.3!", MessageLevel.Error);
+                                        }
+                                        double average = list.Average();
+                                        if (keyData != null)
+                                        {
+                                            if (!keyData.ContainsKey(keyName))
+                                            {
+                                                keyData.Add(keyName, average);
+                                            }
+                                        }
+                                        else
+                                        {
+                                            keyData.Add(keyName, average);
+                                        }
                                     }
-                                    double average = list.Average();
-                                    if (!keyData.ContainsKey(keyName))
-                                        keyData.Add(keyName, average);
-
+                                    
+                                       
                                     if (body1.Length > 1)
                                     {
                                         for (int j = 1; j <= body1.Length; j++)
@@ -3687,37 +3742,39 @@ namespace TeamAAS_VP.Core
                 // ==============================================
                 // 第一行:ESC + F1~F12
                 // ==============================================
-                ["ESC"] = new List<string> { "F1", "`", "1" },
-                ["F1"] = new List<string> { "ESC", "F2", "`", "1", "2" },
-                ["F2"] = new List<string> { "F1", "F3", "1", "2", "3" },
-                ["F3"] = new List<string> { "F2", "F4", "2", "3", "4" },
-                ["F4"] = new List<string> { "F3", "F5", "3", "4", "5" },
-                ["F5"] = new List<string> { "F4", "F6", "4", "5", "6" },
-                ["F6"] = new List<string> { "F5", "F7", "5", "6", "7" },
-                ["F7"] = new List<string> { "F6", "F8", "6", "7", "8" },
-                ["F8"] = new List<string> { "F7", "F9", "7", "8", "9" },
-                ["F9"] = new List<string> { "F8", "F10", "8", "9", "0" },
-                ["F10"] = new List<string> { "F9", "F11", "9", "0", "-" },
-                ["F11"] = new List<string> { "F10", "F12", "0", "-", "=" },
-                ["F12"] = new List<string> { "F11", "-", "=", "Backspace" },
+                ["ESC"] = new List<string> { "F1", "~",  },
+                ["F1"] = new List<string> { "ESC", "F2", "1" },
+                ["F2"] = new List<string> { "F1", "F3",  "2" },
+                ["F3"] = new List<string> { "F2", "F4", "2", "3"},
+                ["F4"] = new List<string> { "F3", "F5", "3", "4" },
+                ["F5"] = new List<string> { "F4", "F6", "4", "5" },
+                ["F6"] = new List<string> { "F5", "F7", "5", "6" },
+                ["F7"] = new List<string> { "F6", "F8", "6", "7" },
+                ["F8"] = new List<string> { "F7", "F9", "7", "8" },
+                ["F9"] = new List<string> { "F8", "F10", "8", "9" },
+                ["F10"] = new List<string> { "F9", "F11", "9", "0" },
+                ["F11"] = new List<string> { "F10", "F12", "0", "-" },
+                ["F12"] = new List<string> { "F11", "-", "=", "Insert" },
+                ["Insert"] = new List<string> { "F12", "Power", "Backspace" },
+                ["Power"] = new List<string> {"Backspace" },
 
                 // ==============================================
                 // 第二行:` 1 2 3 4 5 6 7 8 9 0 - = Backspace
                 // ==============================================
-                ["`"] = new List<string> { "ESC", "F1", "1", "TAB", "Q" },
-                ["1"] = new List<string> { "ESC", "F1", "F2", "`", "2", "TAB", "Q" },
-                ["2"] = new List<string> { "F1", "F2", "F3", "1", "3", "Q", "W" },
-                ["3"] = new List<string> { "F2", "F3", "F4", "2", "4", "W", "E" },
-                ["4"] = new List<string> { "F3", "F4", "F5", "3", "5", "E", "R" },
-                ["5"] = new List<string> { "F4", "F5", "F6", "4", "6", "R", "T" },
-                ["6"] = new List<string> { "F5", "F6", "F7", "5", "7", "T", "Y" },
-                ["7"] = new List<string> { "F6", "F7", "F8", "6", "8", "Y", "U" },
-                ["8"] = new List<string> { "F7", "F8", "F9", "7", "9", "U", "I" },
-                ["9"] = new List<string> { "F8", "F9", "F10", "8", "0", "I", "O" },
-                ["0"] = new List<string> { "F9", "F10", "F11", "9", "-", "O", "P" },
-                ["-"] = new List<string> { "F10", "F11", "F12", "0", "=", "P", "[" },
-                ["="] = new List<string> { "F11", "F12", "-", "Backspace", "[", "]" },
-                ["Backspace"] = new List<string> { "F12", "=", "]", "\\" },
+                ["~"] = new List<string> { "ESC", "1", "TAB" },
+                ["1"] = new List<string> {  "F1", "`", "2", "TAB", "Q" },
+                ["2"] = new List<string> {  "F2", "1", "3", "Q", "W" },
+                ["3"] = new List<string> {  "F3", "F4", "2", "4", "W", "E" },
+                ["4"] = new List<string> {  "F4", "F5", "3", "5", "E", "R" },
+                ["5"] = new List<string> {  "F5", "F6", "4", "6", "R", "T" },
+                ["6"] = new List<string> {  "F6", "F7", "5", "7", "T", "Y" },
+                ["7"] = new List<string> {  "F7", "F8", "6", "8", "Y", "U" },
+                ["8"] = new List<string> {  "F8", "F9", "7", "9", "U", "I" },
+                ["9"] = new List<string> {  "F9", "F10", "8", "0", "I", "O" },
+                ["0"] = new List<string> {  "F10", "F11", "9", "-", "O", "P" },
+                ["-"] = new List<string> {  "F11", "F12", "0", "=", "P", "{" },
+                ["="] = new List<string> {  "F12", "-", "Backspace", "{", "}" },
+                ["Backspace"] = new List<string> { "Insert", "=", "}", "|", "Power" },
 
                 // ==============================================
                 // 第三行:TAB Q W E R T Y U I O P [ ] \
@@ -3732,10 +3789,10 @@ namespace TeamAAS_VP.Core
                 ["U"] = new List<string> { "Y", "6", "7", "8", "I", "H", "J" },
                 ["I"] = new List<string> { "U", "7", "8", "9", "O", "J", "K" },
                 ["O"] = new List<string> { "I", "8", "9", "0", "P", "K", "L" },
-                ["P"] = new List<string> { "O", "9", "0", "-", "[", "L", ";" }, 
-                ["["] = new List<string> { "P", "0", "-", "=", "]", ";", "'" },
-                ["]"] = new List<string> { "[", "-", "=", "Backspace", "\\", "'", "Enter" },
-                ["\\"] = new List<string> { "]", "=", "Backspace", "Enter" },
+                ["P"] = new List<string> { "O", "9", "0", "-", "{", "L", ";" }, 
+                ["{"] = new List<string> { "P", "0", "-", "=", "}", ";", "'" },
+                ["}"] = new List<string> { "{", "-", "=", "Backspace", "|", "'", "Enter" },
+                ["|"] = new List<string> { "}", "Backspace", "Enter" },
 
                 // ==============================================
                 // 第四行:CapsLock A S D F G H J K L ; ' Enter
@@ -3749,44 +3806,71 @@ namespace TeamAAS_VP.Core
                 ["H"] = new List<string> { "G", "Y", "U", "J", "B", "N" },
                 ["J"] = new List<string> { "H", "U", "I", "K", "N", "M" },
                 ["K"] = new List<string> { "J", "I", "O", "L", "M", "," },
-                ["L"] = new List<string> { "K", "O", "P", ";", ",", ".", "/" },
-                [";"] = new List<string> { "L", "P", "[", "'", ".", "/" },
-                ["'"] = new List<string> { ";", "[", "]", "Enter", "/" },
-                ["Enter"] = new List<string> { "'", "]", "\\", "RightShift" },
+                ["L"] = new List<string> { "K", "O", "P", ";", "<", ">", "?" },
+                [";"] = new List<string> { "L", "P", "{", "'", ">", "?" },
+                ["'"] = new List<string> { ";", "{", "}", "Enter", "?" },
+                ["Enter"] = new List<string> { "'", "}", "|", "RightShift" },
 
                 // ==============================================
                 // 第五行:LeftShift Z X C V B N M , . / RightShift
                 // ==============================================
-                ["LeftShift"] = new List<string> { "CapsLock", "A", "S", "D", "Z", "Ctrl", "Fn" },
-                ["Z"] = new List<string> { "LeftShift", "A", "S", "X" },
+                ["Shift"] = new List<string> { "CapsLock", "A", "S", "D", "Z", "Ctrl", "Fn" },
+                ["Z"] = new List<string> { "Shift", "A", "S", "X" },
                 ["X"] = new List<string> { "Z", "S", "D", "C" },
                 ["C"] = new List<string> { "X", "D", "F", "V" },
                 ["V"] = new List<string> { "C", "F", "G", "B" },
                 ["B"] = new List<string> { "V", "G", "H", "N" },
                 ["N"] = new List<string> { "B", "H", "J", "M" },
-                ["M"] = new List<string> { "N", "J", "K", "," },
-                [","] = new List<string> { "M", "K", "L", "." },
-                ["."] = new List<string> { ",", "L", ";", "/" },
-                ["/"] = new List<string> { ".", ";", "'", "RightShift" },
-                ["RightShift"] = new List<string> { "/", "Enter" },
+                ["M"] = new List<string> { "N", "J", "K", "<" },
+                ["<"] = new List<string> { "M", "K", "L", ">" },
+                [">"] = new List<string> { "<", "L", ";", "?" },
+                ["?"] = new List<string> { ">", ";", "'", "Shift2" },
+                ["Shift2"] = new List<string> { "?", "Enter" },
 
                 // ==============================================
                 // 第六行:Ctrl Fn Win Alt Space Alt Fn Ctrl ← ↓ →
                 // ==============================================
-                ["Ctrl"] = new List<string> { "Fn", "LeftShift" },
-                ["Fn"] = new List<string> { "Ctrl", "Win", "LeftShift" },
+                ["Ctrl1"] = new List<string> { "Fn", "Shift" },
+                ["Fn"] = new List<string> { "Ctrl", "Win", "Shift" },
                 ["Win"] = new List<string> { "Fn", "Alt" },
-                ["Alt"] = new List<string> { "Win", "Space" },
-                ["Space"] = new List<string> { "Alt", "RightAlt" },
-                ["RightAlt"] = new List<string> { "Space", "RightFn" },
-                ["RightFn"] = new List<string> { "RightAlt", "RightCtrl" },
-                ["RightCtrl"] = new List<string> { "RightFn", "←", "↓", "→" },
-                ["←"] = new List<string> { "RightCtrl", "↓" },
-                ["↓"] = new List<string> { "←", "→", "RightCtrl" },
-                ["→"] = new List<string> { "↓", "RightCtrl" }
+                ["Alt1"] = new List<string> { "Win", "Space" },
+                ["Space1"] = new List<string> { "Alt", "Alt2" },
+                ["Alt2"] = new List<string> { "Space", "Ctrl2" },
+               // ["RightFn"] = new List<string> { "RightAlt", "RightCtrl" },
+                ["Ctrl2"] = new List<string> { "Alt2", "Left", "Updown", "Right" },
+                ["Left"] = new List<string> { "RightCtrl", "Updown" },
+                ["Updown"] = new List<string> { "Left", "Right", "Ctrl2" },
+                ["Right"] = new List<string> { "Updown", "Ctrl2" }
             };
         }
 
+        private Dictionary<string, double> GetAdjacentDiffDict(Dictionary<string, double> keyData)
+        {
+            Dictionary<string, double> diffDict = new Dictionary<string, double>();
+            var neighborMap = GetKeyboardNeighborMap(); // 引用你的键盘相邻表
+
+            foreach (var kvp in keyData)
+            {
+                string key1 = kvp.Key;
+                double val1 = kvp.Value;
+
+                if (!neighborMap.TryGetValue(key1, out var neighbors)) continue;
+
+                foreach (string key2 in neighbors)
+                {
+                    if (!keyData.TryGetValue(key2, out double val2)) continue;
+
+                    // 去重核心:保证 A-S 和 S-A 只存一次
+                    string pairKey = string.Compare(key1, key2) < 0 ? $"{key1}-{key2}" : $"{key2}-{key1}";
+
+                    if (diffDict.ContainsKey(pairKey)) continue; // 跳过已存的
+
+                    double diff = Math.Abs(val1 - val2);
+                    diffDict.Add(pairKey, diff);
+                }
+            }
+            return diffDict;
+        }
 
 
         private async void DoYieldTime(object state)
@@ -3893,7 +3977,7 @@ namespace TeamAAS_VP.Core
                 if (!File.Exists(fullPath))
                 {
                     sb.Append("PPID,PROCESS_NAME,PROCESS_START_TIME,CTQ_NAME,CTQ_VALUE,CTQ_LSL,CTQ_USL,PROCESS_END_TIME,SUPPLIER_NAME,COMMODITY_TYPE,REVISION,WO#,MFG_LOT#," +
-                        "MFG_ASSY_LINE,PROCESS_OUTCOME,PROCESS_MACHINE_ID,CTQ_UNIT_OF_MEASURE,ERROR_MESSAGE,PD_ATTR_01,PD_ATTR_02,PD_ATTR_03,PD_ATTR_04,PD_ATTR_05");
+                        "MFG_ASSY_LINE,PROCESS_OUTCOME,PROCESS_MACHINE_ID,CTQ_UNIT_OF_MEASURE,ERROR_MESSAGE,PD_ATTR_01,PD_ATTR_02,PD_ATTR_03,PD_ATTR_04,PD_ATTR_05,PD_ATTR_06");
                     sb.AppendLine();
                 }
                 if (dfcs == null || dfcs.Count() == 0)