wxw
2024-09-06 d89bbfdd748109020f3255c80918d0f60b6e842c
Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -19,6 +19,7 @@
    private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
    private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>();
    private static readonly IHubContext<PlcHub, IPlcHub> _plcHubContext = App.GetService<IHubContext<PlcHub, IPlcHub>>();
    private static readonly SysConfigService _sysConfigService = App.GetService<SysConfigService>();
    private static List<WcsPlc> listPlc = new List<WcsPlc>();
    private static List<WcsDevice> listPlcDevice = new List<WcsDevice>();
@@ -37,6 +38,9 @@
    {
        //订阅事件
        DeviceValueChangeEvent += PLCService.OnChangeEvent;
        boRunningState = _sysConfigService.GetConfigValue<bool>("sys_RunningState").Result;
        boOffline = _sysConfigService.GetConfigValue<bool>("sys_Offline").Result;
        boRefresh = _sysConfigService.GetConfigValue<bool>("sys_Refresh").Result;
    }
    /// <summary>
    /// 初始化PLC连接
@@ -60,18 +64,20 @@
            var plc = new PLCUtil(modPlc);
            listPlcUtil.Add(plc);
        }
        cts = new CancellationTokenSource();
        boRunningState = true;
        _plcHubContext.Clients.All.UpdateService(new PLCServiceModel()
        {
            BoRunningState = boRunningState,
            BoOffline = boOffline,
            BoRefresh = boRefresh
        });
        StartRead();
        ConnectionStatus();
        StartWatchAlarm();
        StartWatchPosition();
        if (boRunningState)
        {
            cts = new CancellationTokenSource();
            StartRead();
            ConnectionStatus();
            StartWatchAlarm();
            StartWatchPosition();
        }
    }
    /// <summary>
    /// 开启读取plc线程