using Furion.InstantMessaging;
using Microsoft.AspNetCore.SignalR;
namespace WCS.Application;
///
/// 任务日志集线器
///
[MapHub("/hubs/Plc")]
public class PlcHub : Hub
{
private readonly IHubContext _plcHubContext;
private readonly SysConfigService _sysConfigService;
public PlcHub(IHubContext plcHubContext, SysConfigService sysConfigService)
{
_plcHubContext = plcHubContext;
_sysConfigService = sysConfigService;
}
///
/// 下发PLC连接状态
///
///
///
public async Task PublicPlcConn(WcsPlc context)
{
await _plcHubContext.Clients.All.PublicPlcConn(context);
}
///
/// 下发工位状态
///
///
///
//public async Task PublicStationStatus(List context)
//{
// await _plcHubContext.Clients.All.PublicStationStatus(context);
//}
///
/// 下发服务状态
///
public async Task UpdateService(PLCServiceModel context)
{
//运行状态
if (context.BoRunningState.HasValue)
{
PLCTaskAction.boRunningState = context.BoRunningState.Value;
if (context.BoRunningState.Value)
PLCTaskAction.Init();
else
PLCTaskAction.Stop();
await _sysConfigService.UpdateConfigValue("sys_RunningState", context.BoRunningState.Value);
}
//脱机模式
if (context.BoOffline.HasValue)
{
PLCTaskAction.boOffline = context.BoOffline.Value;
await _sysConfigService.UpdateConfigValue("sys_Offline", context.BoOffline.Value);
}
//自刷新
if (context.BoRefresh.HasValue)
{
PLCTaskAction.boRefresh = context.BoRefresh.Value;
await _sysConfigService.UpdateConfigValue("sys_Refresh", context.BoRefresh.Value);
}
await _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() { BoRunningState = PLCTaskAction.boRunningState, BoRefresh = PLCTaskAction.boRefresh, BoOffline = PLCTaskAction.boOffline });
}
}
public class PLCServiceModel
{
public bool? BoRunningState { get; set; }
public bool? BoOffline { get; set; }
public bool? BoRefresh { get; set; }
}