| | |
| | | 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>(); |
| | |
| | | { |
| | | //订阅事件 |
| | | 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连接 |
| | |
| | | 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 |
| | | }); |
| | | if (boRunningState) |
| | | { |
| | | cts = new CancellationTokenSource(); |
| | | StartRead(); |
| | | ConnectionStatus(); |
| | | StartWatchAlarm(); |
| | | StartWatchPosition(); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 开启读取plc线程 |
| | | /// </summary> |