123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using Aitex.Common.Util;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Device.ResistivityProbe;
- using MECF.Framework.Common.Device.TemperatureController;
- using MECF.Framework.Common.Persistent.Dryer;
- using MECF.Framework.Common.Persistent.SRD;
- using MECF.Framework.Common.ToolLayout;
- using MECF.Framework.Common.Utilities;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MECF.Framework.Common.Persistent.Temperature
- {
- public class TCPersistentManager : Singleton<TCPersistentManager>
- {
- #region 内部变量
- private Dictionary<string, TCPersistentValue> _persistentValueDic = new Dictionary<string, TCPersistentValue>();
- private Dictionary<string, string> _persistentValuePathDic = new Dictionary<string, string>();
- #endregion
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- List<string> installedModules = TemperatureItemManager.Instance.InstalledModules;
- try
- {
- string xmlPath = PathManager.GetCfgDir() + "Devices\\SMCCfg.xml";
- TemperatureConfig cfg = CustomXmlSerializer.Deserialize<TemperatureConfig>(new FileInfo(xmlPath));
- if (cfg != null)
- {
- foreach (TemperatureDeviceConfig config in cfg.TemperatureDeviceConfigs)
- {
- if (installedModules!=null&&installedModules.Contains(config.Name))
- {
- foreach (TemperatureDevice item in config.TemperatureDevices)
- {
- string module = item.Name;
- string foldStr = PathManager.GetCfgDir() + $"Persistent\\TC";
- if (!Directory.Exists(foldStr))
- {
- Directory.CreateDirectory(foldStr);
- }
- string str = $"{foldStr}\\{module}Persistent.xml";
- _persistentValuePathDic[module] = str;
- if (File.Exists(str))
- {
- TCPersistentValue tcPersistentValue = CustomXmlSerializer.Deserialize<TCPersistentValue>(new FileInfo(str));
- if (tcPersistentValue != null)
- {
- _persistentValueDic[module] = tcPersistentValue;
- }
- }
- else
- {
- TCPersistentValue persistentValue = new TCPersistentValue();
- persistentValue.Name = module;
- persistentValue.SetPoint = 10;
- persistentValue.SetPointLowLimit = 0;
- persistentValue.SetPointHighLimit = 50;
- _persistentValueDic[module] = persistentValue;
- UpdateModulePersistentValue(module);
- }
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", "Load TCPersistent xml exception");
- }
- }
- /// <summary>
- /// 更新数值
- /// </summary>
- /// <param name="module"></param>
- public void UpdateModulePersistentValue(string module)
- {
- if (_persistentValueDic.ContainsKey(module))
- {
- try
- {
- CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]);
- }
- catch (Exception ex)
- {
- LOG.WriteLog(eEvent.ERR_TEMPERATURE, module, "Save TC Persistent xml file excepetion");
- }
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_TEMPERATURE, module, "Update TC Persistent xml file excepetion");
- }
- }
- /// <summary>
- /// 获取TCPersistent数值
- /// </summary>
- /// <returns></returns>
- public TCPersistentValue GetTCPersistentValue(string module)
- {
- TCPersistentValue value = new TCPersistentValue();
- if (_persistentValueDic.ContainsKey(module) == false)
- {
- LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", $"{module} persistentValue is not exist");
- }
- else
- {
- value = _persistentValueDic[module];
- }
- return value;
- }
- /// <summary>
- /// 更新设置值和高\低limit值
- /// </summary>
- /// <returns></returns>
- public void UpdateTemperatureValue(string module, double setPoint, double setPointLowLimit,double setPointHighLimit)
- {
- _persistentValueDic[module].SetPoint = setPoint;
- _persistentValueDic[module].SetPointLowLimit = setPointLowLimit;
- _persistentValueDic[module].SetPointHighLimit = setPointHighLimit;
- try
- {
- CustomXmlSerializer.Serialize(_persistentValueDic[module], _persistentValuePathDic[module]);
- }
- catch (Exception ex)
- {
- LOG.WriteLog(eEvent.ERR_TEMPERATURE, "System", "Update TCPersistent xml file excepetion");
- }
- }
- }
- }
|