using Aitex.Core.RT.Log; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using MECF.Framework.Common.Beckhoff.ModuleIO; using MECF.Framework.Common.Device.Festo; using MECF.Framework.Common.TwinCat; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.Device.Galil { public class GalilAxisManager : Singleton { #region 内部变量 /// /// 模块变量更新委托字典(key-模块.变量,value-变量委托事件 /// private Dictionary _moduleVariableActionDic = new Dictionary(); /// /// 变量数值字典(key-io变量名称,value-数值) /// private Dictionary _nameVariableValueDic = new Dictionary(); #endregion /// /// 注册变量数值发生变化回调 /// /// /// /// public void SubscribeModuleVariable(string moduleName, string variable, BeckhoffDelegate.OnUpdateModuleVariableValue onUpdateModuleVariableValue) { string name = $"{moduleName}.{variable}"; _moduleVariableActionDic[name] = onUpdateModuleVariableValue; if (_nameVariableValueDic.ContainsKey(name)) { _moduleVariableActionDic[name].Invoke(variable, _nameVariableValueDic[name]); } } /// /// 更新IO数值 /// /// /// public void UpdateIoValue(string name, object value) { bool _enableRead = SC.GetValue("Twincat.EnableReadLog"); if (_enableRead) { LOG.WriteBackgroundLog(eEvent.INFO_GALIL, "System", $"read {name} value {value}"); } _nameVariableValueDic[name] = value; if (_moduleVariableActionDic.ContainsKey(name)) { string[] strAry = name.Split('.'); if (strAry.Length != 0) { _moduleVariableActionDic[name].Invoke(strAry[strAry.Length - 1], value); } } } } }