diff --git a/yuhong_plc/zzz.Api/Controllers/Test/TestController.cs b/yuhong_plc/zzz.Api/Controllers/Test/TestController.cs index 1e0a5f8..c3bcf5b 100644 --- a/yuhong_plc/zzz.Api/Controllers/Test/TestController.cs +++ b/yuhong_plc/zzz.Api/Controllers/Test/TestController.cs @@ -306,13 +306,12 @@ namespace zzz.Api.Controllers [HttpGet] public async Task TestRead2() { - //IP 183.129.248.194 EquipInput input1 = new() { eqmt_id = 8, ip = "183.129.248.194", - port = new() { 6012} + port = new() { 6012 } }; await _readPLCDataService.ReadDataLine2(input1); @@ -320,6 +319,26 @@ namespace zzz.Api.Controllers return "OK"; } + + /// + /// 读取2线数据 + /// + [HttpGet] + public async Task TestRead3() + { + //IP 183.129.248.194 + EquipInput input1 = new() + { + eqmt_id = 8, + ip = "183.129.248.194", + port = new() { 6013 } + }; + + await _readPLCDataService.ReadDataLine3(input1); + + return "OK"; + } + /// /// 读取15线数据 /// diff --git a/yuhong_plc/zzz.Services/ReadPLC/IReadPLCDataService.cs b/yuhong_plc/zzz.Services/ReadPLC/IReadPLCDataService.cs index 330e423..9a00500 100644 --- a/yuhong_plc/zzz.Services/ReadPLC/IReadPLCDataService.cs +++ b/yuhong_plc/zzz.Services/ReadPLC/IReadPLCDataService.cs @@ -56,6 +56,13 @@ namespace zzz.Services.ReadPLC /// Task ReadDataLine2(EquipInput input); + /// + /// 读取3线数据 + /// + /// + /// + Task ReadDataLine3(EquipInput input); + /// /// 读取20线数据 /// diff --git a/yuhong_plc/zzz.Services/ReadPLC/ReadPLCDataService.cs b/yuhong_plc/zzz.Services/ReadPLC/ReadPLCDataService.cs index 3ecdc12..c4e7449 100644 --- a/yuhong_plc/zzz.Services/ReadPLC/ReadPLCDataService.cs +++ b/yuhong_plc/zzz.Services/ReadPLC/ReadPLCDataService.cs @@ -28,6 +28,7 @@ namespace zzz.Services.ReadPLC private readonly IBaseRepository _eqmt7Rep;//lgy add private readonly IBaseRepository _eqmt2Rep;//lgy add private readonly IBaseRepository _eqmt20Rep;//lgy add + private readonly IBaseRepository _eqmt3Rep;//cg add private readonly IBaseRepository _eqmt16Rep; private readonly IBaseRepository _eqmt17Rep; @@ -52,6 +53,7 @@ namespace zzz.Services.ReadPLC IBaseRepository eqmt15Rep, IBaseRepository eqmt7Rep, IBaseRepository eqmt2Rep, + IBaseRepository eqmt3Rep, IBaseRepository eqmt20Rep, IBaseRepository eqmt16Rep, IBaseRepository eqmt17Rep, @@ -76,6 +78,7 @@ namespace zzz.Services.ReadPLC _eqmt15Rep = eqmt15Rep; _eqmt7Rep = eqmt7Rep; _eqmt2Rep = eqmt2Rep; + _eqmt3Rep = eqmt3Rep; _eqmt20Rep = eqmt20Rep; _eqmt16Rep = eqmt16Rep; _eqmt17Rep = eqmt17Rep; @@ -1875,61 +1878,15 @@ namespace zzz.Services.ReadPLC eqmt7.d9508 = _melsecMcNet.ReadInt32("D9508").Content; // 班废品 eqmt7.d9510 = _melsecMcNet.ReadInt32("D9510").Content; // 班能耗 eqmt7.d9522 = _melsecMcNet.ReadInt32("D9522").Content; // 视觉废品 - eqmt7.d9524 = _melsecMcNet.ReadInt32("D9524").Content/10; //班合格率 - Console.WriteLine(_melsecMcNet.ReadFloat("D9524").Content); + + eqmt7.d9524 = Math.Round((decimal) _melsecMcNet.ReadInt32("D9524").Content / 10, 2); //班合格率 + //Console.WriteLine(_melsecMcNet.ReadFloat("D9524").Content); eqmt7.d9526 = _melsecMcNet.ReadFloat("D9526").Content.ObjToDecimal(0); //班开机率 eqmt7.d9528 = _melsecMcNet.ReadFloat("D9528").Content.ObjToDecimal(0); //班有效率 eqmt7.d9530 = _melsecMcNet.ReadInt32("D9530").Content; //班OEE - - //异常不停机数据 - #region 异常不停机数据 -/* - var except02 = new List(); - - var L100_L115 = _melsecMcNet.ReadBool("L100", 18); - for (int i = 0; i < 18; i++) - { - if (L100_L115.Content[i]) - { - except02.Add($"L{100 + i}"); - } - } - - var M800_M834 = _melsecMcNet.ReadBool("M800", 35); - for (int i = 0; i < 35; i++) - { - if (M800_M834.Content[i]) - { - except02.Add($"M{800 + i}"); - } - } - - var M860_M874 = _melsecMcNet.ReadBool("M860", 15); - for (int i = 0; i < 15; i++) - { - if (M860_M874.Content[i]) - { - except02.Add($"M{860 + i}"); - } - } - - var SM52 = _melsecMcNet.ReadBool("SM52"); - if (SM52.Content) except02.Add($"SM52"); - - var B0000F = _melsecMcNet.ReadBool("B0000F"); - if (B0000F.Content) except02.Add($"B0000F"); - - var B0050F = _melsecMcNet.ReadBool("B0050F"); - if (B0050F.Content) except02.Add($"B0050F"); - - var B00A0F = _melsecMcNet.ReadBool("B00A0F"); - if (B00A0F.Content) except02.Add($"B00A0F"); - */ - #endregion - #region 增加EqmtPub数据 var product_type = "1"; //if (eqmt7.l271 == 1) @@ -2077,7 +2034,7 @@ namespace zzz.Services.ReadPLC eqmt2.d9554 = _melsecMcNet.ReadInt32("D7954").Content; // 总能耗 eqmt2.d9506 = _melsecMcNet.ReadInt32("D7552").Content; // 班成品 eqmt2.d9508 = _melsecMcNet.ReadInt32("D7554").Content; // 班废品 - eqmt2.d9524 = Math.Round((decimal) eqmt2.d9506/eqmt2.d9504, 2) * 100; //班合格率 + eqmt2.d9524 = eqmt2.d9504 == 0 ? 0 : Math.Round((decimal) eqmt2.d9506 * 100 / eqmt2.d9504, 2); //班合格率 eqmt2.d9526 = _melsecMcNet.ReadFloat("D9526").Content.ObjToDecimal(0); //班开机率 eqmt2.d9528 = _melsecMcNet.ReadFloat("D9528").Content.ObjToDecimal(0); //班有效率 @@ -2230,6 +2187,98 @@ namespace zzz.Services.ReadPLC } + + + /// + /// 读取3线数据 + /// + /// + /// + public async Task ReadDataLine3(EquipInput input) + { + Stopwatch oTime1 = new Stopwatch(); + oTime1.Start(); //记录开始时间 + try + { + _logger.LogInformation($"读取3线数据 开始"); + + var eqmt3 = new Eqmt3() + { + eqmt_id = input.eqmt_id, + collect_id = Guid.NewGuid().ToString(), + gmt_create = DateTime.Now, + }; + + var connSuccess = ConnectPLC(input.ip, input.port[0]); + + if (connSuccess) + { + eqmt3.d260 = _melsecMcNet.ReadInt16("D260").Content; // 产品型号 + eqmt3.d204 = _melsecMcNet.ReadInt16("D204").Content; // 生产速度 + + eqmt3.d840 = _melsecMcNet.ReadInt32("D840").Content; // 总生产产量 + eqmt3.d842 = _melsecMcNet.ReadInt32("D842").Content; // 总成品量 + eqmt3.d6600 = _melsecMcNet.ReadInt32("D6600").Content; // 班产量 + eqmt3.d6602 = _melsecMcNet.ReadInt32("D6602").Content; // 班成品 + eqmt3.d6604 = _melsecMcNet.ReadInt32("D6604").Content; // 班废品 + eqmt3.d6614 = _melsecMcNet.ReadInt32("D6614").Content; //班合格率 + + eqmt3.d9530 = _melsecMcNet.ReadInt32("D9530").Content; //班OEE + + + + #region 增加EqmtPub数据 + var product_type = "1"; + var eqmtBaseInfo = (await _eqmtBaseRep.QueryAsync(x => x.eqmt_id == eqmt3.eqmt_id)).FirstOrDefault(); + var eqmtProductSpecInfo = (await _eqmtProductSpecRep.QueryAsync(x => x.eqmt_id == eqmt3.eqmt_id && x.product_type == product_type)).FirstOrDefault(); + + EqmtPubData newPub = new EqmtPubData(); + + newPub.collect_id = eqmt3.collect_id; + newPub.eqmt_id = eqmt3.eqmt_id; + newPub.product_type = product_type; + newPub.product_type_name = $"{eqmtBaseInfo?.product}({eqmtProductSpecInfo?.product_type_name})"; + + newPub.speed = eqmt3.d204; + newPub.total_product_qty = eqmt3.d840; + newPub.intraday_product_qty = eqmt3.d842; + + newPub.intraday_ok_qty = eqmt3.d6600; + newPub.intraday_ng_qty = eqmt3.d6604; + newPub.intraday_yield_rate = eqmt3.d6614; + + newPub.oee = eqmt3.d9530; + + #endregion + + + + #region 写入数据库 + //报工数据 一定要写在 pubData插入之前 + var addData = await CreateEqmtCollectAddData(newPub); + await _eqmtAddDataRep.InsertAsync(addData); + + await _eqmt3Rep.InsertAsync(eqmt3); + + await _eqmtPubRep.InsertAsync(newPub); + + #endregion + } + + } + catch (Exception e) + { + _logger.LogInformation($"读取3线数据 异常 {e.Message}"); + } + finally + { + oTime1.Stop(); //记录结束时间 + _logger.LogInformation($"读取3线数据 完成,耗时{oTime1.Elapsed.TotalSeconds}秒"); + DisConnectPLC(); + } + } + + /// /// 读取20线数据 /// diff --git a/yuhong_plc/zzz.Tasks/QuartzNet/Jobs/Job_PLC_read_line3.cs b/yuhong_plc/zzz.Tasks/QuartzNet/Jobs/Job_PLC_read_line3.cs new file mode 100644 index 0000000..61dda20 --- /dev/null +++ b/yuhong_plc/zzz.Tasks/QuartzNet/Jobs/Job_PLC_read_line3.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Logging; +using Quartz; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using zzz.Common.Helper; +using zzz.Services.ReadPLC; +using zzz.Services.Sys.TasksQzs; + +namespace zzz.Tasks +{ + public class Job_PLC_read_line3 : JobBase, IJob + { + public ILogger _logger = null; + private readonly IReadPLCDataService _readPlcDataService; + + + public Job_PLC_read_line3( + ILogger logger, + IReadPLCDataService readPlcDataService, + ITasksQzServices tasksQzServices + ) + { + _logger = logger; + _readPlcDataService = readPlcDataService; + _tasksQzServices = tasksQzServices; + } + public async Task Execute(IJobExecutionContext context) + { + var executeLog = await ExecuteJob(context, async () => await Run(context)); + } + public async Task Run(IJobExecutionContext context) + { + //var list = await _blogArticleServices.Query(); + // 也可以通过数据库配置,获取传递过来的参数 + //JobDataMap data = context.JobDetail.JobDataMap; + //int jobId = data.GetInt("JobParam"); + //ConsoleHelper.WriteColorLine("执行任务具体XXXXXXXXXXX", ConsoleColor.Red); + + + // 可以直接获取 JobDetail 的值 + var jobKey = context.JobDetail.Key; + var jobId = jobKey.Name; + // 也可以通过数据库配置,获取传递过来的参数 + JobDataMap data = context.JobDetail.JobDataMap; + + _logger.LogInformation($"执行任务{jobKey}-{jobId}"); + + var jobParam = JsonHelper.JsonToObj(data["JobParam"].ToString()); + + await _readPlcDataService.ReadDataLine3(jobParam); + + } + } +} + diff --git a/yuhong_plc/zzz.model/Entity/Equipment/Eqmt3.cs b/yuhong_plc/zzz.model/Entity/Equipment/Eqmt3.cs new file mode 100644 index 0000000..1737147 --- /dev/null +++ b/yuhong_plc/zzz.model/Entity/Equipment/Eqmt3.cs @@ -0,0 +1,58 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace zzz.Model.Entity +{ + /// + /// 2线 + /// + [SugarTable("eqmt_collect_data3")] + public class Eqmt3 + { + /// + /// id + /// + [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "自增主键")] + public long id { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(IsNullable = true, ColumnDescription = "创建时间")] + public DateTime? gmt_create { get; set; } = DateTime.Now; + + /// + /// 修改时间 + /// + [SugarColumn(IsNullable = true, ColumnDescription = "修改时间")] + public DateTime? gmt_modified { get; set; } + + /// + /// 收集唯一ID + /// + [SugarColumn(IsNullable = true, ColumnDescription = "收集唯一ID")] + public string collect_id { get; set; } + + /// + /// 设备ID + /// + public int eqmt_id { get; set; } + + + public int d260 { get; set; } + public int d204 { get; set; } + public int d840 { get; set; } + public int d842 { get; set; } + + public int d6600 { get; set; } + public int d6602 { get; set; } + public int d6604 { get; set; } + + public decimal d6614 { get; set; } + public decimal d9530 { get; set; } + } +} diff --git a/yuhong_plc/zzz.model/Entity/Equipment/Eqmt7.cs b/yuhong_plc/zzz.model/Entity/Equipment/Eqmt7.cs index 134f128..c8f18a2 100644 --- a/yuhong_plc/zzz.model/Entity/Equipment/Eqmt7.cs +++ b/yuhong_plc/zzz.model/Entity/Equipment/Eqmt7.cs @@ -55,7 +55,7 @@ namespace zzz.Model.Entity public int d9510 { get; set; } public int d9522 { get; set; } - public int d9524 { get; set; } + public decimal d9524 { get; set; } public decimal d9526 { get; set; } public decimal d9528 { get; set; }