/// <summary> /// 运行下一个电枪拧紧 /// </summary> private void RunNextTightenTool() { if (lTightenConfigs.Count > 0) { int index = 0; if (curTightenCfg != null) { index = lTightenConfigs.IndexOf(curTightenCfg) + 1; } if (lTightenConfigs.Count > index) { curTightenCfg = lTightenConfigs[index]; if (!tightenControllers.ContainsKey(curTightenCfg.ToolId)) { ViewModel.PrintlnWarning($"拧紧参数配置异常,没有id为{curTightenCfg.ToolId}的电枪"); adam.AlarmWarning(true); return; } Log.Information("当前拧紧配置:{id}:{count}", curTightenCfg.Id, curTightenCfg.TightenPointNum); } else { Log.Information("拧紧结束结算"); curTightenCfg = null; //结算 TightenComplate(); return; } if (curTightenCfg != null && tightenControllers[curTightenCfg.ToolId] != null) { tightenControllers[curTightenCfg.ToolId].InitTightenInfo(CurrentCode, curTightenCfg); //向拧紧机发送条码,通过isSendVIN参数第一步判断,tdconfig里面的配置是第二步 //tightenControllers[curTightenCfg.ToolId].SetTighenCode(CurrentCode); if (_screenConfig.Part.Available) { ViewModel.PnoCode = $"请扫描{_screenConfig.Part.PartName}条码"; ViewModel.CodeBindStatus = ""; } } else { adam.AlarmWarning(true); ViewModel.PrintlnWarning($"ToolId为{curTightenCfg.ToolId}的电枪对象为空!"); Log.Warning("ToolId为{ToolId}的电枪对象为空!", curTightenCfg.ToolId); } } else { //结算 TightenComplate(); return; } }
/// <summary> /// 设置拧紧点信息 /// </summary> /// <param name="engineCode"></param> public void InitTightenInfo(string engineCode, LTightenConfigModel tConfig) { try { TightenCount = 0; CurrentBoltIndex = 0; Debug.WriteLine($"MyController -> InitTightenInfo -> CurrentBoltIndex = {CurrentBoltIndex}"); Debug.WriteLine($"MyController -> InitTightenInfo -> TightenCount = {TightenCount}"); if (string.IsNullOrEmpty(engineCode) && tConfig == null) { newTightenConfig = null; TightenDatas.ReSetTighten(0); return; } newTightenConfig = tConfig; if (engineCode != CurrentEngineCode) { //TODO:测试时注释 //TightenToolClient.DisableTightenTool(); CurrentEngineCode = engineCode; //取发动机码前7位,到DB中查询相关信息 var queryEngineCode = engineCode.Substring(0, 7); if (newTightenConfig == null) { newTightenConfig = new LTightenConfigModel { StationId = CurrentStationId, TightenPointNum = 0 }; } //未配置拧紧信息 if (newTightenConfig.TightenPointNum == 0) { Debug.WriteLine($"当前工位未配置{engineCode}类型的拧紧信息"); Log.Information("当前工位未配置{engineCode}类型的拧紧信息", engineCode); TightenDatas.ReSetTighten(0); OnWorkUnitFinishedAction?.Invoke(tdConfig.ToolId, true, null); return; } CurrentPointNum = 1; //兼容 TightenDatas.ReSetTighten(newTightenConfig.TightenPointNum); SetTighenCode(engineCode); } } catch (Exception ex) { Debug.WriteLine($"设置拧紧信息出错{ex.Message}"); Log.Error("设置拧紧信息出错", ex); } }
/// <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); } }