| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设备 运行 |
| | | /// 设备 运行(执行 板卡系列的操作的 集合) |
| | | /// </summary> |
| | | /// <param name="config"></param> |
| | | /// <returns></returns> |
| | | public override ResponseMessage Run(IOperationConfig config) |
| | | { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | var opConfig = config as GTSCardOperationConfig; |
| | | var motionCardOperationConfig = config as MotionCardOperationConfigBase; |
| | | foreach (var operationSet in motionCardOperationConfig.OperationCollection) |
| | | { |
| | | responseMessage = RunOperationSet(operationSet); |
| | | if (!responseMessage.Result) |
| | | { |
| | | return responseMessage; |
| | | } |
| | | } |
| | | return responseMessage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行 一个系列的操作 |
| | | /// </summary> |
| | | private ResponseMessage RunOperationSet(MotionCardOperationSet operationSet) |
| | | { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | // 1.预检查 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | foreach (var preCheck in opConfig.PreCheckIOCollection) |
| | | foreach (var preCheck in operationSet.PreCheckIOCollection) |
| | | { |
| | | int timeout = opConfig.PreCheckIOTimeout; |
| | | int? ioData = null; |
| | | int timeout = operationSet.PreCheckIOTimeout; |
| | | IOValue? ioData = null; |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | Thread.Sleep(10); |
| | | ioData = MonitorValues.FirstOrDefault(u => u.IONum == preCheck.IOItem.IONum && u.IOType == preCheck.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | timeout -= 10; |
| | | if (preCheck.CheckValue == ioData || (opConfig.PreCheckIOTimeout > 0 && timeout < 0)) |
| | | if (preCheck.CheckValue == ioData || (operationSet.PreCheckIOTimeout > 0 && timeout < 0)) |
| | | { |
| | | break; |
| | | } |
| | |
| | | // 2.板卡运动 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | responseMessage = MoveToPoint(opConfig); |
| | | |
| | | responseMessage = MoveToPoint(operationSet.MotionOperationCollection); |
| | | if (!responseMessage.Result) |
| | | { |
| | | return responseMessage; |
| | |
| | | // 3.IO输出 不需要超时 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | foreach (var ioOutput in opConfig.IOOutputCollection) |
| | | foreach (var ioOutput in operationSet.IOOutputCollection) |
| | | { |
| | | var ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioOutput.IOItem.IONum && u.IOType == ioOutput.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | if (ioOutput.CheckValue != ioData) |
| | |
| | | // 4.IO确认 |
| | | if (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | foreach (var ioConfirm in opConfig.IOConfirmCollection) |
| | | foreach (var ioConfirm in operationSet.IOConfirmCollection) |
| | | { |
| | | int timeout = opConfig.IOConfirmTimeout; |
| | | int? ioData = null; |
| | | int timeout = operationSet.IOConfirmTimeout; |
| | | IOValue? ioData = null; |
| | | while (CurrentState == DeviceState.DSOpen) |
| | | { |
| | | Thread.Sleep(10); |
| | | ioData = MonitorValues.FirstOrDefault(u => u.IONum == ioConfirm.IOItem.IONum && u.IOType == ioConfirm.IOItem.IOType)?.Value;//IO 是开、关 从MonitorValues 获取 |
| | | timeout -= 10; |
| | | if (ioConfirm.CheckValue == ioData || (opConfig.IOConfirmTimeout > 0 && timeout < 0)) |
| | | if (ioConfirm.CheckValue == ioData || (operationSet.IOConfirmTimeout > 0 && timeout < 0)) |
| | | { |
| | | break; |
| | | } |
| | |
| | | public override ResponseMessage MoveToPoint(IOperationConfig opConfig) |
| | | { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | var gtsOperationConfig = opConfig as GTSCardOperationConfig; |
| | | var gtsOperationCollection = opConfig as MotionOperationCollection; |
| | | List<Task<bool>> taskList = new List<Task<bool>>(); |
| | | //TaskFactory factory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None); |
| | | // 如果是多个轴的运动 等每个轴运动结束 |
| | | foreach (var movingOp in gtsOperationConfig.MovingOps) |
| | | foreach (var movingOp in gtsOperationCollection.MovingOps) |
| | | { |
| | | //var task = factory.StartNew<bool>((op) => |
| | | //{ |
| | | // return SingleAxisMoving(op as MovingOption); |
| | | //}, movingOp); |
| | | var task = SingleAxisMoving(movingOp); |
| | | taskList.Add(task); |
| | | } |
| | | |
| | | Task.WaitAll(taskList.ToArray()); |
| | | responseMessage.Result = taskList.All(u => u.GetAwaiter().GetResult()); |
| | | if (!responseMessage.Result) |
| | |
| | | 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> |
| | | /// <param name="index">输出口,返回1-16</param> |
| | | /// <param name="value">false表示输出,true表示关闭</param> |
| | | public void WriteOut(short index, bool value) |
| | | public override void WriteOutput(short cardNum, short index, IOValue value) |
| | | { |
| | | short outNum = (short)(index % 100 + 1); |
| | | if (value) |
| | | if ((int)value <= 1) |
| | | { |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, 0); |
| | | GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value); |
| | | } |
| | | else |
| | | { |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPO, outNum, 1); |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | #region IMonitor |
| | | |
| | | public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); |
| | | //public List<IOItem> MonitorValues { get; set; } = new List<IOItem>(); |
| | | |
| | | |
| | | public List<IOItem> GetMonitorValues() |
| | |
| | | IOItem inItem = new IOItem() |
| | | { |
| | | IONum = index, |
| | | Value = (inValue & (1 << index)) == 0 ? 1 : 0, |
| | | Value = (inValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE, |
| | | IOType = IOType.INPUT |
| | | }; |
| | | IOItem outItem = new IOItem() |
| | | { |
| | | IONum = index, |
| | | Value = (outValue & (1 << index)) == 0 ? 1 : 0, |
| | | Value = (outValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE, |
| | | IOType = IOType.OUTPUT |
| | | }; |
| | | result.Add(inItem); |
| | |
| | | }); |
| | | } |
| | | |
| | | private void OnMethodInvoked(IAsyncResult ar) |
| | | public override void OnMethodInvoked(IAsyncResult ar) |
| | | { |
| | | MotionCardMonitorSet monitorSet = ar.AsyncState as MotionCardMonitorSet; |
| | | ProcessResponse resValues = monitorSet.Response; |
| | |
| | | { |
| | | MotionCardWarningSet warningSet = wSet as MotionCardWarningSet; |
| | | |
| | | bool isOn = ((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0); |
| | | bool isOn = (((int)((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value)) >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0); |
| | | |
| | | if (warningSet.CurrentStatus != isOn) |
| | | { |
| | | warningSet.CurrentStatus = isOn; |
| | | warningSet.TriggerTime = DateTime.Now; |
| | | warningSet.WarningDescription = $"警报:{warningSet.Name}-触发索引:{warningSet.TriggerIndex}-{warningSet.WarningIOModel.GetEnumDescription()}:{warningSet.WarningCode}"; |
| | | SaveAlarmCSVAsync(DateTime.Now, this.Name, warningSet); |
| | | ExcuteMonitorAlarm(DateTime.Now, this, warningSet); |
| | | } |
| | |
| | | |
| | | if (newIOItem?.Value != oldIOItem?.Value) |
| | | { |
| | | if (monitorSet.TriggerValue == -999 || newIOItem.Value == monitorSet.TriggerValue) |
| | | if (monitorSet.TriggerValue == -999 || (int)newIOItem.Value == monitorSet.TriggerValue) |
| | | { |
| | | if (monitorSet.OpConfig == null) |
| | | { |
| | |
| | | // return tempNew[index].Value; |
| | | //}).ToList(); |
| | | |
| | | ExcuteMonitorInvok(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet, OnMethodInvoked); |
| | | ExcuteMonitorInvoke(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet); |
| | | } |
| | | } |
| | | }); |