| | |
| | | public class GTSCardDriver : MotionCardBase |
| | | { |
| | | // 异常事件 |
| | | public Action<Exception> OnExceptionRaised; |
| | | //public Action<Exception> OnExceptionRaised; |
| | | |
| | | public GTSCardInitialConfig IIConfig |
| | | { |
| | |
| | | { |
| | | AxisInfo axisInfo = new AxisInfo(); |
| | | axisInfo.AxisName = axisSetting.AxisName; |
| | | var axisMovingStatus = AxisMovingOptionValues.FirstOrDefault(u => u.AxisIndex == axisSetting.AxisIndex); |
| | | var axisMovingStatus = AxisStatusList.FirstOrDefault(u => u.AxisIndex == axisSetting.AxisIndex); |
| | | axisInfo.AxisLocation = axisMovingStatus == null ? 0 : Convert.ToDouble(axisMovingStatus.CurPosition); |
| | | |
| | | axisInfos.Add(axisInfo); |
| | |
| | | protected override void Start() |
| | | { |
| | | AllAxisOn(); |
| | | |
| | | base.Start(); |
| | | } |
| | | |
| | | protected override void Stop() |
| | |
| | | /// <summary> |
| | | /// 启动立即暂停 |
| | | /// </summary> |
| | | public void SetImmediatePause() |
| | | public override void SetImmediatePause() |
| | | { |
| | | if (!_isResetting) |
| | | { |
| | |
| | | /// <summary> |
| | | /// 恢复立即暂停 |
| | | /// </summary> |
| | | public void ResetImmediatePause() |
| | | public override void ResetImmediatePause() |
| | | { |
| | | var immediatePauseAxis = IConfig.AxisSettings.FindAll(a => a.IsAxisEnabled && a.IsImmediatePause).Select(u => u.AxisIndex).ToList(); |
| | | |
| | |
| | | catch (Exception ex) |
| | | { |
| | | AllMoveStop(true); |
| | | OnExceptionRaised?.Invoke(ex); |
| | | OnExceptionOccured?.Invoke(DateTime.Now, ex); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | catch (Exception ex) |
| | | { |
| | | AllMoveStop(true); |
| | | OnExceptionRaised?.Invoke(ex); |
| | | OnExceptionOccured?.Invoke(DateTime.Now, ex); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | catch (Exception ex) |
| | | { |
| | | AllMoveStop(true); |
| | | OnExceptionRaised?.Invoke(ex); |
| | | OnExceptionOccured?.Invoke(DateTime.Now, ex); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | catch (Exception ex) |
| | | { |
| | | AllMoveStop(true); |
| | | OnExceptionRaised?.Invoke(ex); |
| | | OnExceptionOccured?.Invoke(DateTime.Now, ex); |
| | | return false; |
| | | } |
| | | } |
| | |
| | | /// <param name="value">false表示输出,true表示关闭</param> |
| | | public override void WriteOutput(short index, IOValue value) |
| | | { |
| | | short outNum = (short)(index % 100); |
| | | short outNum = (short)(index % 100 + 1); |
| | | if ((int)value <= 1) |
| | | { |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, (short)value); |
| | |
| | | /// <returns></returns> |
| | | public bool IsStop(short axisNum) |
| | | { |
| | | int sts = GetAxisStatus(axisNum); |
| | | int sts = AxisStatusList.FirstOrDefault(u => u.AxisIndex == axisNum).AxisStatus; |
| | | if ((sts & 0x400) == 0) return true;//停止返回true |
| | | else return false; //运行中返回false |
| | | } |
| | |
| | | AxisMovingStatus axisMovingStatus = new AxisMovingStatus(); |
| | | axisMovingStatus.AxisIndex = axisConfig.AxisIndex; |
| | | axisMovingStatus.AxisName = axisConfig.AxisName; |
| | | axisMovingStatus.CurPosition = Convert.ToInt32(GetPosition(axisMovingStatus.AxisIndex)); |
| | | //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.CurVelocity = GetVelocity(axisMovingStatus.AxisIndex); |
| | | //axisMovingStatus.PrfVelocity = GetPrfVelocity(axisMovingStatus.AxisIndex); |
| | | axisMovingStatus.AxisStatus = GetAxisStatus(axisMovingStatus.AxisIndex); |
| | | |
| | | axisMovingStatusesList.Add(axisMovingStatus); |
| | |
| | | GTSCardAPI.GT_GetDo((short)IConfig.CardNum, GTSCardAPI.MC_GPO, out outValue); |
| | | |
| | | //解析结果 |
| | | for (var index = 1; index <= 16; index++) |
| | | for (var index = 0; index < 16; index++) |
| | | { |
| | | IOItem inItem = new IOItem() |
| | | { |
| | |
| | | { |
| | | if (!IConfig.IsEnableMonitor) |
| | | return; |
| | | |
| | | var newValues = GetMonitorValues(); |
| | | var newAxisMovingStatus = GetAxisMovingStatus(); |
| | | |
| | | if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0) |
| | | continue; |
| | | |
| | |
| | | sw.Start(); |
| | | if (MonitorValues.Count == newValues.Count) |
| | | { |
| | | var tempNew = newValues.DeepSerializeClone();//clone |
| | | var tempOld = MonitorValues.DeepSerializeClone(); |
| | | //var tempNew = newValues.DeepSerializeClone();//clone |
| | | //var tempOld = MonitorValues.DeepSerializeClone(); |
| | | var tempNew = new List<IOItem>(newValues);//clone |
| | | var tempOld = new List<IOItem>(MonitorValues); |
| | | MonitorCheckAndInvoke(tempNew, tempOld); |
| | | } |
| | | |
| | | AxisMovingOptionValues = new List<AxisMovingStatus>(newAxisMovingStatus); |
| | | 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); |
| | | MonitorValues = new List<IOItem>(newValues); |
| | | sw.Stop(); |
| | | |
| | |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | LogAsync(DateTime.Now, $"{this.Name}监听异常", ex.GetExceptionMessage()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private async void AxisStatusCheck(List<AxisMovingStatus> tempNew, List<AxisMovingStatus> tempOld) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | foreach (var newSts in tempNew) |
| | | { |
| | | var oldSts = tempOld.FirstOrDefault(u => u.AxisIndex == newSts.AxisIndex); |
| | | if (oldSts != null) |
| | | { |
| | | if (oldSts.AxisStatus != newSts.AxisStatus) |
| | | { |
| | | AxisStatusChanged(newSts.AxisIndex, oldSts.AxisStatus, newSts.AxisStatus); |
| | | } |
| | | |
| | | if (((newSts.AxisStatus >> 1 & 1) == 1) && ((oldSts.AxisStatus >> 1 & 1) == 0)) //初次报警 |
| | | { |
| | | AxisAlarmRaised(newSts.AxisStatus, $"轴{newSts.AxisIndex}:{newSts.AxisName}轴伺服报警"); |
| | | } |
| | | } |
| | | } |
| | |
| | | monitorSet.OpConfig = new OperationConfigBase(); |
| | | } |
| | | |
| | | //monitorSet.OpConfig.InputPara = monitorSet.InputDataIndex.ConvertAll(index => |
| | | //{ |
| | | // return tempNew[index].Value; |
| | | //}).ToList(); |
| | | monitorSet.OpConfig.InputPara = monitorSet.InputDataIndex.ConvertAll(index => |
| | | { |
| | | return tempNew[index].Value == IOValue.TRUE ? 1 : 0; |
| | | }).ToList(); |
| | | |
| | | ExcuteMonitorInvoke(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet); |
| | | } |
| | |
| | | ClearStatus(1, axisSettings.Count); |
| | | foreach (var axisSetting in axisSettings) |
| | | { |
| | | axis_sts = GetAxisStatus((short)axisSetting.AxisIndex); |
| | | //axis_sts = GetAxisStatus((short)axisSetting.AxisIndex); |
| | | axis_sts = AxisStatusList.FirstOrDefault(u => u.AxisIndex == axisSetting.AxisIndex).AxisStatus; |
| | | if ((axis_sts & 0x200) == 0) |
| | | { |
| | | var rst = GTSCardAPI.GT_AxisOn((short)IConfig.CardNum, (short)axisSetting.AxisIndex); |