Browse Source

Merge repos.ubtob.net:usoft/mes-client

callm 4 weeks ago
parent
commit
09526d4b44

+ 117 - 81
UAS_MES_HYSX/FunctionCode/Make/Make_AirTightnessTest.cs

@@ -1,4 +1,5 @@
 using DevExpress.Utils.Drawing.Helpers;
+using DevExpress.XtraBars.Docking2010.Views.Widget;
 using NPOI.SS.Formula.Functions;
 using Seagull.BarTender.Print;
 using System;
@@ -36,8 +37,6 @@ namespace UAS_MES_NEW.Make
 
         SerialPort serialPort = new SerialPort();
         StringBuilder receivedData = new StringBuilder();
-        DateTime lastReceiveTime = DateTime.Now;
-        readonly object lockObj = new object();
 
         private void Make_AirTightnessTest_Load(object sender, EventArgs e)
         {
@@ -184,7 +183,7 @@ namespace UAS_MES_NEW.Make
                 serialPort.BaudRate = Convert.ToInt32(BaudRate.Text);
                 if (!serialPort.IsOpen) serialPort.Open();
                 serialPort.WriteLine(workStation);
-                Serial_DataReceived(null,null);
+                //Serial_DataReceived(null,null);
                 return true;
             }
             catch (Exception ex)
@@ -201,46 +200,40 @@ namespace UAS_MES_NEW.Make
             }
             try
             {
-                string resList = serialPort.ReadExisting();
+                string resList = serialPort.ReadExisting(); //resList = "/20251014_142742/0K/2#/NULL/30/99/0/12700/0/N/0K";
                 receivedData.Append(resList);
 
-                //resList = "/20251014_142742/0K/2#/NULL/30/99/0/12700/0/N/0K";
-                lock (lockObj)
+                string completeData = receivedData.ToString();
+                string dateString = DateTime.Now.ToString("yyyyMMdd");
+                string[] records = completeData.Split(new string[] { "/"+ dateString }, StringSplitOptions.RemoveEmptyEntries);
+                string parseStr = "/" + dateString + records[records.Length - 1].ToString();
+                if (parseStr.Split('/').Length > 10)
                 {
-                    receivedData.Append(resList);
-                    lastReceiveTime = DateTime.Now;
-                    if(receivedData.Length > 0)
+                    if (receivedData.ToString().Contains("1#"))
                     {
-                        string completeData = receivedData.ToString();
-                        this.Invoke(new Action(() =>
+                        Result.Text = parseStr;
+                        string testRes = LoadTestDetail("L", "1");
+                        CheckPassStation(FirstSN.Text.Trim(), testRes);
+                        if (testRes == "NG")
                         {
-                            if (mTestVal == "LWS1")
-                            {
-                                Result.Text = completeData;
-                                CheckPassStation(FirstSN.Text, Result.Text);
-                                LoadTestDetail("L", out string testRes);
-                                if (testRes == "NG")
-                                {
-                                    Pagination.SelectedIndex = 0;
-                                    RTxt8.Focus();
-                                    RTxt8.SelectAll();
-                                }
-                            }
-                            else if (mTestVal == "LWS2")
-                            {
-                                Result1.Text = completeData;
-                                CheckPassStation(SecondSN.Text, Result1.Text);
-                                LoadTestDetail("L", out string testRes);
-                                if (testRes == "NG")
-                                {
-                                    Pagination.SelectedIndex = 1;
-                                    R1Txt8.Focus();
-                                    R1Txt8.SelectAll();
-                                }
-                            }
-                            receivedData.Clear();
-                        }));
+                            Pagination.SelectedIndex = 0;
+                            RTxt8.Focus();
+                            RTxt8.SelectAll();
+                        }
+                    }
+                    else if (receivedData.ToString().Contains("2#"))
+                    {
+                        Result1.Text = parseStr;
+                        string testRes = LoadTestDetail("L", "2");
+                        CheckPassStation(SecondSN.Text.Trim(), testRes);
+                        if (testRes == "NG")
+                        {
+                            Pagination.SelectedIndex = 1;
+                            R1Txt8.Focus();
+                            R1Txt8.SelectAll();
+                        }
                     }
+                    receivedData.Clear();
                 }
             }
             catch (Exception ex)
