| | |
| | | { |
| | | AllAxisOn(); |
| | | |
| | | MonitorPosition(); |
| | | MonitorAxisStatus(); |
| | | |
| | | base.Start(); |
| | | } |
| | | |
| | |
| | | short capture = 0; |
| | | |
| | | GTSCardAPI.TTrapPrm trapPrm; |
| | | //搜索距离 阶段1 |
| | | // 启动Home捕获 |
| | | short sRtn = GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | |
| | | // 切换到点位运动模式 |
| | | sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex); |
| | | short sRtn = GTSCardAPI.GT_PrfTrap((short)IConfig.CardNum, (short)movingOption.AxisIndex); |
| | | // 读取点位模式运动参数 |
| | | sRtn = GTSCardAPI.GT_GetTrapPrm((short)IConfig.CardNum, (short)movingOption.AxisIndex, out trapPrm); |
| | | trapPrm.acc = movingOption.VelocityPara.Acc; |
| | |
| | | { |
| | | PositionReset(movingOption.AxisIndex, 1); |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | |
| | | //搜索距离 阶段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); |
| | |
| | | |
| | | if (isStop && capture != 1) |
| | | { |
| | | ClearStatus((short)movingOption.AxisIndex, 1); |
| | | |
| | | if (((axisStatus.AxisStatus & 0x20) != 0) || ((axisStatus.AxisStatus & 0x40) != 0)) |
| | | { |
| | | //movingOption.GoHomePara.HomeDir = (short)(movingOption.GoHomePara.HomeDir == 1 ? -1 : 1); |
| | |
| | | isRightLimitReached = true; |
| | | } |
| | | |
| | | |
| | | //负限位 |
| | | if ((axisStatus.AxisStatus & 0x40) != 0 && goHomePara.IsCaptureDirPositive) |
| | | { |
| | |
| | | |
| | | homeDirection = !homeDirection; |
| | | } |
| | | |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | } |
| | | |
| | | if (capture == 1) |
| | |
| | | if (!isRightLimitReached) |
| | | { |
| | | capture = 0; |
| | | ClearStatus(movingOption.AxisIndex, 1); |
| | | //GTSCardAPI.GT_SetCaptureMode((short)IConfig.CardNum, (short)movingOption.AxisIndex, GTSCardAPI.CAPTURE_HOME); |
| | | continue; |
| | | } |
| | |
| | | //先stop |
| | | MoveStop((short)movingOption.AxisIndex, 0); |
| | | ClearStatus((short)movingOption.AxisIndex, 1); |
| | | |
| | | //已经捕获到Home才可以回零 阶段2 |
| | | // 运动到"捕获位置+偏移量" |
| | | sRtn = GTSCardAPI.GT_SetPos((short)IConfig.CardNum, (short)movingOption.AxisIndex, pos + goHomePara.HomeOffset); |
| | |
| | | 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(); |
| | | |