using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.Beckhoff.IOAxis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.TwinCat { public class TwincatCoeManager : Singleton { #region 内部变量 /// /// 模块COE字典(key-模块名称,key-TwincatCoe接口对象) /// private Dictionary _moduleCoeInterfaceDic = new Dictionary(); /// /// 地址COE字典(key-NetId:Port,key-TwincatCoe接口对象) /// private Dictionary _addressInterfaceDic = new Dictionary(); #endregion /// /// 初始化 /// /// /// public void Initialize(BeckhoffAxis beckhoffAxis) { string address = $"{beckhoffAxis.COEAddress}.{beckhoffAxis.COEPort}"; if (!_addressInterfaceDic.ContainsKey(address)) { TwincatCoeInterface coeInterface = new TwincatCoeInterface(beckhoffAxis); _moduleCoeInterfaceDic[beckhoffAxis.Name] = coeInterface; _addressInterfaceDic[address] = coeInterface; coeInterface.Connect(); } else { _moduleCoeInterfaceDic[beckhoffAxis.Name] = _addressInterfaceDic[address]; } _addressInterfaceDic[address].InnitialInputAndOutputVariable(beckhoffAxis); } /// /// 启动读取输入变量 /// public void StartReadInput() { string[] strAry=_addressInterfaceDic.Keys.ToArray(); foreach (string item in strAry) { _addressInterfaceDic[item].StartReadInputDataThread(); } } /// /// 写变量数值 /// /// /// /// public bool WriteVariableValue(string moduleName,string variableName,object value) { if(_moduleCoeInterfaceDic.ContainsKey(moduleName)) { return _moduleCoeInterfaceDic[moduleName].WriteModuleCoeData(moduleName,variableName, value); } else { LOG.WriteLog(eEvent.ERR_TWINCAT, moduleName, $"Twincat Coe variables doesnot have [{moduleName}] module"); return false; } } } }