@@ -251,30 +244,34 @@ namespace UAS_MES_NEW.Make
 
         private void CheckPassStation(string sn,string res)
         {
+            List<string> param = new List<string>() { };
+            string outMsg = "";
+            param.Add(workOrder.Text.Trim());
+            param.Add(sn);
+            param.Add(User.UserSourceCode);
+            param.Add(res);
+            param.Add("");
+            param.Add("");
+            param.Add("AirTightness");
+            param.Add("");
+            param.Add(outMsg);
+            string[] paramList = param.ToArray();
+            dh.CallProcedure("cs_insert_testrejects", ref paramList);
+            if (paramList[8].Substring(0, 2) == "OK")
+            {
+                ShowMsg(1, $"序列号{sn}采集成功:测试结果为{res}");
+                LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oWO, User.UserLineCode, User.UserSourceCode, "气密性测试", "气密性测试过站成功", sn, "");
+            }
+
+            dt = (DataTable)dh.ExecuteSql($"SELECT mp_id FROM makeprocess WHERE mp_sncode = '{sn}' AND mp_sourcecode = 'QMX'", "select");
+            if (dt.Rows.Count > 0) return;
+
             if (LogicHandler.CheckStepSNAndMacode(workOrder.Text, User.UserSourceCode, sn, User.UserCode, out oWO, out oWOId, out oErrMsg))
             {
                 if (LogicHandler.SetStepResult(oWO, User.UserSourceCode, sn, "气密性测试", "OK", User.UserCode, out oErrMsg))
                 {
-                    List<string> param = new List<string>() { };
-                    string outMsg = "";
-                    param.Add(oWO);
-                    param.Add(sn);
-                    param.Add(User.UserSourceCode);
-                    param.Add(res);
-                    param.Add("");
-                    param.Add("");
-                    param.Add("AirTightness");
-                    param.Add("");
-                    param.Add(outMsg);
-                    string[] paramList = param.ToArray();
-                    dh.CallProcedure("cs_insert_testrejects", ref paramList);
-                    if (paramList[8].Substring(0, 2) == "OK")
-                    {
-                        ShowMsg(1, $"序列号{sn}采集成功:测试结果为{res}");
-                        LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oWO, User.UserLineCode, User.UserSourceCode, "气密性测试", "气密性测试过站成功", sn, "");
 
-                        //LoadTestDetail("C", out string testRes);
-                    }
+                    ShowMsg(1, $"序列号{sn}过站OK");
                 }
                 else
                 {
@@ -288,38 +285,77 @@ namespace UAS_MES_NEW.Make
             }
         }
 
