|
@@ -0,0 +1,183 @@
|
|
|
+using Aitex.Common.Util;
|
|
|
+using Aitex.Core.RT.Log;
|
|
|
+using Aitex.Core.RT.SCCore;
|
|
|
+using Aitex.Core.Util;
|
|
|
+using MECF.Framework.Common.Device.Festo;
|
|
|
+using MECF.Framework.Common.Equipment;
|
|
|
+using MECF.Framework.Common.IOCore;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Reflection;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace MECF.Framework.Common.Device.Galil
|
|
|
+{
|
|
|
+ public class GalilControllerCfgManager : Singleton<GalilControllerCfgManager>
|
|
|
+ {
|
|
|
+ #region 常量
|
|
|
+ private const string STOPCODE = "StopCode";
|
|
|
+ private const string REFERENCE_POSITION = "ReferencePosition";
|
|
|
+ private const string TORQUE = "Torque";
|
|
|
+ private const string VELOCITY = "Velocity";
|
|
|
+ private const string POSITION_ERROR = "PositionError";
|
|
|
+ private const string AUXILIARY_POSITION="AuxiliaryPosition";
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 内部变量
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Dictionary<string, GalilControllerData> _moduleGalilDataDictionary = new Dictionary<string, GalilControllerData>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Dictionary<string, GalilAxisData> _moduleNameAxisDataDictionary = new Dictionary<string, GalilAxisData>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Dictionary<string, int> _moduleNameIndexDictionary = new Dictionary<string, int>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Dictionary<string,List<string>> _moduleNameLstDictionary= new Dictionary<string,List<string>>();
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void Initialize()
|
|
|
+ {
|
|
|
+ bool isSimulate = SC.GetValue<bool>("System.IsSimulatorMode");
|
|
|
+ string xmlPath = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (isSimulate)
|
|
|
+ {
|
|
|
+ xmlPath = PathManager.GetCfgDir() + "Devices\\GalilControllerCfg-Simulator.xml";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ xmlPath = PathManager.GetCfgDir() + "Devices\\GalilControllerCfg.xml";
|
|
|
+ }
|
|
|
+ GalilControllerCfg cfg = CustomXmlSerializer.Deserialize<GalilControllerCfg>(new FileInfo(xmlPath));
|
|
|
+ if (cfg != null)
|
|
|
+ {
|
|
|
+ foreach (var config in cfg.GalilDeviceConfigs)
|
|
|
+ {
|
|
|
+ InitializeGalilDevice(config);
|
|
|
+ GalilTcpDevice galilDevice = new GalilTcpDevice(config.Module, config.IpAddress, config.Port);
|
|
|
+ galilDevice.ReceiveTimeout = config.RecvTimeout;
|
|
|
+ galilDevice.SendTimeout = config.SendTimeout;
|
|
|
+ galilDevice.Initialize();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ LOG.WriteLog(eEvent.ERR_GALIL, "Galil", "Load galil xml failed");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void InitializeGalilDevice(GalilDeviceConfig deviceConfig)
|
|
|
+ {
|
|
|
+ List<string> lst = new List<string>();
|
|
|
+ foreach(var item in deviceConfig.GalilAxises)
|
|
|
+ {
|
|
|
+ _moduleNameIndexDictionary[$"{deviceConfig.Module}.{item.Name}"] = item.Index;
|
|
|
+ if (!lst.Contains(item.Name))
|
|
|
+ {
|
|
|
+ lst.Add(item.Name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lst.Count > 0)
|
|
|
+ {
|
|
|
+ _moduleNameLstDictionary[deviceConfig.Module] = lst;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void UpdateModuleData(string module,GalilControllerData controllerData)
|
|
|
+ {
|
|
|
+ if (!_moduleGalilDataDictionary.ContainsKey(module))
|
|
|
+ {
|
|
|
+ _moduleGalilDataDictionary[module] = controllerData;
|
|
|
+ }
|
|
|
+ if (!_moduleNameLstDictionary.ContainsKey(module))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<string> lst = _moduleNameLstDictionary[module];
|
|
|
+ foreach (var item in lst)
|
|
|
+ {
|
|
|
+ string moduleName = $"{module}.{item}";
|
|
|
+ if (!_moduleNameIndexDictionary.ContainsKey(moduleName))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int index = _moduleNameIndexDictionary[moduleName];
|
|
|
+ if(index>=controllerData.GalilAxisDatas.Count)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ GalilAxisData galilAxisData=controllerData.GalilAxisDatas[index];
|
|
|
+ CheckAxisDataChanged(moduleName, galilAxisData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void CheckAxisDataChanged(string moduleName,GalilAxisData axisData)
|
|
|
+ {
|
|
|
+ if (_moduleNameAxisDataDictionary.ContainsKey(moduleName))
|
|
|
+ {
|
|
|
+ NotifyGalilAxisData(moduleName, _moduleNameAxisDataDictionary[moduleName],axisData);
|
|
|
+ _moduleNameAxisDataDictionary[moduleName].Copy(axisData);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ NotifyGalilAxisAllData(moduleName, axisData);
|
|
|
+ _moduleNameAxisDataDictionary[moduleName] = axisData.Clone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void NotifyGalilAxisAllData(string moduleName,GalilAxisData axisData)
|
|
|
+ {
|
|
|
+ PropertyInfo[] propertyInfos= axisData.GetType().GetProperties();
|
|
|
+ foreach(var info in propertyInfos)
|
|
|
+ {
|
|
|
+ object value = info.GetValue(axisData);
|
|
|
+ IOModuleManager.Instance.UpdateIoValue($"{moduleName}.{info.Name}", value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void NotifyGalilAxisData(string moduleName,GalilAxisData sourceData, GalilAxisData targetData)
|
|
|
+ {
|
|
|
+ PropertyInfo[] propertyInfos = sourceData.GetType().GetProperties();
|
|
|
+ foreach (var info in propertyInfos)
|
|
|
+ {
|
|
|
+ object sourceValue= info.GetValue(sourceData);
|
|
|
+ object targetValue = info.GetValue(targetData);
|
|
|
+ if (sourceValue.ToString() != targetValue.ToString())
|
|
|
+ {
|
|
|
+ IOModuleManager.Instance.UpdateIoValue(moduleName, targetValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|