diff --git a/Admin.Core.Api/Admin.Core.Model.xml b/Admin.Core.Api/Admin.Core.Model.xml index 1253d367..9408fbfb 100644 --- a/Admin.Core.Api/Admin.Core.Model.xml +++ b/Admin.Core.Api/Admin.Core.Model.xml @@ -2756,6 +2756,11 @@ 异常类型(1=69码校验;2=重复扫描;3=未绑条码;4=未终检) + + + 所在位置 + + 计划执行表 diff --git a/Admin.Core.Model/Model_New/ExceptionRecord.cs b/Admin.Core.Model/Model_New/ExceptionRecord.cs index 4e077b05..e4a7d6a6 100644 --- a/Admin.Core.Model/Model_New/ExceptionRecord.cs +++ b/Admin.Core.Model/Model_New/ExceptionRecord.cs @@ -48,7 +48,12 @@ namespace Admin.Core.Model /// [SugarColumn(ColumnName = "EXCEPTION_TYPE")] public int ExceptionType { get; set; } - + + /// + /// 所在位置 + /// + [SugarColumn(ColumnName = "POSITION")] + public string Position { get; set; } } } diff --git a/Aucma.Core.CodeBinding/Common/SpeechStr.cs b/Aucma.Core.CodeBinding/Common/SpeechStr.cs index 5a1dac7a..32b4f782 100644 --- a/Aucma.Core.CodeBinding/Common/SpeechStr.cs +++ b/Aucma.Core.CodeBinding/Common/SpeechStr.cs @@ -18,7 +18,7 @@ namespace Aucma.Core.CodeBinding.Common } } - public void speech(string str) { + public async void SpeakAsync(string str) { SpeechSynthesizer speech = new SpeechSynthesizer(); speech.Rate = 3;//设置语速 diff --git a/Aucma.Core.CodeBinding/ViewModels/IndexPageViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/IndexPageViewModel.cs index 4d292e36..7ae0a039 100644 --- a/Aucma.Core.CodeBinding/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/IndexPageViewModel.cs @@ -68,6 +68,16 @@ namespace Aucma.Core.CodeBinding.ViewModels // sn扫码器ip private static string SnScannerIp = allScanners.First(x => x.Name == "sn扫码器").Ip; + private SpeechStr speechStr = SpeechStr.Instance; + + private string ProductLineCode = Appsettings.app("StationInfo", "ProductLineCode"); + + + + // 质检记录 + private readonly IReportQualityInspectionServices? _reportQualityInspectionServices; + //异常记录,记录质检失败情况 + private readonly IExceptionRecordServices? exceptionRecordServices; public IndexPageViewModel() { @@ -76,9 +86,10 @@ namespace Aucma.Core.CodeBinding.ViewModels _codeBindingRecordServices = App.ServiceProvider.GetService(); _baseBomInfoServices = App.ServiceProvider.GetService(); _baseMaterialInfoServices = App.ServiceProvider.GetService(); - + _reportQualityInspectionServices = App.ServiceProvider.GetService(); _printBarCodeServices = App.ServiceProvider.GetService(); _iMaterialCompletionServices = App.ServiceProvider.GetService(); + exceptionRecordServices = App.ServiceProvider.GetService(); // Business.MvCodeHelper.ReceiveCodeEvent += ReceiveCode; // Business.MvCodeHelper.BindingCodeEvent += BindingCode; // Business.MvCodeHelper.NoReadEvent += ReceiveNoRead; @@ -86,20 +97,15 @@ namespace Aucma.Core.CodeBinding.ViewModels TouchSocketService.NoReadReceiveEvent += ReceiveNoRead; GunBusiness.BindingReceiveCodeEvent += BindingCode; GunBusiness.RefreshMaterialCodeStrEvent += ReceiveCode; - + MsgUIColor = "White"; LoadData(); - + //实时绑定条码和实时下发plc放行信号 realBindingAndSendPlc(); LoadCharts(); - //Task.Run(() => - //{ - // Thread.Sleep(4000); - - //}); - + } catch (Exception ex) @@ -109,7 +115,6 @@ namespace Aucma.Core.CodeBinding.ViewModels } - /// /// 实时绑定条码和实时下发plc放行信号 /// @@ -465,16 +470,18 @@ namespace Aucma.Core.CodeBinding.ViewModels SendPlcStop(); Clear(); - RefreshAndWriteLog("MES条码未扫描到,NoRead报警,线体停止,请重新扫描!"); + RefreshAndWriteLog("MES条码未扫描到,NoRead报警,线体停止,请重新扫描!",true); + } else if (SnScannerIp == scannerIp) - { - + { SendPlcStop(); Clear(); - RefreshAndWriteLog("SN条码未扫描到,NoRead报警,线体停止,请重新扫描!"); + RefreshAndWriteLog("SN条码未扫描到,NoRead报警,线体停止,请重新扫描!", true); + } + speechStr.SpeakAsync("扫码失败,请补扫"); } /// @@ -577,15 +584,33 @@ namespace Aucma.Core.CodeBinding.ViewModels /// 提示信息刷新并且存日志 /// /// - private void RefreshAndWriteLog(string logStr) + private void RefreshAndWriteLog(string logStr,bool warnflag=false) { TimeSpan currentTime = DateTime.Now.TimeOfDay; // DateTime time = System.DateTime.Now; string timeString = currentTime.ToString(@"hh\:mm\:ss"); BindingInfo = timeString + ":" + logStr; + if(warnflag) + { + MsgUIColor = "Red"; + } + else + { + MsgUIColor = "White"; + } log.Info(BindingInfo); } + /// + /// 提示信息-颜色 + /// + public string msgUIColor; + public string MsgUIColor + { + get => msgUIColor; + set => SetProperty(ref msgUIColor, value); + } + /// /// 条码绑定 /// @@ -598,16 +623,30 @@ namespace Aucma.Core.CodeBinding.ViewModels { if (code1.Substring(0, 1) != "B") { + speechStr.SpeakAsync("扫码失败,请补扫"); RefreshAndWriteLog("MES码:" + code1 + ",扫描错误,请重新扫描!"); SendPlcStop(); return; } if (code2.Length != 20) { + speechStr.SpeakAsync("扫码失败,请补扫"); RefreshAndWriteLog("SN码:" + code2 + ",扫描错误,请重新扫描!"); SendPlcStop(); return; } + #region 终检校验-未查到终检合格记录即为质检不合格 + + ReportQualityInsPection qualityList = _reportQualityInspectionServices.JudgeIsQualified(code1); + if (qualityList == null) + { + SendPlcStop(); + RefreshAndWriteLog($"终检失败!! 箱体码{code1}未查询到终检合格记录,请重新终检!",true); + speechStr.SpeakAsync("终检失败,请终检"); + AddExceptionRecord(code1, $"终检失败!! 箱体码{code1}未查询到终检合格记录,请重新终检!", 4); + return; + } + #endregion RefreshAndWriteLog("开始绑定MES条码:" + code1 + " SN条码:" + code2); // 1.数据库查询各个工序质检结果,不合格报警 @@ -677,7 +716,7 @@ namespace Aucma.Core.CodeBinding.ViewModels } else { - RefreshAndWriteLog("条码【" + record.BoxCode + "】与SN码【" + record.ProductCode + "】绑定失败"); + RefreshAndWriteLog("条码【" + record.BoxCode + "】与SN码【" + record.ProductCode + "】绑定失败", true); if (SendPlcStop()) { RefreshAndWriteLog("条码绑定失败,线体停止"); @@ -697,6 +736,31 @@ namespace Aucma.Core.CodeBinding.ViewModels } } + + /// + /// 往mes数据库添加异常记录 + /// + /// + /// + /// 1=69码校验;2=重复扫描;3=未绑条码;4=未终检 + public async void AddExceptionRecord(string BoxCode, string Msg, int Type) + { + try + { + ExceptionRecord record = new ExceptionRecord(); + record.ProductSnCode = BoxCode; + record.ProductScanTime = DateTime.Now; + record.ProductLineCode = ProductLineCode; + record.ExceptionMsg = Msg; + record.ExceptionType = Type; + record.Position = "条码绑定"; + await exceptionRecordServices.AddAsync(record); + } + catch (Exception ex) + { + log.Info("添加异常记录方法AddExceptionRecord异常:" + ex.Message.ToString()); + } + } #region plc交互 /// diff --git a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs index 20334bc5..15271326 100644 --- a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs @@ -60,15 +60,32 @@ namespace Aucma.Core.CodeBinding.ViewModels timer.Tick += Timer_Tick; timer.Start(); Scanner1State(false); - Scanner2State(false); - + Scanner2State(false); + PlcState(false); // Job_AllState_Quartz.RefreshStateEvent += RefreshStatus; // MvCodeHelper.RefreshStateEvent += RefreshScanner; TouchSocketService.RefreshStateEvent += RefreshScanner; GunBusiness.InstanceSerialPort3(); + updatePlcState(); // InitHikRobot(); } + private void updatePlcState() + { + Task.Run(() => + { + Thread.Sleep(4000); + var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); + if (obj.plc.IsConnected) + { + PlcState(true); + } + else + { + PlcState(false); + } + }); + } #region 开启海康扫码器 public void InitHikRobot() diff --git a/Aucma.Core.CodeBinding/Views/IndexPageView.xaml b/Aucma.Core.CodeBinding/Views/IndexPageView.xaml index 4a15346f..43e1cea6 100644 --- a/Aucma.Core.CodeBinding/Views/IndexPageView.xaml +++ b/Aucma.Core.CodeBinding/Views/IndexPageView.xaml @@ -141,10 +141,12 @@ + +