-        private void LoadTestDetail(string type, out string testRes)
+        private string LoadTestDetail(string type, string num)
         {
-            string detail = Result.Text.Trim();
+            string detail,testRes;
             if (type == "L")
             {
-                string[] parts = detail.Split('/');
-                RTxt1.Text = parts[1];
-                RTxt2.Text = parts[2];
-                RTxt3.Text = parts[3];
-                RTxt4.Text = parts[5];
-                RTxt5.Text = parts[6];
-                RTxt6.Text = parts[7];
-                RTxt7.Text = parts[8];
-                RTxt8.Text = parts[9];
-                RTxt9.Text = parts[10];
-                RTxt10.Text = parts[11];
-                testRes = parts[9].ToUpper() == "Y" ? "OK" : "NG";
+                if(num == "1")
+                {
+                    detail = Result.Text.Trim();
+                    string[] parts = detail.Split('/');
+                    RTxt1.Text = parts[1];
+                    RTxt2.Text = parts[2];
+                    RTxt3.Text = parts[3];
+                    RTxt4.Text = parts[5];
+                    RTxt5.Text = parts[6];
+                    RTxt6.Text = parts[7];
+                    RTxt7.Text = parts[8];
+                    RTxt8.Text = parts[9];
+                    RTxt9.Text = parts[10];
+                    RTxt10.Text = parts[11];
+                    testRes = parts[parts.Length - 2].ToUpper() == "Y" ? "OK" : "NG";
+                    return testRes;
+                }
+                else
+                {
+                    detail = Result1.Text.Trim();
+                    string[] parts = detail.Split('/');
+                    R1Txt1.Text = parts[1];
+                    R1Txt2.Text = parts[2];
+                    R1Txt3.Text = parts[3];
+                    R1Txt4.Text = parts[5];
+                    R1Txt5.Text = parts[6];
+                    R1Txt6.Text = parts[7];
+                    R1Txt7.Text = parts[8];
+                    R1Txt8.Text = parts[9];
+                    R1Txt9.Text = parts[10];
+                    R1Txt10.Text = parts[11];
+                    testRes = parts[parts.Length - 2].ToUpper() == "Y" ? "OK" : "NG";
+                    return testRes;
+                }
             }
             else if (type == "C")
             {
-                RTxt1.Text = "";
-                RTxt2.Text = "";
-                RTxt3.Text = "";
-                RTxt4.Text = "";
-                RTxt5.Text = "";
-                RTxt6.Text = "";
-                RTxt7.Text = "";
-                RTxt8.Text = "";
-                RTxt9.Text = "";
-                RTxt10.Text = "";
+                if(num == "1")
+                {
+                    RTxt1.Text = "";
+                    RTxt2.Text = "";
+                    RTxt3.Text = "";
+                    RTxt4.Text = "";
+                    RTxt5.Text = "";
+                    RTxt6.Text = "";
+                    RTxt7.Text = "";
+                    RTxt8.Text = "";
+                    RTxt9.Text = "";
+                    RTxt10.Text = "";
+                }
+                else
+                {
+                    R1Txt1.Text = "";
+                    R1Txt2.Text = "";
+                    R1Txt3.Text = "";
+                    R1Txt4.Text = "";
+                    R1Txt5.Text = "";
+                    R1Txt6.Text = "";
+                    R1Txt7.Text = "";
+                    R1Txt8.Text = "";
+                    R1Txt9.Text = "";
+                    R1Txt10.Text = "";
+                }
+                return "";
             }
-            testRes = "";
+            return "";
         }
 
         private void RTxt8_KeyDown(object sender, KeyEventArgs e)

+ 52 - 24
UAS_MES_HYSX/FunctionCode/Make/Make_WirelessThroughput.cs

@@ -58,6 +58,11 @@ namespace UAS_MES_NEW.Make
             {
                 IPList.Text = IPList.Text + ":5001";
             }
+
+            if (!ProductList.Text.Contains(":"))
+            {
+                ProductList.Text = ProductList.Text + ":23";
+            }
         }
 
         private void SN_KeyDown(object sender, KeyEventArgs e)
@@ -77,21 +82,19 @@ namespace UAS_MES_NEW.Make
             UpdateSN("L", SN.Text.Trim());
 
             ShowMsg(1, $"开始测试");
+
+            int cSPort = Convert.ToInt32(ProductList.Text.Trim().Split(':')[1]);
             int iSPort = Convert.ToInt32(IPList.Text.Trim().Split(':')[1]);
             var tester = new CameraIperfTester(
                 timeOut: TestTime.Text.Trim(),
-                cameraIp: ProductList.Text.Trim(),
-                cameraPort: 23,
+                cameraIp: ProductList.Text.Trim().Split(':')[0],
+                cameraPort: cSPort,
                 username: Account.Text.Trim(),
                 password: ProductList.Text.Trim(),
                 iperfServerIp: IPList.Text.Trim().Split(':')[0],
                 iperfServerPort: iSPort
             );
 
-            /*string upRate = tester.ParseIperfBitrate("C:\\Users\\MI\\Desktop\\testEquiment\\吞吐量\\251017010;13629_down.log");
-            string downRate = tester.ParseIperfBitrate("C:\\Users\\MI\\Desktop\\testEquiment\\吞吐量\\251017010;13629_down.log");
-            Console.WriteLine();*/
-
             string Msg = tester.TelnetConnect();
             if (Msg.Substring(0, 2) != "OK")
             {
@@ -108,13 +111,14 @@ namespace UAS_MES_NEW.Make
             }
 
             //string[] comList = new string[] {
