chengsc
2024-09-11 2f0e0fa257c147a223d79ff8a52118768f43eee8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Furion.InstantMessaging;
using Microsoft.AspNetCore.SignalR;
 
namespace WCS.Application;
 
/// <summary>
/// 任务日志集线器
/// </summary>
[MapHub("/hubs/Plc")]
public class PlcHub : Hub<IPlcHub>
{
    private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext;
    private readonly SysConfigService _sysConfigService;
    public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext, SysConfigService sysConfigService)
    {
        _plcHubContext = plcHubContext;
        _sysConfigService = sysConfigService;
    }
    /// <summary>
    /// 下发PLC连接状态
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    public async Task PublicPlcConn(WcsPlc context)
    {
        await _plcHubContext.Clients.All.PublicPlcConn(context);
    }
 
    /// <summary>
    /// 下发工位状态
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    //public async Task PublicStationStatus(List<WcsDevice> context)
    //{
    //    await _plcHubContext.Clients.All.PublicStationStatus(context);
    //}
 
    /// <summary>
    /// 下发服务状态
    /// </summary>
    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, BoDemo = PLCTaskAction.boDemo});
    }
}
public class PLCServiceModel
{
    public bool? BoRunningState { get; set; }
 
 
    public bool? BoOffline { get; set; }
 
 
    public bool? BoRefresh { get; set; }
 
    public bool? BoDemo { get; set; }
}