| | |
| | | if (IConfig.AxisSettings.FirstOrDefault(a => a.AxisIndex == optionPara.AxisIndex)?.IsAxisEnabled ?? false) |
| | | { |
| | | string _position = ""; |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotorMoveMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | string motionType = optionPara.MoveMode == EnumHelper.MotionMode.Normal ? (optionPara.IsAbsolute ? "Abs" : "Rel") : optionPara.MoveMode.ToString(); |
| | | |
| | | _position = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff},{optionPara.AxisIndex},{motionType},{GetPosition(optionPara.AxisIndex)},{GetPrfPosition(optionPara.AxisIndex)},{optionPara.Destination},"; |
| | | |
| | | switch (optionPara.MoveMode) |
| | | { |
| | | case MotorMoveMode.Normal: |
| | | case MotionMode.Normal: |
| | | { |
| | | if (_isResetting) |
| | | { |
| | |
| | | |
| | | } |
| | | break; |
| | | case MotorMoveMode.FindOri: |
| | | case MotionMode.FindOri: |
| | | { |
| | | isSuccessAndStop = GoHome(optionPara); |
| | | } |
| | | break; |
| | | case MotorMoveMode.Jog: |
| | | case MotionMode.Jog: |
| | | { |
| | | isSuccessAndStop = JogMove(optionPara); |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取规划速度 |
| | | /// </summary> |
| | | /// <param name="axisNum">Axis number</param> |
| | | /// <returns></returns> |
| | | public double GetPrfVelocity(int axisNum) |
| | | { |
| | | double prfVel = 0; |
| | | uint pclock = 0; |
| | | var ret = GTSCardAPI.GT_GetPrfVel((short)IConfig.CardNum, (short)axisNum, out prfVel, 1, out pclock); |
| | | if (ret != (short)GTSRetCode.GRCRunOK) |
| | | { |
| | | throw new Exception("轴" + axisNum + "获取规划速度异常,错误码:" + ret); |
| | | } |
| | | prfVel = prfVel / IConfig.AxisVelocityRatio; |
| | | return prfVel; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前速度 |
| | | /// </summary> |
| | | /// <param name="axisNum">Axis number</param> |
| | | /// <returns></returns> |
| | | public double GetVelocity(int axisNum) |
| | | { |
| | | double vel = 0; |
| | | var ret = GTSCardAPI.GT_GetVel((short)IConfig.CardNum, (short)axisNum, out vel); |
| | | if (ret != (short)GTSRetCode.GRCRunOK) |
| | | { |
| | | throw new Exception("轴" + axisNum + "获取当前速度异常,错误码:" + ret); |
| | | } |
| | | vel = vel / IConfig.AxisVelocityRatio; |
| | | return vel; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Set Single Axis Do Jog Move |
| | | /// </summary> |
| | | /// <param name="axisNum">AxisNo</param> |
| | |
| | | |
| | | if (ret != (short)GTSRetCode.GRCRunOK) |
| | | { |
| | | LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "APS_absolute_move异常", "错误码:" + ret + ";" + "重试次数:" + repeatTime); |
| | | LogAsync(DateTime.Now, "轴" + optionPara.AxisIndex + "JogMove异常", "错误码:" + ret + ";" + "重试次数:" + repeatTime); |
| | | Thread.Sleep(10); |
| | | } |
| | | repeatTime--; |
| | |
| | | OnExceptionRaised?.Invoke(ex); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Set Single Axis Do stop Jog Move |
| | | /// </summary> |
| | | /// <param name="axisNum">AxisNo</param> |
| | | /// <returns></returns> |
| | | public bool StopJog(int axisNum) |
| | | { |
| | | //停止运动 |
| | | MoveStop(axisNum, 0); |
| | | //运动开始后 检查运动是否停止 |
| | | bool isStop = false; |
| | | int repeatTime = 1000; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)axisNum); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | | |
| | | return isStop; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | repeatTime = 1000; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)optionPara.AxisIndex); |
| | | isStop = IsStop((short)optionPara.AxisIndex); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | repeatTime = 1000; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)optionPara.AxisIndex); |
| | | isStop = IsStop((short)optionPara.AxisIndex); |
| | | Thread.Sleep(50); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | int repeatTime = 100; |
| | | do |
| | | { |
| | | isStop = IsStop((short)IConfig.CardNum, (short)axisNum); |
| | | isStop = IsStop((short)axisNum); |
| | | Thread.Sleep(10); |
| | | repeatTime--; |
| | | } while (!isStop && repeatTime > 0); |
| | |
| | | /// </summary> |
| | | /// <param name="index">输出口,返回1-16</param> |
| | | /// <param name="value">false表示输出,true表示关闭</param> |
| | | public override void WriteOutput(short cardNum, short index, IOValue value) |
| | | public override void WriteOutput(short index, IOValue value) |
| | | { |
| | | short outNum = (short)(index % 100 + 1); |
| | | if ((int)value <= 1) |
| | | { |
| | | GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value); |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)value); |
| | | } |
| | | else |
| | | { |
| | | var currentValue = (int)MonitorValues.FirstOrDefault(u => u.IONum == outNum && u.IOType == IOType.OUTPUT).Value; |
| | | GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1)); |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1)); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <param name="cardNum">板卡号</param> |
| | | /// <param name="axisNum">轴号</param> |
| | | /// <returns></returns> |
| | | public bool IsStop(short cardNum, short axisNum) |
| | | public bool IsStop(short axisNum) |
| | | { |
| | | int sts = GetAxisStatus(axisNum); |
| | | if ((sts & 0x400) == 0) return true;//停止返回true |
| | | else return false; //运行中返回false |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取轴状态 |
| | | /// </summary> |
| | | /// <param name="cardNum">板卡号</param> |
| | | /// <param name="axisNum">轴号</param> |
| | | /// <returns></returns> |
| | | public int GetAxisStatus(int axisNum) |
| | | { |
| | | lock (moveLock) |
| | | { |
| | | int sts = 0; |
| | | uint pclock = 0; |
| | | GTSCardAPI.GT_GetSts(cardNum, axisNum, out sts, 1, out pclock); |
| | | if ((sts & 0x400) == 0) return true;//停止返回true |
| | | else return false; //运行中返回false |
| | | GTSCardAPI.GT_GetSts((short)IConfig.CardNum, (short)axisNum, out sts, 1, out pclock); |
| | | return sts; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region IMonitor |
| | | |
| | | //public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); |
| | | public List<AxisMovingStatus> GetAxisMovingStatus() |
| | | { |
| | | List<AxisMovingStatus> axisMovingStatusesList = new List<AxisMovingStatus>(); |
| | | foreach (var axisConfig in IConfig.AxisSettings.FindAll(u => u.IsAxisEnabled)) |
| | | { |
| | | AxisMovingStatus axisMovingStatus = new AxisMovingStatus(); |
| | | axisMovingStatus.AxisIndex = axisConfig.AxisIndex; |
| | | axisMovingStatus.AxisName = axisConfig.AxisName; |
| | | axisMovingStatus.CurPosition = Convert.ToInt32(GetPosition(axisMovingStatus.AxisIndex)); |
| | | axisMovingStatus.Destination = Convert.ToInt32(GetPrfPosition(axisMovingStatus.AxisIndex)); |
| | | axisMovingStatus.CurVelocity = GetVelocity(axisMovingStatus.AxisIndex); |
| | | axisMovingStatus.PrfVelocity = GetPrfVelocity(axisMovingStatus.AxisIndex); |
| | | axisMovingStatus.AxisStatus = GetAxisStatus(axisMovingStatus.AxisIndex); |
| | | |
| | | axisMovingStatusesList.Add(axisMovingStatus); |
| | | |
| | | } |
| | | |
| | | return axisMovingStatusesList; |
| | | } |
| | | |
| | | |
| | | public List<IOItem> GetMonitorValues() |
| | |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | var newValues = GetMonitorValues(); |
| | | if (newValues == null || newValues.Count == 0) |
| | | var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0) |
| | | continue; |
| | | |
| | | Stopwatch sw = new Stopwatch(); |
| | |
| | | var tempOld = MonitorValues.DeepSerializeClone(); |
| | | MonitorCheckAndInvoke(tempNew, tempOld); |
| | | } |
| | | |
| | | AxisMovingOptionValues = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | MonitorValues = new List<IOItem>(newValues); |
| | | sw.Stop(); |
| | | |
| | |
| | | public override void ResetAlarm() |
| | | { |
| | | int axis_sts; |
| | | uint clk; |
| | | var axisSettings = IConfig.AxisSettings.FindAll(u => u.IsAxisEnabled); |
| | | GTSCardAPI.GT_ClrSts((short)IConfig.CardNum, 1, (short)axisSettings.Count); |
| | | foreach (var axisSetting in axisSettings) |
| | | { |
| | | GTSCardAPI.GT_GetSts((short)IConfig.CardNum, (short)axisSetting.AxisIndex, out axis_sts, 1, out clk); |
| | | axis_sts = GetAxisStatus((short)axisSetting.AxisIndex); |
| | | if ((axis_sts & 0x200) == 0) |
| | | { |
| | | var rst = GTSCardAPI.GT_AxisOn((short)IConfig.CardNum, (short)axisSetting.AxisIndex); |