-            //    "killall iperf3_mstar",
-            //    "cp /mnt/tf/usb1_1/iperf3_mstar/var/tmp/ -f",
-            //    "chmod a+x /var/tmp/iperf3_mstar",
-            //    $"/var/tmp/iperf3_mstar -s -p {iSPort} -i 1 &"
+            //    "killall iperf3",
+            //    $"iperf3 -s -p {iSPort} -i 1&"
             //};
+
             string[] comList = new string[] {
-                $"iperf3 -s -p {iSPort} -i 1&"
+                "cd /tmp/",
+                "ls iperf3_mstar",
+                "chmod a+x iperf3_mstar"
             };
 
             Msg = tester.StartIperfTest(SN.Text.Trim(), ExePath.Text.Trim(), logsPath, comList);
@@ -123,7 +127,7 @@ namespace UAS_MES_NEW.Make
                 ShowMsg(0, $"iperf3启动失败,{Msg}");
                 return;
             }
-            string upRate = Msg.Split('|')[0];
+            string upRate = Msg.Split('|')[0].Split(',')[1];
             string downRate = Msg.Split('|')[1];
             ShowMsg(1, $"OK,上行速率: {upRate},下行速率: {downRate}");
             ResMax.Text = upRate;
@@ -290,14 +294,18 @@ namespace UAS_MES_NEW.Make
                         WriteStream(_telnetStream, comItem);
                         ReadStream(_telnetStream);
                     }
-
                     Thread.Sleep(1000); // 等服务端启动
 
+                    string serverStartLog = Path.Combine(logDirectory, $"{SN}_start.log");
+                    RunIperfClient($"./iperf3_mstar -s -p {iperfServerPort} -i l&", iperfPath, serverStartLog);
+
                     string upLog = Path.Combine(logDirectory, $"{SN}_up.log");
                     string downLog = Path.Combine(logDirectory, $"{SN}_down.log");
+                    //RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
+                    //RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
 
-                    RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
-                    RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
+                    RunIperfClient($"./iperf3_mstar -c {cameraIp} -p {iperfServerPort} -i l -b 100M -t 10 -R", iperfPath, upLog);
+                    RunIperfClient($"./iperf3_mstar -c {cameraIp} -p {iperfServerPort} -i l -b 100M -t 10", iperfPath, downLog);
 
                     string upRate = ParseIperfBitrate(upLog);
                     string downRate = ParseIperfBitrate(downLog);
@@ -364,16 +372,36 @@ namespace UAS_MES_NEW.Make
                     RedirectStandardOutput = true,
                     RedirectStandardError = true,
                     UseShellExecute = false,
-                    CreateNoWindow = true
+                    CreateNoWindow = true,
+                    WorkingDirectory = Path.GetDirectoryName(path)
                 };
-
                 using (var process = Process.Start(psi))
                 {
-                    string output = process.StandardOutput.ReadToEnd();
-                    string error = process.StandardError.ReadToEnd();
-                    process.WaitForExit(5000); // 最多等 15 秒
+                    StringBuilder outputBuilder = new StringBuilder();
+                    StringBuilder errorBuilder = new StringBuilder();
+
+                    process.OutputDataReceived += (sender, e) =>
+                    {
+                        if (!string.IsNullOrEmpty(e.Data))
+                        {
+                            outputBuilder.AppendLine(e.Data);
+                        }
+                    };
+
+                    process.ErrorDataReceived += (sender, e) =>
+                    {
+                        if (!string.IsNullOrEmpty(e.Data))
+                        {
+                            errorBuilder.AppendLine(e.Data);
+                        }
+                    };
+
+                    process.BeginOutputReadLine();
+                    process.BeginErrorReadLine();
+
+                    process.WaitForExit();
 
-                    File.WriteAllText(logPath, output + Environment.NewLine + error);
+                    File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
                 }
             }
             public string ParseIperfBitrate(string logPath)
@@ -408,10 +436,10 @@ namespace UAS_MES_NEW.Make
                         rVal2 = match.Groups[2].Value;
                     }
                 }
-                double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
-                double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
+                //double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
+                //double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
 
-                return num2.ToString() + rVal2.Split(' ')[1];
+                return rVal2;
             }
 
             private void WriteStream(NetworkStream stream, string text)