123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.Routine;
- using MECF.Framework.Common.TwinCat;
- using CyberX8_Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using MECF.Framework.Common.IOCore;
- namespace CyberX8_RT.Devices.Safety
- {
- public class SafetyArmResetRoutine : RoutineBase, IRoutine
- {
- private enum SafetyToggleStep
- {
- WriteFalse,
- WriteTrue,
- End
- }
- #region 内部变量
- /// <summary>
- /// do名称
- /// </summary>
- private string _doName = "";
- /// <summary>
- /// 写入数值
- /// </summary>
- private double _doWriteValue = 0;
- /// <summary>
- /// 设备
- /// </summary>
- private SafetyDevice _device;
- /// <summary>
- /// 超晨
- /// </summary>
- private int _timeout = 1000;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public SafetyArmResetRoutine(string module) : base(module)
- {
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop($"Manual Safty {_doName} Toggle");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(SafetyToggleStep.WriteFalse, () => { return WriteDoValue(0); }, CheckDoValue, _timeout)
- .Run(SafetyToggleStep.WriteTrue, () => { return WriteDoValue(1); }, CheckDoValue, _timeout)
- .End(SafetyToggleStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- /// 写入do数值
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- private bool WriteDoValue(double value)
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{_doName}");
- _doWriteValue = value;
- return IOModuleManager.Instance.WriteIoValue(ioName, value);
- }
- /// <summary>
- /// 检验do的数值
- /// </summary>
- /// <returns></returns>
- private bool CheckDoValue()
- {
- PropertyInfo propertyInfo = _device.SafetyData.GetType().GetProperty(_doName);
- if (propertyInfo != null)
- {
- double doValue = (double)propertyInfo.GetValue(_device.SafetyData);
- return doValue==_doWriteValue;
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_SAFETY, Module, $"{_doName} in not in property");
- return false;
- }
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<SafetyDevice>(Module);
- _doName= objs[0].ToString();
- return Runner.Start(Module, $"{_doName} toggle");
- }
- }
- }
|