| | |
| | | { |
| | | AllAxisOn(); |
| | | |
| | | MonitorPosition(); |
| | | MonitorAxisStatus(); |
| | | |
| | | base.Start(); |
| | | } |
| | | |
| | |
| | | return axisMovingStatusesList; |
| | | } |
| | | |
| | | |
| | | public List<IOItem> GetMonitorValues() |
| | | { |
| | | var result = new List<IOItem>(); |
| | |
| | | return result; |
| | | } |
| | | |
| | | SpinWait _positionWait = new SpinWait(); |
| | | private async void MonitorPosition() |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) |
| | | { |
| | | try |
| | | { |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | |
| | | AxisStatusList.ForEach(a => |
| | | { |
| | | int curPosition = (int)GetPrfPosition(a.AxisIndex); |
| | | |
| | | if (a.CurPosition != curPosition) |
| | | { |
| | | a.CurPosition = curPosition; |
| | | AxisPositionChanged(a.AxisIndex, curPosition); |
| | | } |
| | | }); |
| | | |
| | | _positionWait.SpinOnce(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | LogAsync(DateTime.Now, $"{this.Name}监听轴信息异常", ex.GetExceptionMessage()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | SpinWait _statusWait = new SpinWait(); |
| | | private async void MonitorAxisStatus() |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) |
| | | { |
| | | try |
| | | { |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | |
| | | AxisStatusList.ForEach(a => |
| | | { |
| | | int curStatus = GetAxisStatus(a.AxisIndex); |
| | | |
| | | if (a.AxisStatus != curStatus) |
| | | { |
| | | int temp = a.AxisStatus; |
| | | a.AxisStatus = curStatus; |
| | | AxisStatusChanged(a.AxisIndex, temp, curStatus); |
| | | } |
| | | }); |
| | | |
| | | _statusWait.SpinOnce(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | LogAsync(DateTime.Now, $"{this.Name}监听轴信息异常", ex.GetExceptionMessage()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public async override void Monitor() |
| | | { |
| | | await Task.Run(() => |
| | |
| | | return; |
| | | |
| | | var newValues = GetMonitorValues(); |
| | | var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | //var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | |
| | | if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0) |
| | | if (newValues == null || newValues.Count == 0 ) |
| | | continue; |
| | | |
| | | //Stopwatch sw = new Stopwatch(); |
| | |
| | | MonitorCheckAndInvoke(tempNew, tempOld); |
| | | } |
| | | |
| | | if (AxisStatusList.Count == newAxisMovingStatus.Count) |
| | | { |
| | | var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone |
| | | var tempOld = new List<AxisMovingStatus>(AxisStatusList); |
| | | AxisStatusCheck(tempNew, tempOld); |
| | | } |
| | | //if (AxisStatusList.Count == newAxisMovingStatus.Count) |
| | | //{ |
| | | // var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone |
| | | // var tempOld = new List<AxisMovingStatus>(AxisStatusList); |
| | | // AxisStatusCheck(tempNew, tempOld); |
| | | //} |
| | | |
| | | AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | //AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | MonitorValues = new List<IOItem>(newValues); |
| | | //sw.Stop(); |
| | | |