private void SetEngineCode(string code) { EngineViewModel engine = GetEngineCodeInfo(code); if (engine == null) { Log.Warning($"条码{code}异常,没有找到发动机信息"); ViewModel.PrintlnWarning($"没有找到{code}的机型信息"); engine = EngineViewModel.CreateModel(code); } ReadScanCode(engine); }
/// <summary> /// 出工位判定 /// </summary> /// <param name="adam"></param> private void EngineOutStation() { try { ViewModel.PrintlnInfo("到达限位"); Log.Information("到达限位"); if (EngineInfo == null || string.IsNullOrEmpty(EngineInfo.EngineCode) || EngineInfo.EngineCode == Configs.FileConfigs.NullCode) { return; } bool result = true; string alarmInfo = EngineInfo.EngineCode; if (GetTdResult() == false) { result = false; ViewModel.PrintlnWarning("拧紧作业没有完成"); ViewModel.TightenResult = "NG"; alarmInfo += "拧紧未完成报警;"; UpdateEngineResultToDB(EngineInfo.EngineCode, 0); } if (_screenConfig.Part.Bind) { if (metasModel != null && metasModel.Id <= 0 && string.IsNullOrEmpty(metasModel.MaterialCode)) { metasModel.MaterialCode = ""; metasModel.Result = 0; Task.Run(() => RFIDDBHelper.MSSQLHandler.SaveMaterialMetas(metasModel)); } if (metasModel == null || metasModel.Result != 1) { ViewModel.PrintlnWarning("减震器条码未绑定"); alarmInfo += "减震器条码未绑定;"; result = false; } } if (!result) { Log.Warning($"{Station}:{alarmInfo}"); LogAlarm("作业未完成", alarmInfo); Task.Run(() => UpdateStationInfo(Station, 0)); } else { EngineInfo = null; } } catch (Exception ex) { ViewModel.PrintlnWarning("[EngineOutStation]:" + ex.Message); Log.Error($"[{theTitle}]EngineOutStation", ex); } }
/// <summary> /// 扫描条码开始拧紧 /// </summary> /// <param name="engine"></param> public void ReadScanCode(EngineViewModel engine) { if (engine == null) { Log.Warning("扫描得到的engine为null"); DisPlayEngineInfo(null); return; } EngineInfo = engine.Clone(); ViewModel.PrintlnInfo($"扫码:{engine.EngineCode} {engine.EngineName}"); StartTighten(engine);//扫描的条码不分手自动 }
/// <summary> /// 将条码发送到拧紧岗位 /// </summary> /// <param name="code"></param> private void OpenTightening(TagData tag) { try { if (tag == null || string.IsNullOrEmpty(tag.EngineCode)) { return; } EngineViewModel model = GetEngineViewModel(tag.EngineCode, tag.EngineMto); currentEngine = model; lock (forms) forms.ForEach(f => f.SetEngineCode(model?.Clone())); } catch (Exception ex) { Log.Error("在启动终端拧紧时出现异常", ex); } }
/// <summary> /// 发动机码(RFID\扫描) /// </summary> /// <param name="code"></param> public void SetEngineCode(EngineViewModel engine) { if (engine == null) { Log.Warning("接收到发动机信息engine为null"); DisPlayEngineInfo(null); return; } ViewModel.PrintlnInfo($"RFID:{engine.EngineCode} {engine.EngineName}"); EngineInfo = engine.Clone(); string engineCode = engine.EngineCode; string engineMto = engine.EngineMTO; try { if (engineCode == Configs.FileConfigs.NullCode || string.IsNullOrEmpty(engineCode)) { DisPlayEngineInfo(null); //空吊具与空条码有不同的提示 if (!string.IsNullOrEmpty(engineCode))/*engineCode == 000000000000;这种是吊具上没有发动机,无需作业*/ { ViewModel.PrintlnInfo("读取到空吊具标签"); } ViewModel.TightenResult = ""; ViewModel.TighteningData = null; ViewModel.CurTorque = 0; ViewModel.CurAngle = ""; ViewModel.TorqueColor = Color.Black; } else { ViewModel.CurTorque = 0; ViewModel.CurAngle = ""; ViewModel.TorqueColor = Color.Black; //StartTighten?.Invoke(engine, isAutoMatic); StartTighten(engine); } } catch (Exception ex) { Log.Error("SetEngineCode:" + engineCode, ex); ViewModel.PrintlnWarning(ex.Message); } }
/// <summary> /// 扫描枪 /// </summary> /// <param name="code"></param> /// <param name="codeType"></param> private void Scan_OnScanCoded(string code) { Log.Information("扫描枪扫描条码:{code}", code); if (codeRegex == null) { codeRegex = new Regex(appConfig.BarCodePattern); } if (codeRegex.IsMatch(code)) { EngineViewModel model = GetEngineViewModel(code, ""); lock (forms) { forms.ForEach(f => f.ReadScanCode(model)); } } else { Log.Warning($"扫描的条码{code}格式不正确。Pattern:{appConfig.BarCodePattern}"); } }
/// <summary> /// 开始拧紧作业 /// 正儿八经的开始控制拧紧枪 /// </summary> /// <param name="engine"></param> /// <param name="isSendVIN">是否向TightenControl发送条码</param> private async void StartTighten(EngineViewModel engine) { /* * 不管手动自动扫描到条码后都会走到这里. * 所以向两个拧紧机发送条码的代码先添加到这里. */ curTightenCfg = null; try { DisPlayEngineInfo(engine); ViewModel.TightenResult = ""; ViewModel.TighteningData = null; CurrentCode = engine.EngineCode; await CreateResult(engine.EngineCode); if (string.IsNullOrEmpty(engine.EngineMTO)) { ViewModel.PrintlnWarning($"没有找到发动机{engine.EngineCode}派生"); } lTightenConfigs = await RFIDDBHelper.LocalSQLHandler.LTightenConfig.GetTdConfig(engine.EngineCode, _screenConfig.Station.StationID); if (lTightenConfigs == null) { lTightenConfigs = new List <LTightenConfigModel>(); } theCfgTdCount = lTightenConfigs.Sum(s => s.TightenPointNum); Log.Information("拧紧配置数:{tcount},拧紧点数:{pcount}", lTightenConfigs.Count, theCfgTdCount); CurrentPointNum = 1; InitTightenTool(); RunNextTightenTool(); if (Station != null) { Station.LastCode = engine.EngineCode; RFIDDBHelper.MSSQLHandler.StationService.Update(Station); } } catch (Exception ex) { Log.Error("接收条码开始拧紧时出现错误", ex); } }
/// <summary> /// 发动机信息展示 /// </summary> /// <param name="model"></param> private void DisPlayEngineInfo(EngineViewModel model) { if (model == null) { ViewModel.EngineCode = ""; ViewModel.EngineMTO = ""; ViewModel.EngineType = ""; } else { ViewModel.EngineCode = model.EngineCode; ViewModel.EngineMTO = model.EngineMTO ?? ""; ViewModel.EngineType = model.EngineName ?? ""; if (lastMTO != "" && model.EngineMTO != lastMTO) { //派生切换 ViewModel.EngineMTO += " 派生切换"; } lastMTO = model.EngineMTO; } }
private EngineViewModel GetEngineViewModel(string code, string mto) { EngineViewModel model = null; try { if (!string.IsNullOrEmpty(code) && code != appConfig.NullCode) { model = RFIDDBHelper.GetEngineOther(code, mto); } } catch (Exception ex) { Log.Error(ex, "获取机型信息报错!"); ViewModels[0].PrintlnWarning(ex.Message); } if (model == null) { model = EngineViewModel.CreateModel(code, mto); } return(model); }