三色灯
This commit is contained in:
parent
cd60096fe9
commit
62bb089231
@ -19,12 +19,11 @@ using ZR.Service.mqtt;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
//后台定时任务
|
||||
//builder.Services.AddHostedService<ScheduledBackgroundService>();
|
||||
//builder.Services.AddHostedService<SocketBackgroundService>();
|
||||
//builder.Services.AddHostedService<ScheduledBackgroundService>()builder.Services.AddHostedService<SocketBackgroundService>();
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllers();
|
||||
//配置中心
|
||||
//builder.Configuration.AddNacosV2Configuration(builder.Configuration.GetSection("NacosConfig"));
|
||||
//服务注册
|
||||
|
||||
@ -69,7 +69,7 @@ namespace ZR.Service.Utils.MyAlarmLigth
|
||||
{
|
||||
ushort startAddress = 0x0000; // 起始地址,对应
|
||||
ushort numberOfRegisters = 0x000B; // 要读取的寄存器数量 (40001 到 40012)
|
||||
List<ushort> commandValues = new List<ushort> { 0x0000, 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000A }; // 红色闪烁 且蜂鸣器响
|
||||
List<ushort> commandValues = new List<ushort> { 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<ushort> commandValues = new List<ushort> { 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; // 红色闪烁 且蜂鸣器响
|
||||
List<ushort> commandValues = new List<ushort> { 0x0000, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; // 绿灯常亮 且蜂鸣器关闭
|
||||
// 发送写指令到警灯设备
|
||||
_modbusClient.WriteMultipleRegisters(unitId, startAddress, commandValues);
|
||||
Console.WriteLine($"已向从站 {unitId} 的寄存器 {startAddress} 写入指令: {string.Join(", ", commandValues)}");
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建报警记录
|
||||
/// </summary>
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user