| | |
| | | { |
| | | AllAxisOn(); |
| | | |
| | | MonitorPosition(); |
| | | MonitorAxisStatus(); |
| | | |
| | | base.Start(); |
| | | } |
| | | |
| | |
| | | // 设置点位模式运动参数 |
| | | sRtn = GTSCardAPI.GT_SetTrapPrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, ref trapPrm); |
| | | // 设置点位模式目标速度,即回原点速度 |
| | | sRtn = GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)movingOption.AxisIndex, goHomePara.HighVelocity); |
| | | sRtn = GTSCardAPI.GT_SetVel((short)IConfig.CardNum, (short)movingOption.AxisIndex, goHomePara.HomeVelocity); |
| | | |
| | | do |
| | | { |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | |
| | | //搜索距离 阶段1 |
| | | // 启动Home捕获 |
| | | sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | if (goHomePara.IsCaptureMode) |
| | | { |
| | | //搜索距离 阶段1 |
| | | // 启动Home捕获 |
| | | sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | } |
| | | |
| | | // 设置点位模式目标位置,即原点搜索距离 |
| | | sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, homeDirection ? 99999999 : -99999999); |
| | |
| | | int repeatTime = goHomePara.GoHomeTimeOut * 1000; |
| | | |
| | | bool isStop = false; |
| | | int pos; |
| | | int pos = 0; |
| | | uint clk;//时钟参数 |
| | | |
| | | int checkInterval = IConfig.MonitorInterval; |
| | | if (IConfig.MonitorInterval <= 0) |
| | | { |
| | | checkInterval = 10; |
| | | } |
| | | |
| | | do |
| | | { |
| | | Thread.Sleep(IConfig.MonitorInterval * 5); |
| | | // 读取捕获状态 |
| | | GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk); |
| | | Thread.Sleep(checkInterval * 2); |
| | | |
| | | if (goHomePara.IsCaptureMode) |
| | | { |
| | | // 读取捕获状态 |
| | | GTSCardAPI.GT_GetCaptureStatus((short)IConfig.CardNum, (short)movingOption.AxisIndex, out capture, out pos, 1, out clk); |
| | | } |
| | | else |
| | | { |
| | | GTSCardAPI.GT_GetDi((short)IConfig.CardNum, GTSCardAPI.MC_HOME, out int pValue); |
| | | |
| | | capture = (short)((pValue & (1 << (movingOption.AxisIndex - 1))) == 0 ? 1 : 0); |
| | | } |
| | | isStop = IsStop((short)movingOption.AxisIndex); |
| | | repeatTime -= IConfig.MonitorInterval * 5; |
| | | repeatTime -= checkInterval * 2; |
| | | } while (!(isStop || capture == 1 || repeatTime <= 0)); |
| | | |
| | | if (repeatTime <= 0) |
| | |
| | | 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(); |
| | | |