diff --git a/Rs.DeweyTester/Commom/VirtualBarCode.cs b/Rs.DeweyTester/Commom/VirtualBarCode.cs index 47e447e..8e66b07 100644 --- a/Rs.DeweyTester/Commom/VirtualBarCode.cs +++ b/Rs.DeweyTester/Commom/VirtualBarCode.cs @@ -27,5 +27,14 @@ namespace Rs.MotionPlat.Commom { barCode = 0; } + + public static string NumCode + { + get + { + barCode++; + return barCode.ToString().PadLeft(18, '0'); + } + } } } diff --git a/Rs.DeweyTester/Controls/UFixture.cs b/Rs.DeweyTester/Controls/UFixture.cs index 2e85aaf..f6adf36 100644 --- a/Rs.DeweyTester/Controls/UFixture.cs +++ b/Rs.DeweyTester/Controls/UFixture.cs @@ -54,7 +54,7 @@ namespace Rs.MotionPlat string logFileName = ""; string regstr = tf.Index+"_(\\d{0,10}).txt"; //打印日志 - string logDir = $"d:\\log\\debug\\{DateTime.Now.ToString("yyyyMMdd")}"; + string logDir = $"d:\\log\\debug\\{DateTime.Now.ToString("yyyyMMdd")}\\{tf.Index}"; if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); diff --git a/Rs.DeweyTester/Entitys/TestFixtureManager.cs b/Rs.DeweyTester/Entitys/TestFixtureManager.cs index a401db8..9332a57 100644 --- a/Rs.DeweyTester/Entitys/TestFixtureManager.cs +++ b/Rs.DeweyTester/Entitys/TestFixtureManager.cs @@ -13,6 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -22,6 +23,7 @@ using System.Threading; using System.Threading.Tasks; using System.Web; using System.Windows.Forms; +using static NPOI.HSSF.Util.HSSFColor; namespace Rs.MotionPlat.Entitys { @@ -60,20 +62,79 @@ namespace Rs.MotionPlat.Entitys Homing } + public enum EFixtureState + { + /// + /// 无产品 + /// + NoProduct, + /// + /// 产品已放入 + /// + InProducted, + /// + /// 产品测试中 + /// + Testing, + /// + /// 产品测试完成 + /// + TestFinished + } + + + enum ETestFixtureFlowStep + { + 等待治具连接, + 查询治具状态, + 查询报警代码, + 报警代码处理, + 等待治具状态返回, + 启动测试, + 等待启动测试返回结果, + 获取测试结果, + 等待测试结果 + } + + + /// /// 测试治具 /// - public class TestFixture:INotifyPropertyChanged + public class TestFixture { + private ETestFixtureFlowStep step = ETestFixtureFlowStep.等待治具连接; + List data = new List(); bool exit = false; public TestFixture() { //PrintCommunitionLog(); - QueryStatus(); + //QueryStatus(); StartRecive(); + BusinessDeal(); } - public event Action OnProChange; + + private EFixtureState mState = EFixtureState.NoProduct; + + /// + /// 治具内部状态 + /// + public EFixtureState State + { + get { return mState; } + set { mState = value; } + } + + private string cmdResult = string.Empty; + Stopwatch waitTimer = new Stopwatch(); + bool bAlertAlarm = false; + /// + /// 启动成功事件 + /// + private ManualResetEvent startTestOkEvent = new ManualResetEvent(false); + + #region private field private TestProduct _Product; @@ -85,37 +146,12 @@ namespace Rs.MotionPlat.Entitys if (_Product != value) { _Product = value; - if(OnProChange != null) - { - OnProChange(nameof(Product), value); - } } } } - public void AddTestRecordToProduct() - { - if (Product != null && !string.IsNullOrEmpty(Result)) - { - Product.AddResult(this.Index, "", ""); - } - } - - public void Clear() - { - this.Product = null; - //this.Result = ""; - } - - public void ClearData() - { - this.Product = null; - this.Result = ""; - this.PassCount = 0; - this.TotalCount = 0; - this.LastCT = 0; - this.Yield = 0; - } + + private int _Index; /// @@ -128,10 +164,6 @@ namespace Rs.MotionPlat.Entitys if (_Index != value) { _Index = value; - if (OnProChange != null) - { - OnProChange(nameof(Index), value); - } } } } @@ -148,7 +180,6 @@ namespace Rs.MotionPlat.Entitys if (_MachineID != value) { _MachineID = value; - OnPropertyChanged(nameof(MachineID)); } } } @@ -179,12 +210,6 @@ namespace Rs.MotionPlat.Entitys if(_Status != value) { _Status = value; - OnProChange?.Invoke(nameof(Status), value); - //OnPropertyChanged(nameof(Status)); - //if (OnProChange != null) - //{ - // OnProChange(nameof(Status), value); - //} } } @@ -211,8 +236,6 @@ namespace Rs.MotionPlat.Entitys if (_LastCT != value) { _LastCT = value; - OnProChange?.Invoke(nameof(LastCT), value); - //OnPropertyChanged(nameof(LastCT)); } } @@ -231,7 +254,6 @@ namespace Rs.MotionPlat.Entitys //if (_Enable != value) { _Enable = value; - OnProChange?.Invoke(nameof(Enable), value); } } @@ -249,7 +271,6 @@ namespace Rs.MotionPlat.Entitys if (_PassCount != value) { _PassCount = value; - OnPropertyChanged(nameof(PassCount)); } } @@ -267,7 +288,6 @@ namespace Rs.MotionPlat.Entitys if (_TotalCount != value) { _TotalCount = value; - OnPropertyChanged(nameof(TotalCount)); } } @@ -285,7 +305,6 @@ namespace Rs.MotionPlat.Entitys if (_Yield != value) { _Yield = value; - OnProChange?.Invoke(nameof(Yield), value); } } @@ -303,8 +322,6 @@ namespace Rs.MotionPlat.Entitys //if (_Result != value) { _Result = value; - // OnPropertyChanged(nameof(Result)); - OnProChange?.Invoke(nameof(Result), value); } } @@ -332,90 +349,44 @@ namespace Rs.MotionPlat.Entitys _socket = socket; } - List data = new List(); - public int Send(string content) - { - byte[] data=Encoding.ASCII.GetBytes(content); - return _socket.Send(data); - } - - //ManualResetEvent dataEvent=new ManualResetEvent(true); - AutoResetEvent dataEvent = new AutoResetEvent(true); - - public event PropertyChangedEventHandler PropertyChanged; - - protected virtual void OnPropertyChanged(string propertyName) + /// + /// 断开连接 + /// + public void DisConnect() { - if (PropertyChanged != null) + Connected = false; + if(_socket!=null ) { - PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } - - public void SetEvent() - { - dataEvent.Set(); + _socket.Close(); + _socket.Dispose(); + _socket = null; + } } - public void QueryStatus() + + public int Send(string content) { - Task.Run(() => { - while (!exit) - { - if(!Connected) - { - Thread.Sleep(50); - continue; - } - while (true) - { - if (dataEvent.WaitOne(100)) - { - break; - } - else - { - Thread.Sleep(100); - } - } - Send("Status$"); - //dataEvent.Reset(); - if (CheckPrintLog()) - { - AddLog($"<<< TC{Index} status$"); - //logs.Enqueue($"<<< TC{Index} status$"); - //lock(this) - //{ - // File.AppendAllText($"d:\\1\\{Index}.txt", $"<<< 治具{Index} status$\r\n"); - //} - - } - Thread.Sleep(100); - } - }); + byte[] data=Encoding.ASCII.GetBytes(content); + if(_socket!=null && _socket.Connected) + { + return _socket.Send(data); + } + return 0; } + #endregion /// /// 通知治具回原 /// public void Home() { - while (true) + if(Send($"Reset$")>0) { - if (dataEvent.WaitOne(100)) - { - break; - } - else - { - Thread.Sleep(100); - } + AddLog($"<<< TC{Index} Reset$"); } - Send($"Reset$"); - //Result = ""; - if (CheckPrintLog()) + else { - AddLog($"<<< TC{Index} Reset$"); + DisConnect(); } } @@ -424,73 +395,72 @@ namespace Rs.MotionPlat.Entitys /// public void Pause() { - while (true) + if (Send($"Pause#1$") > 0) { - if (dataEvent.WaitOne(100)) - { - break; - } - else - { - Thread.Sleep(100); - } + AddLog($"<<< TC{Index} Pause#1$"); } - Send($"Pause#1$"); - if (CheckPrintLog()) + else { - AddLog($"<<< TC{Index} Pause#1$"); + DisConnect(); } } /// /// 通知治具启动测试 /// - public void StartTest(TestProduct _product, string sn = "") + public bool StartTest(TestProduct willTestDut, string sn = "") { - while (true) - { - if (dataEvent.WaitOne(100)) - { - break; - } - else - { - Thread.Sleep(100); - } - } - Product=_product; - //先把侧相机数据清空 - if(!GlobalVar.IsSimTest) - { - VisionHelper.sideCameraVision.ClearQueue(this.Index); - } - int noise = GlobalVar.Noise ? 1 : 0; - int mtcp=GlobalVar.Mtcp ? 1 : 0; - int isFirstFixture = IsFirstFixture ? 1 : 0; - string msg = string.Empty; - if(string.IsNullOrEmpty(sn)) - { - //StartTest#SN#Machine#User#Config#Lot#Mode#SiteID#ProjectID#RetryMode#Mes#Mtcp#configD#DualMode#TakeIndex#SubLotName$ - //msg = $"StartTest#{Product.SN}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; - string RetryMode = "T1"; - if (Product.TestNum > 0) - { - RetryMode = $"R{Product.TestNum}"; - } - msg = $"StartTest#{Product.SN}#{GlobalVar.MachineID}#op#{GlobalVar.Config}#{GlobalVar.LotName}#{GlobalVar.TestMode}#{GlobalVar.SiteID}#{GlobalVar.ProjectID}#{RetryMode}#0#{mtcp}#{GlobalVar.ConfigName}#0#{Product.From}#{GlobalVar.SubLotName}#{noise}#{isFirstFixture}#{GlobalVar.RelCategory}#{GlobalVar.RelCp}#{GlobalVar.HostType}$"; - } - else - { - msg = $"StartTest#{sn}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; - } - LogHelper.Debug(msg); - // string msg = $"StartTest#123#{GlobalVar.MachineID}#op#{GlobalVar.Config}#Lot#Mode#SiteID#ProjectID#RetryMode#{mtcp}#Mtcp#configD#DualMode#R1C1#SubLotName#{noise}$"; - //msg = $"StartTest#{Product.SN}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; - Send(msg); - if(CheckPrintLog()) - { - AddLog($"<<< TC{Index} {msg}"); - } + startTestOkEvent.Reset(); + Product = willTestDut; + Result = String.Empty; + State = EFixtureState.InProducted; + return startTestOkEvent.WaitOne(5 * 1000); + #region 注释掉旧逻辑 + //while (true) + //{ + // if (dataEvent.WaitOne(100)) + // { + // break; + // } + // else + // { + // Thread.Sleep(100); + // } + //} + //Product=_product; + ////先把侧相机数据清空 + //if(!GlobalVar.IsSimTest) + //{ + // VisionHelper.sideCameraVision.ClearQueue(this.Index); + //} + //int noise = GlobalVar.Noise ? 1 : 0; + //int mtcp=GlobalVar.Mtcp ? 1 : 0; + //int isFirstFixture = IsFirstFixture ? 1 : 0; + //string msg = string.Empty; + //if(string.IsNullOrEmpty(sn)) + //{ + // //StartTest#SN#Machine#User#Config#Lot#Mode#SiteID#ProjectID#RetryMode#Mes#Mtcp#configD#DualMode#TakeIndex#SubLotName$ + // //msg = $"StartTest#{Product.SN}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; + // string RetryMode = "T1"; + // if (Product.TestNum > 0) + // { + // RetryMode = $"R{Product.TestNum}"; + // } + // msg = $"StartTest#{Product.SN}#{GlobalVar.MachineID}#op#{GlobalVar.Config}#{GlobalVar.LotName}#{GlobalVar.TestMode}#{GlobalVar.SiteID}#{GlobalVar.ProjectID}#{RetryMode}#0#{mtcp}#{GlobalVar.ConfigName}#0#{Product.From}#{GlobalVar.SubLotName}#{noise}#{isFirstFixture}#{GlobalVar.RelCategory}#{GlobalVar.RelCp}#{GlobalVar.HostType}$"; + //} + //else + //{ + // msg = $"StartTest#{sn}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; + //} + //LogHelper.Debug(msg); + //// string msg = $"StartTest#123#{GlobalVar.MachineID}#op#{GlobalVar.Config}#Lot#Mode#SiteID#ProjectID#RetryMode#{mtcp}#Mtcp#configD#DualMode#R1C1#SubLotName#{noise}$"; + ////msg = $"StartTest#{Product.SN}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; + //Send(msg); + //if(CheckPrintLog()) + //{ + // AddLog($"<<< TC{Index} {msg}"); + //} + #endregion } private ConcurrentQueue logs = new ConcurrentQueue(); public void StartRecive() @@ -521,8 +491,6 @@ namespace Rs.MotionPlat.Entitys data.Clear(); } } - //string data = Encoding.ASCII.GetString(bytes, 0, len); - //MessageQueue.Instance.Insert(data); } else { @@ -547,161 +515,160 @@ namespace Rs.MotionPlat.Entitys if(data!=null&&data.Count>0) { string content = Encoding.ASCII.GetString(data.ToArray()); - if (CheckPrintLog()) - { - AddLog($">>> TC{Index},{content}"); - } + AddLog($">>> TC{Index},{content}"); string[] items = content.Split('#'); string command = items[0]; switch (command) { case "Status": - switch (items[1]) - { - case "0": - //非就绪状态,查询错误代码 - Send("ErrorCode$"); - if (CheckPrintLog()) - { - //lock (this) - //{ - // File.AppendAllText($"d:\\1\\{Index}.txt", $"<<< 治具{Index} ErrorCode$\r\n"); - //} + cmdResult = content; + //switch (items[1]) + //{ + // case "0": + // //非就绪状态,查询错误代码 + // Send("ErrorCode$"); + // if (CheckPrintLog()) + // { + // //lock (this) + // //{ + // // File.AppendAllText($"d:\\1\\{Index}.txt", $"<<< 治具{Index} ErrorCode$\r\n"); + // //} - AddLog($"<<< TC{Index} ErrorCode$"); - } - break; - case "1": - //就绪状态,如果有产品就查询测试结果 - if(Status == ETestFixtureStatus.Testing ||(Status== ETestFixtureStatus.IDLE && Product!=null &&String.IsNullOrEmpty(Result))) - { - Send("Result$"); - LogHelper.Debug($"<<< TC{Index} Result$,Status={Status},Result={Result}"); - if (CheckPrintLog()) - { - //lock (this) - //{ - // File.AppendAllText($"d:\\1\\{Index}.txt", $"<<< 治具{Index} Result$\r\n"); - //} - AddLog($"<<< TC{Index} Result$"); - } - } - else - { - dataEvent.Set(); - Status = ETestFixtureStatus.IDLE; - } - break; - case "2": - dataEvent.Set(); - Status = ETestFixtureStatus.Homing; - break; - case "3": - //侧相机测试失败 - AlarmEntity alarmInfo = AlarmCollection.Get(AlarmConstID.DUT未放好).Transform(Index); - DevLog.EventTracker("ERROR START", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); - EButtonType sideCameraSelect = Msgbox.ShowTipDialog(EButtonType.Retry | EButtonType.Cancel, $"Please check DUT{Index} is placed ok,ok continue test click retry,stop test click Cancel","warn",true); - if(sideCameraSelect== EButtonType.Retry) - { - string msg = "ContinueTest#1$"; - Send(msg); - } - else if(sideCameraSelect== EButtonType.Cancel) - { - string msg = "ContinueTest#0$"; - Send(msg); - } - dataEvent.Set(); - DevLog.EventTracker("ERROR END", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); - break; - } + // AddLog($"<<< TC{Index} ErrorCode$"); + // } + // break; + // case "1": + // //就绪状态,如果有产品就查询测试结果 + // if(Status == ETestFixtureStatus.Testing ||(Status== ETestFixtureStatus.IDLE && Product!=null &&String.IsNullOrEmpty(Result))) + // { + // Send("Result$"); + // LogHelper.Debug($"<<< TC{Index} Result$,Status={Status},Result={Result}"); + // if (CheckPrintLog()) + // { + // //lock (this) + // //{ + // // File.AppendAllText($"d:\\1\\{Index}.txt", $"<<< 治具{Index} Result$\r\n"); + // //} + // AddLog($"<<< TC{Index} Result$"); + // } + // } + // else + // { + // dataEvent.Set(); + // Status = ETestFixtureStatus.IDLE; + // } + // break; + // case "2": + // dataEvent.Set(); + // Status = ETestFixtureStatus.Homing; + // break; + // case "3": + // //侧相机测试失败 + // AlarmEntity alarmInfo = AlarmCollection.Get(AlarmConstID.DUT未放好).Transform(Index); + // DevLog.EventTracker("ERROR START", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); + // EButtonType sideCameraSelect = Msgbox.ShowTipDialog(EButtonType.Retry | EButtonType.Cancel, $"Please check DUT{Index} is placed ok,ok continue test click retry,stop test click Cancel","warn",true); + // if(sideCameraSelect== EButtonType.Retry) + // { + // string msg = "ContinueTest#1$"; + // Send(msg); + // } + // else if(sideCameraSelect== EButtonType.Cancel) + // { + // string msg = "ContinueTest#0$"; + // Send(msg); + // } + // dataEvent.Set(); + // DevLog.EventTracker("ERROR END", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); + // break; + //} break; case "StartTest": + cmdResult = content; //if (writeLogs.Contains(Index)) //{ // LogHelper.Info($">>> 治具{Index} StartTest"); //} - this.Result = ""; - this.StartTestTime=DateTime.Now; - this.Status= ETestFixtureStatus.Testing; - dataEvent.Set(); + //this.Result = ""; + //this.StartTestTime=DateTime.Now; + //this.Status= ETestFixtureStatus.Testing; + //dataEvent.Set(); break; case "Result": + cmdResult = content; //if(items!=null && items.Length>=6) - { - lock(this) - { - if (Product != null) - { - LogHelper.Debug($"治具{Index}测试完成,测试总数量由{TotalCount}增加到{TotalCount + 1}"); - if (items[2] == "1") - { - Result = "PASS"; - PassCount++; - } - else - { - Result = "NG"; - } - Product.Result = Result; - Product.Bin = items[6]; - this.EndTestTime = DateTime.Now; - this.LastCT = (EndTestTime - StartTestTime).TotalSeconds; - TotalCount++; - Yield = (double)((double)PassCount / TotalCount); - AddTestRecordToProduct(); - DevLog.UnitTracker(this); - //this.Product.AddResult(this.Index, Result, items[6]); - } - Status = ETestFixtureStatus.IDLE; - string csvContent = string.Join(",", items[3], items[4], items[5]); - LogHelper.Debug($"Result:{items[2]},{items[3]}"); - DevLog.Summary(CsvTitle, csvContent); - dataEvent.Set(); - } - } + //{ + // lock(this) + // { + // if (Product != null) + // { + // LogHelper.Debug($"治具{Index}测试完成,测试总数量由{TotalCount}增加到{TotalCount + 1}"); + // if (items[2] == "1") + // { + // Result = "PASS"; + // PassCount++; + // } + // else + // { + // Result = "NG"; + // } + // Product.Result = Result; + // Product.Bin = items[6]; + // this.EndTestTime = DateTime.Now; + // this.LastCT = (EndTestTime - StartTestTime).TotalSeconds; + // TotalCount++; + // Yield = (double)((double)PassCount / TotalCount); + // AddTestRecordToProduct(); + // DevLog.UnitTracker(this); + // //this.Product.AddResult(this.Index, Result, items[6]); + // } + // Status = ETestFixtureStatus.IDLE; + // string csvContent = string.Join(",", items[3], items[4], items[5]); + // LogHelper.Debug($"Result:{items[2]},{items[3]}"); + // DevLog.Summary(CsvTitle, csvContent); + // dataEvent.Set(); + // } + //} break; case "ErrorCode": + cmdResult = content; //if (writeLogs.Contains(Index)) //{ // LogHelper.Info($">>> 治具{Index} ErrorCode"); //} - string code = items[1]; - if(code!="0") - { - if(Status != ETestFixtureStatus.Warning) - { - Status = ETestFixtureStatus.Warning; - Task.Run(() => { - string errInfo = $"tc{Index} test,code:{items[1]},desc:{items[2]}"; - MessageQueue.Instance.Warn(errInfo); - Msgbox.ShowTipDialog(EButtonType.Ok, errInfo,"testfixture error",true); - }); - } - } - else - { - Status = ETestFixtureStatus.Testing; - } - dataEvent.Set(); + //string code = items[1]; + //if(code!="0") + //{ + // if(Status != ETestFixtureStatus.Warning) + // { + // Status = ETestFixtureStatus.Warning; + // Task.Run(() => { + // string errInfo = $"tc{Index} test,code:{items[1]},desc:{items[2]}"; + // MessageQueue.Instance.Warn(errInfo); + // Msgbox.ShowTipDialog(EButtonType.Ok, errInfo,"testfixture error",true); + // }); + // } + //} + //else + //{ + // Status = ETestFixtureStatus.Testing; + //} + //dataEvent.Set(); break; case "Grip": - dataEvent.Set(); + break; case "Vlog": //dataEvent.Set(); DevLog.Breakdown(items[1], items[2]); break; case "Reset": - dataEvent.Set(); break; case "GR": VisionHelper.sideCameraVision.Grab(Index, items[1]); //dataEvent.Set(); break; case "Pause": - dataEvent.Set(); break; case "ReadIO": // dataEvent.Set(); @@ -762,6 +729,313 @@ namespace Rs.MotionPlat.Entitys } } + /// + /// 业务数据处理 + /// + private void BusinessDeal() + { + step = ETestFixtureFlowStep.等待治具连接; + Task.Run(() => { + while (true) + { + switch (step) + { + case ETestFixtureFlowStep.等待治具连接: + { + if (Connected) + { + step = ETestFixtureFlowStep.查询治具状态; + } + } + break; + case ETestFixtureFlowStep.查询治具状态: + { + cmdResult = ""; + if (Send("Status$") > 0) + { + AddLog("<<< Status$"); + waitTimer.Restart(); + step = ETestFixtureFlowStep.等待治具状态返回; + } + else + { + //发送命令失败, + Msg.ShowError("Status$ send fail"); + DisConnect(); + step = ETestFixtureFlowStep.等待治具连接; + } + } + break; + + case ETestFixtureFlowStep.等待治具状态返回: + { + if (waitTimer.ElapsedMilliseconds > 10 * 1000) + { + Msg.ShowError($"TC{Index} disconnected"); + DisConnect(); + //超时未返回结果报警 + step = ETestFixtureFlowStep.等待治具连接; + } + else if (!string.IsNullOrEmpty(cmdResult)) + { + string ret = cmdResult.Replace("Status#", ""); + switch (ret) + { + case "0": + { + step = ETestFixtureFlowStep.查询报警代码; + } + break; + case "1": + { + //就绪状态,如果有产品就查询测试结果 + if ((State == EFixtureState.Testing) && (Status == ETestFixtureStatus.Testing || (Status == ETestFixtureStatus.IDLE && Product != null && String.IsNullOrEmpty(Result)))) + { + step = ETestFixtureFlowStep.获取测试结果; + } + else + { + Status = ETestFixtureStatus.IDLE; + if (State == EFixtureState.InProducted) + { + step = ETestFixtureFlowStep.启动测试; + } + else + { + step = ETestFixtureFlowStep.查询治具状态; + } + } + } + break; + case "2": + { + Status = ETestFixtureStatus.Homing; + step = ETestFixtureFlowStep.查询治具状态; + } + break; + case "3": + { + if (!bAlertAlarm) + { + bAlertAlarm = true; + //报警 + Task.Run(() => { + //侧相机测试失败 + AlarmEntity alarmInfo = AlarmCollection.Get(AlarmConstID.DUT未放好).Transform(Index); + DevLog.EventTracker("ERROR START", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); + EButtonType sideCameraSelect = Msgbox.ShowTipDialog(EButtonType.Retry | EButtonType.Cancel, $"Please check DUT{Index} is placed ok,ok continue test click retry,stop test click Cancel", "warn", true); + bAlertAlarm = false; + if (sideCameraSelect == EButtonType.Retry) + { + string msg = "ContinueTest#1$"; + Send(msg); + } + else if (sideCameraSelect == EButtonType.Cancel) + { + string msg = "ContinueTest#0$"; + Send(msg); + } + DevLog.EventTracker("ERROR END", alarmInfo.AlarmID, alarmInfo.EventTrackerDesc, alarmInfo.EN); + }); + } + step = ETestFixtureFlowStep.查询治具状态; + } + break; + default: + break; + } + + } + } + break; + case ETestFixtureFlowStep.查询报警代码: + { + cmdResult = ""; + if (Send("ErrorCode$") > 0) + { + AddLog($"<<< TC{Index} ErrorCode$"); + waitTimer.Restart(); + step = ETestFixtureFlowStep.报警代码处理; + } + else + { + Msg.ShowError("ErrorCode send fail"); + DisConnect(); + step = ETestFixtureFlowStep.等待治具连接; + } + + } + break; + case ETestFixtureFlowStep.报警代码处理: + { + if (waitTimer.ElapsedMilliseconds > 10 * 1000) + { + Msg.ShowError($"TC{Index} disconnected"); + DisConnect(); + //超时未返回结果报警 + step = ETestFixtureFlowStep.等待治具连接; + } + else if (!string.IsNullOrEmpty(cmdResult)) + { + string[] items = cmdResult.Split('#'); + string code = cmdResult.Split('#')[1]; + if (code != "0") + { + if (Status != ETestFixtureStatus.Warning) + { + Status = ETestFixtureStatus.Warning; + Task.Run(() => { + string errInfo = $"tc{Index} test,code:{items[1]},desc:{items[2]}"; + MessageQueue.Instance.Warn(errInfo); + Msgbox.ShowTipDialog(EButtonType.Ok, errInfo, "testfixture error", true); + }); + } + } + else + { + Status = ETestFixtureStatus.Testing; + } + step = ETestFixtureFlowStep.查询治具状态; + } + } + break; + case ETestFixtureFlowStep.启动测试: + { + if (Product != null) + { + cmdResult = ""; + string RetryMode = "T1"; + if (Product.TestNum > 0) + { + RetryMode = $"R{Product.TestNum}"; + } + int noise = GlobalVar.Noise ? 1 : 0; + int mtcp = GlobalVar.Mtcp ? 1 : 0; + int isFirstFixture = IsFirstFixture ? 1 : 0; + string msg = string.Empty; + msg = $"StartTest#{Product.SN}#{GlobalVar.MachineID}#op#{GlobalVar.Config}#{GlobalVar.LotName}#{GlobalVar.TestMode}#{GlobalVar.SiteID}#{GlobalVar.ProjectID}#{RetryMode}#0#{mtcp}#{GlobalVar.ConfigName}#0#{Product.From}#{GlobalVar.SubLotName}#{noise}#{isFirstFixture}#{GlobalVar.RelCategory}#{GlobalVar.RelCp}#{GlobalVar.HostType}$"; + //string sn = VirtualBarCode.Code; + //string msg = $"StartTest#{sn}#MS001#OP#DXD#GRR_GRR_DXD_202203120320#Production#LF1#MOS#T1#0#0#Paint#0#R1C5#SP0012#1$"; + LogHelper.Debug(msg); + if (Send(msg) > 0) + { + startTestOkEvent.Set(); + State = EFixtureState.Testing; + Status = ETestFixtureStatus.Testing; + AddLog($"<<< TC{Index} {msg}"); + waitTimer.Restart(); + step = ETestFixtureFlowStep.等待启动测试返回结果; + } + else + { + Msg.ShowError("StartTest send fail"); + DisConnect(); + step = ETestFixtureFlowStep.等待治具连接; + } + } + else + { + Msg.ShowError($"TC{Index} hasn't product,cann't test"); + } + } + break; + case ETestFixtureFlowStep.等待启动测试返回结果: + { + if (waitTimer.ElapsedMilliseconds > 10 * 1000) + { + Msg.ShowError($"TC{Index} disconnected"); + DisConnect(); + //超时未返回结果报警 + step = ETestFixtureFlowStep.等待治具连接; + } + else + { + StartTestTime = DateTime.Now; + Thread.Sleep(1000); + step = ETestFixtureFlowStep.查询治具状态; + } + } + break; + case ETestFixtureFlowStep.获取测试结果: + { + cmdResult = ""; + if (Send("Result$") > 0) + { + waitTimer.Restart(); + AddLog($"<<< TC{Index} Result$"); + step = ETestFixtureFlowStep.等待测试结果; + } + else + { + Msg.ShowError("Result send fail"); + DisConnect(); + step = ETestFixtureFlowStep.查询治具状态; + } + } + break; + case ETestFixtureFlowStep.等待测试结果: + { + if (waitTimer.ElapsedMilliseconds > 10 * 1000) + { + Msg.ShowError($"TC{Index} disconnected"); + DisConnect(); + //超时未返回结果报警 + step = ETestFixtureFlowStep.等待治具连接; + } + else if (!string.IsNullOrEmpty(cmdResult)) + { + string[] items = cmdResult.Split('#'); + if (Product != null) + { + State = EFixtureState.TestFinished; + LogHelper.Debug($"治具{Index}测试完成,测试总数量由{TotalCount}增加到{TotalCount + 1}"); + + //if (GlobalVar.SimulateTestYield < 100) + //{ + // Random rnd = new Random(); + // int randomNumber = rnd.Next(0, 100); + // items[2] = randomNumber < (100 - GlobalVar.SimulateTestYield) ? "0" : "1"; + //} + //else + //{ + // items[2] = "1"; + //} + + if (items[2] == "1") + { + Result = "PASS"; + PassCount++; + } + else + { + Result = "NG"; + } + Product.Result = Result; + Product.Bin = items[6]; + this.EndTestTime = DateTime.Now; + this.LastCT = (EndTestTime - StartTestTime).TotalSeconds; + TotalCount++; + Yield = (double)((double)PassCount / TotalCount); + AddTestRecordToProduct(); + DevLog.UnitTracker(this); + //this.Product.AddResult(this.Index, Result, items[6]); + } + Status = ETestFixtureStatus.IDLE; + string csvContent = string.Join(",", items[3], items[4], items[5]); + LogHelper.Debug($"Result:{items[2]},{items[3]}"); + DevLog.Summary(CsvTitle, csvContent); + step = ETestFixtureFlowStep.查询治具状态; + } + } + break; + default: + break; + } + Thread.Sleep(100); + } + }); + } + public void AddLog(string log) { if(logs.Count>500) @@ -793,59 +1067,32 @@ namespace Rs.MotionPlat.Entitys } return msg.ToString(); } - //private void PrintCommunitionLog() - //{ - // Task.Run(() => { - // while (true) - // { - // if(logs.Count > 0) - // { - // bool ret = logs.TryDequeue(out string log); - // if (ret) - // { - // //打印日志 - // string logDir = $"d:\\Communition\\{DateTime.Now.ToString("yyyyMMdd")}"; - // if(!Directory.Exists(logDir)) - // { - // Directory.CreateDirectory(logDir); - // } - // string logFileName = $"{logDir}\\{Index}.txt"; - // File.AppendAllText(logFileName, $"{DateTime.Now.ToString("HH:mm:ss fff")} {log}\r\n"); - // } - // } - // else - // { - // Thread.Sleep(100); - // } - // } - // }); - //} - /// - /// 检测是否需要打印日志 - /// - /// - private bool CheckPrintLog() + public void AddTestRecordToProduct() { - return true; - switch (Index) + if (Product != null && !string.IsNullOrEmpty(Result)) { - case 1: - return GlobalVar.PrintTC1Communicate; - case 2: - return GlobalVar.PrintTC2Communicate; - case 3: - return GlobalVar.PrintTC3Communicate; - case 4: - return GlobalVar.PrintTC4Communicate; - case 5: - return GlobalVar.PrintTC5Communicate; - case 6: - return GlobalVar.PrintTC6Communicate; - default: return false; + Product.AddResult(this.Index, "", ""); } } + public void Clear() + { + this.Product = null; + State = EFixtureState.NoProduct; + //this.Result = ""; + } + + public void ClearData() + { + this.Product = null; + this.Result = ""; + this.PassCount = 0; + this.TotalCount = 0; + this.LastCT = 0; + this.Yield = 0; + } + /// /// 夹头夹紧 /// @@ -911,6 +1158,7 @@ namespace Rs.MotionPlat.Entitys return targetPos; } } + public class TestFixtureManager { TestFixture[] testFixtures=new TestFixture[6]; @@ -1015,7 +1263,6 @@ namespace Rs.MotionPlat.Entitys tf.Connected = true; tf.Status = ETestFixtureStatus.None; tf.CsvTitle = items[3]; - tf.SetEvent(); stop = true; break; } diff --git a/Rs.DeweyTester/Flow/NormalFlow/DischargeFlow.cs b/Rs.DeweyTester/Flow/NormalFlow/DischargeFlow.cs index bc4789a..90f577a 100644 --- a/Rs.DeweyTester/Flow/NormalFlow/DischargeFlow.cs +++ b/Rs.DeweyTester/Flow/NormalFlow/DischargeFlow.cs @@ -28,24 +28,18 @@ namespace Rs.MotionPlat.Flow { public enum EDischargeFlowStep { - //开始排料前准备 等待启动, 工作前准备, - //料仓取料 判断是否需要从料仓取料, 进料盘产品定位, 料仓取料, - //治具换料 到治具取料等待位, 等待到治具取料等待位, 等待治具测试完成换料, 治具取料, 治具放料, - //料仓放料 判断是否需要放料到料仓, 料仓放料, - //工作完成到安全位, - //等待工作完成到安全位, 工作完成收料, 等待收料完成 } @@ -560,11 +554,7 @@ namespace Rs.MotionPlat.Flow case EDischargeFlowStep.等待治具测试完成换料: if (NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count==NozzleManager.GetEnableNozzles().Count-1) { - //double curXpos = Ops.GetCurPosition(AxisControl.LoadX); - //if(curXpos-GlobalVar.FixtureSafePosX>1) - //{ - // DischargeModuleGoSafePosFlow.Instance.GoSafePostion(ESafePosSide.PlaceToStock); - //} + logInfo = GetClassName()+ $"检测到需要下料的吸嘴个数为:{NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count},准备下料"; flowStep = EDischargeFlowStep.判断是否需要放料到料仓; } else @@ -661,11 +651,11 @@ namespace Rs.MotionPlat.Flow //lastFixtureIndex = curFixture.Index == checkFixtureList.Max() ? checkFixtureList.Min()-1 : curFixture.Index; //lastFixtureIndex = curFixture.Index == 6 ? 0 : curFixture.Index; - int num = TestFixtureManager.Instance.GetHaveProductFixtureList().Count(); + //int num = TestFixtureManager.Instance.GetHaveProductFixtureList().Count(); int tounloadNum = NozzleManager.GetNozzlesByStatus(ENozzleStatus.ToUnload).Count(); if ( tounloadNum==NozzleManager.GetEnableNozzles().Count - 1 - || num==0 + //|| num==0 || NozzleManager.GetToTestNozzle() == null ) //GlobalVar.Clear && ( @@ -920,26 +910,6 @@ namespace Rs.MotionPlat.Flow #endregion - //case EDischargeFlowStep.工作完成到安全位: - // targetPosition.X = GlobalVar.DischargeSafePostionX; - // targetPosition.Y1 = GlobalVar.StockSideY1; - // targetPosition.Y2 = GlobalVar.DischargeSafePostionY2; - - // if(GroupAxisMove.XY1Y2MovePos(targetPosition, GlobalVar.WholeSpeed)) - // { - // flowStep = EDischargeFlowStep.等待工作完成到安全位; - // } - // break; - //case EDischargeFlowStep.等待工作完成到安全位: - // if(Ops.IsStop("LoadX", "LoadY1", "LoadY2")) - // { - // AxisPosPrint.PrintXY1Y2CurrentPos("运动已停止,",GetClassName()); - // if(AxisArrived.LoadXY1Y2IsArrived(targetPosition.X,targetPosition.Y1,targetPosition.Y2)) - // { - // flowStep = EDischargeFlowStep.工作完成收料; - // } - // } - // break; case EDischargeFlowStep.工作完成收料: DischargeModuleGoSafePosFlow.Instance.GoSafePostion(); TakeTrayFlow.Instance.Take(ETrayType.Empty, ETrayType.Ok,true,true); diff --git a/Rs.DeweyTester/Flow/SubFlow/StockTakeFlow.cs b/Rs.DeweyTester/Flow/SubFlow/StockTakeFlow.cs index 20c2041..d508236 100644 --- a/Rs.DeweyTester/Flow/SubFlow/StockTakeFlow.cs +++ b/Rs.DeweyTester/Flow/SubFlow/StockTakeFlow.cs @@ -200,14 +200,14 @@ namespace Rs.MotionPlat.Flow.SubFlow //curNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, TestNum = 0 }; if(GlobalVar.RunSpace) { - curNozzle.Product = new TestProduct() { SN = VirtualBarCode.Code, FromSlotIndex = waitTakeProductSlot.Index, TestNum = 0, From = $"R{waitTakeProductSlot.Row + 1}C{waitTakeProductSlot.Column + 1}" }; + curNozzle.Product = new TestProduct() { SN = VirtualBarCode.NumCode, FromSlotIndex = waitTakeProductSlot.Index, TestNum = 0, From = $"R{waitTakeProductSlot.Row + 1}C{waitTakeProductSlot.Column + 1}" }; } else { string sn = string.Empty; if(GlobalVar.EnableVirtualBarCode) { - sn = VirtualBarCode.Code; + sn = VirtualBarCode.NumCode; } else { diff --git a/Rs.DeweyTester/FormMain.designer.cs b/Rs.DeweyTester/FormMain.designer.cs index e04140e..370ebf1 100644 --- a/Rs.DeweyTester/FormMain.designer.cs +++ b/Rs.DeweyTester/FormMain.designer.cs @@ -1132,7 +1132,7 @@ namespace Rs.MotionPlat this.trayNozzle.HeadText = "Loader picker"; this.trayNozzle.InitSlotStatus = Rs.Controls.ESlotStatus.NotHave; this.trayNozzle.ItemName = null; - this.trayNozzle.LeftSpaceWidth = 20; + this.trayNozzle.LeftSpaceWidth = 0; this.trayNozzle.Location = new System.Drawing.Point(0, 0); this.trayNozzle.Margin = new System.Windows.Forms.Padding(4); this.trayNozzle.Name = "trayNozzle"; @@ -1151,7 +1151,7 @@ namespace Rs.MotionPlat this.trayNozzle.SortDir = Rs.Controls.ESortDir.LeftToRight; this.trayNozzle.Status = null; this.trayNozzle.TabIndex = 4; - this.trayNozzle.TopSpaceHeight = 20; + this.trayNozzle.TopSpaceHeight = 0; this.trayNozzle.DrawTrayAfterEvent += new System.Action>(this.trayDischargeNozzle_DrawTrayAfterEvent); // // groupBox38 diff --git a/Rs.DeweyTester/SysConfig/NozzleConfig.Designer.cs b/Rs.DeweyTester/SysConfig/NozzleConfig.Designer.cs index c0f6041..1578b01 100644 --- a/Rs.DeweyTester/SysConfig/NozzleConfig.Designer.cs +++ b/Rs.DeweyTester/SysConfig/NozzleConfig.Designer.cs @@ -74,8 +74,12 @@ this.panel3 = new System.Windows.Forms.Panel(); this.groupBox13 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.cboxNozzle8 = new System.Windows.Forms.CheckBox(); this.cboxNozzle4 = new System.Windows.Forms.CheckBox(); + this.cboxNozzle7 = new System.Windows.Forms.CheckBox(); this.cboxNozzle3 = new System.Windows.Forms.CheckBox(); + this.cboxNozzle6 = new System.Windows.Forms.CheckBox(); + this.cboxNozzle5 = new System.Windows.Forms.CheckBox(); this.cboxNozzle2 = new System.Windows.Forms.CheckBox(); this.cboxNozzle1 = new System.Windows.Forms.CheckBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); @@ -264,10 +268,6 @@ this.txtPlaceProdcutToStockTrayOffsetHeight = new System.Windows.Forms.TextBox(); this.label33 = new System.Windows.Forms.Label(); this.label27 = new System.Windows.Forms.Label(); - this.cboxNozzle5 = new System.Windows.Forms.CheckBox(); - this.cboxNozzle6 = new System.Windows.Forms.CheckBox(); - this.cboxNozzle7 = new System.Windows.Forms.CheckBox(); - this.cboxNozzle8 = new System.Windows.Forms.CheckBox(); this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip2.SuspendLayout(); this.panelEx2.SuspendLayout(); @@ -646,32 +646,68 @@ this.groupBox3.Name = "groupBox3"; this.groupBox3.TabStop = false; // + // cboxNozzle8 + // + resources.ApplyResources(this.cboxNozzle8, "cboxNozzle8"); + this.cboxNozzle8.BackColor = System.Drawing.Color.Transparent; + this.cboxNozzle8.Name = "cboxNozzle8"; + this.cboxNozzle8.UseVisualStyleBackColor = false; + this.cboxNozzle8.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); + // // cboxNozzle4 // resources.ApplyResources(this.cboxNozzle4, "cboxNozzle4"); + this.cboxNozzle4.BackColor = System.Drawing.Color.Transparent; this.cboxNozzle4.Name = "cboxNozzle4"; - this.cboxNozzle4.UseVisualStyleBackColor = true; + this.cboxNozzle4.UseVisualStyleBackColor = false; this.cboxNozzle4.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); // + // cboxNozzle7 + // + resources.ApplyResources(this.cboxNozzle7, "cboxNozzle7"); + this.cboxNozzle7.BackColor = System.Drawing.Color.Transparent; + this.cboxNozzle7.Name = "cboxNozzle7"; + this.cboxNozzle7.UseVisualStyleBackColor = false; + this.cboxNozzle7.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); + // // cboxNozzle3 // resources.ApplyResources(this.cboxNozzle3, "cboxNozzle3"); + this.cboxNozzle3.BackColor = System.Drawing.Color.Transparent; this.cboxNozzle3.Name = "cboxNozzle3"; - this.cboxNozzle3.UseVisualStyleBackColor = true; + this.cboxNozzle3.UseVisualStyleBackColor = false; this.cboxNozzle3.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); // + // cboxNozzle6 + // + resources.ApplyResources(this.cboxNozzle6, "cboxNozzle6"); + this.cboxNozzle6.BackColor = System.Drawing.Color.Transparent; + this.cboxNozzle6.Name = "cboxNozzle6"; + this.cboxNozzle6.UseVisualStyleBackColor = false; + this.cboxNozzle6.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); + // + // cboxNozzle5 + // + resources.ApplyResources(this.cboxNozzle5, "cboxNozzle5"); + this.cboxNozzle5.BackColor = System.Drawing.Color.Transparent; + this.cboxNozzle5.Name = "cboxNozzle5"; + this.cboxNozzle5.UseVisualStyleBackColor = false; + this.cboxNozzle5.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); + // // cboxNozzle2 // resources.ApplyResources(this.cboxNozzle2, "cboxNozzle2"); + this.cboxNozzle2.BackColor = System.Drawing.Color.Transparent; this.cboxNozzle2.Name = "cboxNozzle2"; - this.cboxNozzle2.UseVisualStyleBackColor = true; + this.cboxNozzle2.UseVisualStyleBackColor = false; this.cboxNozzle2.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); // // cboxNozzle1 // resources.ApplyResources(this.cboxNozzle1, "cboxNozzle1"); + this.cboxNozzle1.BackColor = System.Drawing.Color.Transparent; this.cboxNozzle1.Name = "cboxNozzle1"; - this.cboxNozzle1.UseVisualStyleBackColor = true; + this.cboxNozzle1.UseVisualStyleBackColor = false; this.cboxNozzle1.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); // // groupBox1 @@ -2550,34 +2586,6 @@ resources.ApplyResources(this.label27, "label27"); this.label27.Name = "label27"; // - // cboxNozzle5 - // - resources.ApplyResources(this.cboxNozzle5, "cboxNozzle5"); - this.cboxNozzle5.Name = "cboxNozzle5"; - this.cboxNozzle5.UseVisualStyleBackColor = true; - this.cboxNozzle5.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); - // - // cboxNozzle6 - // - resources.ApplyResources(this.cboxNozzle6, "cboxNozzle6"); - this.cboxNozzle6.Name = "cboxNozzle6"; - this.cboxNozzle6.UseVisualStyleBackColor = true; - this.cboxNozzle6.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); - // - // cboxNozzle7 - // - resources.ApplyResources(this.cboxNozzle7, "cboxNozzle7"); - this.cboxNozzle7.Name = "cboxNozzle7"; - this.cboxNozzle7.UseVisualStyleBackColor = true; - this.cboxNozzle7.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); - // - // cboxNozzle8 - // - resources.ApplyResources(this.cboxNozzle8, "cboxNozzle8"); - this.cboxNozzle8.Name = "cboxNozzle8"; - this.cboxNozzle8.UseVisualStyleBackColor = true; - this.cboxNozzle8.CheckedChanged += new System.EventHandler(this.cboxNozzle_CheckedChanged); - // // NozzleConfig // resources.ApplyResources(this, "$this");