Example #1
0
        /// <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);
            }
        }
Example #2
0
 /// <summary>
 /// 拧紧机TCP客户端向外发送的条码信息
 /// </summary>
 /// <param name="code"></param>
 private void ReadVinNumber(string code)
 {
     try
     {
         Log.Information("接收到拧紧机条码:{code}", code);
         if (code.Length > 17)
         {
             code = code.Substring(0, 17);
         }
         if (code == CurrentEngineCode)
         {
             VinNumberChangedEvent?.Invoke(tdConfig.ToolId, code);
             //newTightenConfig中的信息
             if (newTightenConfig != null && newTightenConfig.TightenPointNum > 0)
             {
                 if (newTightenConfig.JobId.HasValue)
                 {
                     TightenToolClient.SelectJob(newTightenConfig.JobId.Value);
                 }
                 else if (newTightenConfig.BoltPset1.HasValue)
                 {
                     //设置Pset值,等待拧紧
                     GotoNextBolt(CurrentBoltIndex);
                 }
                 TightenToolClient.EnableTightenTool();
             }
             else
             {
                 OnWorkUnitFinishedAction?.Invoke(tdConfig.ToolId, true, null);
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "拧紧机条码接收处理报错");
     }
 }
Example #3
0
        /// <summary>
        /// 读取拧紧数据
        /// 这应该是TightenClient的回调方法
        /// </summary>
        /// <param name="msg"></param>
        private void ReadLastTightenData(TightenData result)
        {
            Debug.WriteLine($"MyController -> ReadLastTightenData ->  {result.Torque}");
            Debug.WriteLine($"MyController -> ReadLastTightenData ->  {result.Pset}");

            try
            {
                if (result == null || result.Torque == 0)
                {
                    return;
                }
                if (string.IsNullOrEmpty(CurrentEngineCode) == false)
                {
                    result.EngineCode = CurrentEngineCode;
                }

                TightenDatas.AddTightenData(result);
                result.JobResult = GetResult() ? 1 : 0;

                //手动给螺栓号赋值
                result.BoltNo = CurrentBoltIndex;
                if (CurrentBoltIndex == 0)
                {
                    OnLastTightenAction?.Invoke(tdConfig.ToolId, result);
                    return;
                }
                if (result.Result == 0) //NG
                {
                    TightenCount++;
                    Debug.WriteLine($"MyController -> ReadLastTightenData -> CurrentBoltIndex = {CurrentBoltIndex}");
                    Debug.WriteLine($"MyController -> ReadLastTightenData -> TightenCount = {TightenCount}");

                    if (TightenCount >= TightenCountLimit && TightenCountLimit != 0) //NG
                    {
                        //锁枪
                        //TODO:测试时注释
                        TightenToolClient.DisableTightenTool();
                        //调用结束事件
                        OnWorkUnitFinishedAction?.Invoke(tdConfig.ToolId, false, result);
                    }
                    else
                    {
                        //调用拧紧结果事件
                        OnLastTightenAction?.Invoke(tdConfig.ToolId, result);
                    }
                }
                else
                {
                    Debug.WriteLine($"MyController -> ReadLastTightenData -> CurrentBoltIndex = {CurrentBoltIndex}");
                    Debug.WriteLine($"MyController -> ReadLastTightenData -> TightenCount = {TightenCount}");
                    Debug.WriteLine($"MyController -> ReadLastTightenData -> newTightenConfig ==null? {newTightenConfig == null}");

                    //当前螺丝处理完再加1
                    if (CurrentBoltIndex == newTightenConfig.TightenPointNum)
                    {
                        //调用结束事件
                        OnWorkUnitFinishedAction?.Invoke(tdConfig.ToolId, true, result);
                        //锁枪
                        //TODO:测试时注释
                        TightenToolClient.DisableTightenTool();
                    }
                    else
                    {
                        CurrentBoltIndex++;
                        //调用拧紧结果事件
                        OnLastTightenAction?.Invoke(tdConfig.ToolId, result);
                        GotoNextBolt(CurrentBoltIndex);
                    }
                    //到下一颗螺丝时,拧紧次数清0
                    TightenCount = 0;
                }
            }
            catch (Exception ex)
            {
                Log.Error("ReadLastTightenData", ex);
            }
        }