diff --git a/ProductionSystem/Untils/Tool/StepTool.cs b/ProductionSystem/Untils/Tool/StepTool.cs index d5e5589..d887aa2 100644 --- a/ProductionSystem/Untils/Tool/StepTool.cs +++ b/ProductionSystem/Untils/Tool/StepTool.cs @@ -110,9 +110,8 @@ namespace ProductionSystem.Untils.Tool uyTool = new UyTool(pzf1.Com, val); - uyTool.Send(); - - + uyTool.Send(step); + _curveTool.Step = "BZ1"; _curveTool.Code = GetCode(); _curveTool.Start(); diff --git a/ProductionSystem/Untils/Tool/Uy.cs b/ProductionSystem/Untils/Tool/Uy.cs index 14b8bcc..7a759ea 100644 --- a/ProductionSystem/Untils/Tool/Uy.cs +++ b/ProductionSystem/Untils/Tool/Uy.cs @@ -6,6 +6,9 @@ using NewLife; using NewLife.Log; using NewLife.Serialization; using NewLife.Threading; +using ProductionSystem_Model.DbModel; +using ProductionSystem_Model.Enum; +using ProductionSystem_Service; namespace ProductionSystem.Untils.Tool { @@ -37,7 +40,7 @@ namespace ProductionSystem.Untils.Tool public string Val { get; set; } = "0"; public string Write { get; set; } = "0"; - + bool b = false; public bool ToAction() { @@ -53,50 +56,8 @@ namespace ProductionSystem.Untils.Tool XTrace.WriteLine($"水泵Uy 第[{mo}-{com}]个 写入设备报文:{sendMes}"); - bool b = false; - - - - - - mfSerialInfo.MsgFunc += (x) => - { - XTrace.WriteLine($"水泵Uy 第[{mo}-{com}]个 收到反馈报文:{sendMes}"); - if (x.Id.Contains("26") && x.Err == "0") - { - var bytes = x.Dat.ToHex(); - - me = new MFMsgVariable(bytes, 0, 8); - - XTrace.WriteLine("============================="); - var intelLsb = me.GetMotoralaLsb(0, 1); - XTrace.WriteLine("on: {0}", intelLsb); - intelLsb = me.GetMotoralaLsb(4, 2); - XTrace.WriteLine("PumpPCState: {0}", intelLsb); - intelLsb = me.GetMotoralaLsb(24, 8); - XTrace.WriteLine("RealRPM: {0}", intelLsb); - - Val = intelLsb.ToString(); - - XTrace.WriteLine($"水泵Uy 第[{mo}-{com}]个 收到反馈速度:{Val}"); - double errorMargin = Math.Abs(intelLsb.ToInt() - Write.ToInt()); - - if(!b && errorMargin<=5) - { - XTrace.WriteLine($"水泵Uy[{mo}-{com}] 逻辑结束"); - mfSerialInfo.MsgFunc = null; - mfSerialInfo.Exit = true; - b = true; - } - - } - - - - }; - - + mfSerialInfo.MsgFunc = Fun; mfSerialInfo.SendMsg(sendMes,50); return b; @@ -106,26 +67,29 @@ namespace ProductionSystem.Untils.Tool public bool Exit { get; set; } private TimerX _timer; - - public void Send() + + + public T_Product_Step TProductStep { set; get; } + + public void Send(T_Product_Step step) { - + TProductStep = step; + mfSerialInfo.MsgFunc = Fun; var sendMes = GetMsg(mo); _timer= new TimerX(DoBackup, sendMes, 100, 800) { Async = true }; } - + string sendMes = ""; private void DoBackup(Object state) { XTrace.WriteLine("Uy定时器"); - var sendMes = ""; - sendMes = state == null ? GetMsg(mo) : state.ToString(); mfSerialInfo.SendMessage(sendMes); } - - - public string GetMsg(int num) + + private ProductStepService _productStepService = new ProductStepService(); + + private string GetMsg(int num) { uint seep = uint.Parse((num * 0.4).ToString()); Write = seep.ToString(); @@ -154,5 +118,42 @@ namespace ProductionSystem.Untils.Tool Exit = true; Dispose(); } + + + + public void Fun(MfSerialEntity x) + { + XTrace.WriteLine($"水泵Uy 第[{mo}-{com}]个 收到反馈报文:{sendMes}"); + if (x.Id.Contains("26") && x.Err == "0") + { + var bytes = x.Dat.ToHex(); + + var me = new MFMsgVariable(bytes, 0, 8); + + XTrace.WriteLine("============================="); + var intelLsb = me.GetMotoralaLsb(0, 1); + XTrace.WriteLine("on: {0}", intelLsb); + intelLsb = me.GetMotoralaLsb(4, 2); + XTrace.WriteLine("PumpPCState: {0}", intelLsb); + intelLsb = me.GetMotoralaLsb(24, 8); + XTrace.WriteLine("RealRPM: {0}", intelLsb); + + Val = intelLsb.ToString(); + + _productStepService.UpdateSBSpeed(TProductStep.ProductType,TProductStep.ProductBarcode,TProductStep.StepName,EquipmentEnum.SB1ZS_DB.ToString(),Write,Val); + + XTrace.WriteLine($"水泵Uy 第[{mo}-{com}]个 收到反馈速度:{Val}"); + double errorMargin = Math.Abs(intelLsb.ToInt() - Write.ToInt()); + + if(!b && errorMargin<=5) + { + XTrace.WriteLine($"水泵Uy[{mo}-{com}] 逻辑结束"); + mfSerialInfo.MsgFunc = null; + mfSerialInfo.Exit = true; + b = true; + } + + } + } } } \ No newline at end of file