From 62bb08923137637e1e340895f1f205db0e9183a1 Mon Sep 17 00:00:00 2001 From: quowingwang Date: Tue, 23 Dec 2025 16:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E8=89=B2=E7=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Program.cs | 5 ++- ZR.Service/Utils/MyAlarmLigth/LightUp.cs | 4 +-- .../mes/andon/AndonAlarmRecordService.cs | 31 +++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index ec3159fa..fd3f0944 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -19,12 +19,11 @@ using ZR.Service.mqtt; var builder = WebApplication.CreateBuilder(args); //后台定时任务 -//builder.Services.AddHostedService(); -//builder.Services.AddHostedService(); +//builder.Services.AddHostedService()builder.Services.AddHostedService(); // Add services to the container. -builder.Services.AddControllers(); + builder.Services.AddControllers(); //配置中心 //builder.Configuration.AddNacosV2Configuration(builder.Configuration.GetSection("NacosConfig")); //服务注册 diff --git a/ZR.Service/Utils/MyAlarmLigth/LightUp.cs b/ZR.Service/Utils/MyAlarmLigth/LightUp.cs index e13515b1..467db64e 100644 --- a/ZR.Service/Utils/MyAlarmLigth/LightUp.cs +++ b/ZR.Service/Utils/MyAlarmLigth/LightUp.cs @@ -69,7 +69,7 @@ namespace ZR.Service.Utils.MyAlarmLigth { ushort startAddress = 0x0000; // 起始地址,对应 ushort numberOfRegisters = 0x000B; // 要读取的寄存器数量 (40001 到 40012) - List commandValues = new List { 0x0000, 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000A }; // 红色闪烁 且蜂鸣器响 + List commandValues = new List { 0x0000, 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000A }; // 黄色常亮 且蜂鸣器响 // 发送写指令到警灯设备 _modbusClient.WriteMultipleRegisters(unitId, startAddress, commandValues); Console.WriteLine($"已向从站 {unitId} 的寄存器 {startAddress} 写入指令: {string.Join(", ", commandValues)}"); @@ -86,7 +86,7 @@ namespace ZR.Service.Utils.MyAlarmLigth { ushort startAddress = 0x0000; // 起始地址,对应 ushort numberOfRegisters = 0x000B; // 要读取的寄存器数量 (40001 到 40012) - List commandValues = new List { 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; // 红色闪烁 且蜂鸣器响 + List commandValues = new List { 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; // 绿灯常亮 且蜂鸣器关闭 // 发送写指令到警灯设备 _modbusClient.WriteMultipleRegisters(unitId, startAddress, commandValues); Console.WriteLine($"已向从站 {unitId} 的寄存器 {startAddress} 写入指令: {string.Join(", ", commandValues)}"); diff --git a/ZR.Service/mes/andon/AndonAlarmRecordService.cs b/ZR.Service/mes/andon/AndonAlarmRecordService.cs index b9bd8361..e337f983 100644 --- a/ZR.Service/mes/andon/AndonAlarmRecordService.cs +++ b/ZR.Service/mes/andon/AndonAlarmRecordService.cs @@ -29,6 +29,7 @@ namespace ZR.Service.mes.andon private AndonAlarmTypeDictService andonAlarmTypeDictService = new AndonAlarmTypeDictService(); private SocketGatewayServer _socketGateway = null; private readonly ModbusTcpClientHelper _modbusClient; + private AndonAlarmAreaLightDicService _andonAlarmAreaLightDicService = new AndonAlarmAreaLightDicService(); public AndonAlarmRecordService(SocketGatewayServer socketGateway, ModbusTcpClientHelper modbusClient) { @@ -243,6 +244,9 @@ namespace ZR.Service.mes.andon andonAlarmRecordProcess.UpdatedName = parm.UserName; andonAlarmRecordProcess.UpdatedTime = DateTime.Now; int iResult = andonAlarmRecordProcessService.Insert(andonAlarmRecordProcess); + //三色灯变黄 + byte bLightIp = GetLightIp(parm.Area1, parm.Area2); + LightUp.WriteAlarmLightCommand_Yellow(_modbusClient, bLightIp); return ApiResult.Success("成功", andonAlarmRecordProcess); } } @@ -297,6 +301,9 @@ namespace ZR.Service.mes.andon andonAlarmRecordProcess.UpdatedName = parm.UserName; andonAlarmRecordProcess.UpdatedTime = DateTime.Now; int iResult = andonAlarmRecordProcessService.Insert(andonAlarmRecordProcess); + //三色灯变绿 + byte bLightIp = GetLightIp(parm.Area1, parm.Area2); + LightUp.WriteAlarmLightCommand_Normal(_modbusClient, bLightIp); return ApiResult.Success("成功", andonAlarmRecordProcess); } else @@ -342,7 +349,8 @@ namespace ZR.Service.mes.andon //报警给领导 //Watchup.StartPush("123456789", _socketGateway); - LightUp.WriteAlarmLightCommand_Red(_modbusClient, 15); + byte bLightIp = GetLightIp(parm.Area1,parm.Area2); + LightUp.WriteAlarmLightCommand_Red(_modbusClient, bLightIp); return ApiResult.Success("成功", andonAlarmRecordProcess); } else @@ -356,6 +364,24 @@ namespace ZR.Service.mes.andon } } + private byte GetLightIp(string area1, string area2) + { + byte bLightIp = 0; + if (area2 == null || area2 == "") + { + area2 = "NA"; + } + var query = _andonAlarmAreaLightDicService.Queryable() + .Where(x => x.Area1 == area1 && x.Area2 == area2) + .ToList().FirstOrDefault(); + if (query != null) + { + string lightIp = query.Lightip; + bLightIp = Convert.ToByte(lightIp); + } + return bLightIp; + } + /// /// 创建报警记录 /// @@ -393,7 +419,8 @@ namespace ZR.Service.mes.andon } string strMessage = model.Area1+ model.Area2+model.AlarmType + model.AlarmInfo; //Watchup.StartPush(strMessage, _socketGateway); - LightUp.WriteAlarmLightCommand_Red(_modbusClient, 15); + byte bLightIp = GetLightIp(model.Area1, model.Area2); + LightUp.WriteAlarmLightCommand_Red(_modbusClient, bLightIp); return Context.Insertable(model).ExecuteReturnEntity(); }