123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using Aitex.Core.RT.Device;
- using MECF.Framework.Common.Beckhoff.IOAxis;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.IOCore;
- using MECF.Framework.Common.TwinCat;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace CyberX8_RT.Devices.Galil
- {
- public class GalilAxis : BaseDevice, IDevice
- {
- #region 常量
- private const string MOTOR_POSITION = "MotorPosition";
- private const string POSITION_ERROR = "PositionError";
- #endregion
- #region 内部变量
- /// <summary>
- /// 变量是否初始化字典
- /// </summary>
- private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
- /// <summary>
- /// 运动数据对象
- /// </summary>
- protected CommandMotionData _commandMotionData = new CommandMotionData();
- #endregion
- #region 属性
- /// <summary>
- /// 运动数据对象
- /// </summary>
- public CommandMotionData MotionData { get { return _commandMotionData; } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="moduleName"></param>
- /// <param name="name"></param>
- public GalilAxis(string moduleName, string name) : base(moduleName, name, name, name)
- {
- }
- #region public 公开方法
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- public bool Initialize()
- {
- SubscribeValueAction();
- return true;
- }
- /// <summary>
- /// 订阅变量数值发生变化
- /// </summary>
- protected void SubscribeValueAction()
- {
- BeckhoffIoSubscribeUpdateVariable(MOTOR_POSITION);
- BeckhoffIoSubscribeUpdateVariable(POSITION_ERROR);
- }
- /// <summary>
- /// 订阅IO变量
- /// </summary>
- /// <param name="variable"></param>
- private void BeckhoffIoSubscribeUpdateVariable(string variable)
- {
- _variableInitializeDic[variable] = false;
- IOModuleManager.Instance.SubscribeModuleVariable($"{Module}.{Name}", variable, UpdateVariableValue);
- }
- /// <summary>
- /// 更新变量数值
- /// </summary>
- /// <param name="variable"></param>
- /// <param name="value"></param>
- protected void UpdateVariableValue(string variable, object value)
- {
- if (value == null)
- {
- return;
- }
- if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
- {
- _variableInitializeDic[variable] = true;
- }
- UpdateMotionData(variable, value);
- }
- /// <summary>
- /// 更新运动数据
- /// </summary>
- /// <param name="variable"></param>
- /// <param name="value"></param>
- private void UpdateMotionData(string variable, object value)
- {
- if (!MotionData.IsDataInitialized)
- {
- MotionData.IsDataInitialized = true;
- }
- PropertyInfo property = MotionData.GetType().GetProperty(variable);
- if (property != null)
- {
- property.SetValue(MotionData, value);
- }
- }
- #endregion
- /// <summary>
- /// 监控
- /// </summary>
- public void Monitor()
- {
- }
- public void Reset()
- {
- }
- /// 停止
- /// </summary>
- public void Terminate()
- {
- }
- }
- }
|