| | |
| | | private static List<WcsPosition> listPlcStation; |
| | | |
| | | private static List<PLCUtil> listPlcUtil = new List<PLCUtil>(); |
| | | private static CancellationTokenSource cts;//取消线程标识 |
| | | private static CancellationTokenSource cts = new CancellationTokenSource();//取消线程标识 |
| | | //对外公布连接状态 |
| | | public static List<PLCUtil> listPlcConn |
| | | { |
| | |
| | | cts = new CancellationTokenSource(); |
| | | boRunningState = true; |
| | | StartRead(); |
| | | ConnectionStatus(); |
| | | } |
| | | /// <summary> |
| | | /// 开启读取plc线程 |
| | |
| | | { |
| | | foreach (var modPlcUtil in listPlcUtil) |
| | | { |
| | | modPlcUtil.Close(); |
| | | if (modPlcUtil != null && modPlcUtil.Connected) |
| | | modPlcUtil.Close(); |
| | | } |
| | | break; |
| | | throw new OperationCanceledException(); |
| | | } |
| | | try |
| | |
| | | modPlcUtil = new PLCUtil(modPlc); |
| | | listPlcUtil.Add(modPlcUtil); |
| | | } |
| | | var listDevice = listPlcDevice.Where(s => s.PlcId == _modplc.Id).ToList(); |
| | | var listDevice = listPlcDevice.Where(s => s.PlcId == _modplc.Id && s.DeviceType == DeviceTypeEnum.Business).ToList(); |
| | | //循环读设备 |
| | | foreach (var modDevice in listDevice.Where(s => s.Level == DeviceLevelEnum.DB)) |
| | | { |
| | |
| | | dto.Type = _modplc.Type; |
| | | dto.PLCUtil = modPlcUtil; |
| | | dto.listStation = listPlcStation.Where(s => s.DeviceId == modDevice.Id).ToList(); |
| | | dto.listDevice = listDevice.Where(s => s.StationNum == modDevice.StationNum).ToList(); |
| | | dto.listDevice = listDevice.Where(s => s.StationNum == modDevice.StationNum && s.Level == DeviceLevelEnum.Station).ToList(); |
| | | //这里触发值变更事件 |
| | | DeviceValueChangeEvent?.Invoke(dto, EventArgs.Empty); |
| | | //DeviceValueChangeEvent?.Invoke(dto, EventArgs.Empty); |
| | | } |
| | | else |
| | | { |