hwh
2024-09-03 c56d28d684cee010f291295dbe851bab64c1b6a6
Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -21,8 +21,12 @@
    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
    {
        get { return listPlcUtil; }
    }
    public static event EventHandler DeviceValueChangeEvent;
    static PLCTaskAction()
    {
@@ -60,6 +64,7 @@
        cts = new CancellationTokenSource();
        boRunningState = true;
        StartRead();
        ConnectionStatus();
    }
    /// <summary>
    /// 开启读取plc线程
@@ -78,19 +83,21 @@
                    {
                        foreach (var modPlcUtil in listPlcUtil)
                        {
                            modPlcUtil.Close();
                            if (modPlcUtil != null && modPlcUtil.Connected)
                                modPlcUtil.Close();
                        }
                        break;
                        throw new OperationCanceledException();
                    }
                    try
                    {
                        var modPlcUtil = listPlcUtil.FirstOrDefault(s => s.PlcId == modPlc.Id);
                        var modPlcUtil = listPlcUtil.FirstOrDefault(s => s != null && s.PlcId == modPlc.Id);
                        if (modPlcUtil == null)
                        {
                            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))
                        {
@@ -105,9 +112,9 @@
                                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
                            {