diff --git a/ProductionSystem/Forms/HomeForm.cs b/ProductionSystem/Forms/HomeForm.cs index dc5c7e3..12dd28c 100644 --- a/ProductionSystem/Forms/HomeForm.cs +++ b/ProductionSystem/Forms/HomeForm.cs @@ -45,6 +45,7 @@ namespace ProductionSystem.Forms private readonly ProtocolConfigService _protocolConfigService = new ProtocolConfigService(); private readonly PlcPointService _plcPointService = new PlcPointService(); private readonly ProductTypeService _productTypeService = new ProductTypeService(); + private readonly ProductStepService productStepService = new ProductStepService(); private Random random = new Random(); DataProductService dataProductService = new DataProductService(); @@ -179,8 +180,8 @@ namespace ProductionSystem.Forms hslCurveHistory.RemoveAllCurve(); - - + + } @@ -1023,6 +1024,13 @@ namespace ProductionSystem.Forms GetPlc(Program.BZ5, "BZ5"); GetPlc(Program.BZ6, "BZ6"); + SetMiddleData("BZ1_DB"); + SetMiddleData("BZ2_DB"); + SetMiddleData("BZ3_DB"); + SetMiddleData("BZ4_DB"); + SetMiddleData("BZ5_DB"); + SetMiddleData("BZ6_DB"); + Thread.Sleep(Program.ReadPlcRate); } @@ -1229,6 +1237,9 @@ namespace ProductionSystem.Forms SetMiddleData(values, txt); } + + + @@ -1336,33 +1347,58 @@ namespace ProductionSystem.Forms { if (middleMyTestResultControls[j].IsHandleCreated && !middleMyTestResultControls[j].IsDisposed) { - var result = string.Empty; - var val = string.Empty; + int result = 0; + var writeVal = string.Empty; + var returnVal = string.Empty; var testResultPoint = middleMyTestResultControls[j].TestResultPLCPointCode; var testValPoint = middleMyTestResultControls[j].TestValPLCPointCode; //获取点位 var paraCode = middleMyTestResultControls[j].ParaCode; - + var step = productStepService.QueryLatestStep(paraCategory, paraCode, Program.ProductType); if (string.IsNullOrEmpty(testResultPoint) || string.IsNullOrEmpty(testValPoint)) { //进行sql 进行查询sql - val=dataProductService.QueryDataProduct(paraCategory, paraCode); + //val=dataProductService.QueryDataProduct(paraCategory, paraCode); + + } this.Invoke(new Action(() => { - if (middleMyTestResultControls[j].LblItemText == "总状态") + if (step == null) { - result = val; + middleMyTestResultControls[j].TestResultText = "空闲"; + middleMyTestResultControls[j].TestResultForeColor = Color.Gray; + middleMyTestResultControls[j].TestValText = ""; + } + else + { + writeVal = step.WriteValue; + returnVal = step.ReturnValue; + int val1 = Convert.ToInt32(writeVal); + int val2 = Convert.ToInt32(returnVal); + if (returnVal == null) + { + result = 2; + } + if (Math.Abs(val2 - val1) <= 10) + { + result = 1; + } + else + { + result = 2; + } + + middleMyTestResultControls[j].TestResultText = result == 1 ? "OK" : (result == 2 ? "NG" : ""); + middleMyTestResultControls[j].TestResultForeColor = Color.White; + middleMyTestResultControls[j].TestResultBackColor = result == 1 ? Color.Green : (result == 2 ? Color.Red : Color.Gainsboro); + middleMyTestResultControls[j].TestValText = returnVal; } - middleMyTestResultControls[j].TestResultText = result == "1.000" ? "OK" : (result == "2.000" ? "NG" : ""); - middleMyTestResultControls[j].TestResultForeColor = Color.White; - middleMyTestResultControls[j].TestResultBackColor = result == "1.000" ? Color.Green : (result == "2.000" ? Color.Red : Color.Gainsboro); - middleMyTestResultControls[j].TestValText = val; })); } } diff --git a/ProductionSystem_Service/ProductStepService.cs b/ProductionSystem_Service/ProductStepService.cs index f3cc21f..ead2db8 100644 --- a/ProductionSystem_Service/ProductStepService.cs +++ b/ProductionSystem_Service/ProductStepService.cs @@ -26,5 +26,17 @@ namespace ProductionSystem_Service return -1; } } + + /// + /// 查询最新一条记录 + /// + /// + /// + /// + /// + public T_Product_Step QueryLatestStep(string stepName,string equipmentName,string productType) + { + return db.Queryable().Where(m => m.StepName == stepName && m.EquipmentName == equipmentName && m.ProductType == productType).First(); + } } }