IoHeater.cs 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Common.DeviceData;
  3. using Aitex.Core.RT.DataCenter;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.ParameterCenter;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.RT.Tolerance;
  11. using Aitex.Core.Util;
  12. using MECF.Framework.Common.CommonData;
  13. using MECF.Framework.Common.Device.Bases;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.Event;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.IO;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Xml;
  24. namespace FurnaceRT.Devices
  25. {
  26. public class IoHeater : HeaterBase
  27. {
  28. public IoHeater(string module, XmlElement node, string ioModule = "")
  29. {
  30. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  31. base.Name = node.GetAttribute("id");
  32. base.Display = node.GetAttribute("display");
  33. base.DeviceID = node.GetAttribute("schematicId");
  34. formatString = node.GetAttribute("formatString");
  35. InstallZone = node.GetAttribute("installzone");
  36. _uniqueName = $"{Module}{Name}";
  37. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  38. _aiCascadePV = ParseAiNode("aiCascadePV", node, ioModule);
  39. _aiHeaterPV = ParseAiNode("aiHeaterPV", node, ioModule);
  40. _aiWorkingOutput = ParseAiNode("aiWorkingOutput", node, ioModule);
  41. _aiOverTemp = ParseAiNode("aiOverTemp", node, ioModule);
  42. _aoCascadeControlModeSetPoint = ParseAoNode("aoCascadeControlModeSetPoint", node, ioModule);
  43. _aoHeaterControlModeSetPoint = ParseAoNode("aoHeaterControlModeSetPoint", node, ioModule);
  44. _aoCascadePID_P = ParseAoNode("aoCascadePID_P", node, ioModule);
  45. _aoCascadePID_I = ParseAoNode("aoCascadePID_I", node, ioModule);
  46. _aoCascadePID_D = ParseAoNode("aoCascadePID_D", node, ioModule);
  47. _aoHeaterPID_P = ParseAoNode("aoHeaterPID_P", node, ioModule);
  48. _aoHeaterPID_I = ParseAoNode("aoHeaterPID_I", node, ioModule);
  49. _aoHeaterPID_D = ParseAoNode("aoHeaterPID_D", node, ioModule);
  50. _aoUpRate = ParseAoNode("aoUpRate", node, ioModule);
  51. _aoDownRate = ParseAoNode("aoDownRate", node, ioModule);
  52. _diCascadePVSBrk = ParseDiNode("diCascadePVSBrk", node, ioModule);
  53. _diHeaterPVSBrk = ParseDiNode("diHeaterPVSBrk", node, ioModule);
  54. _diEnableOutput = ParseDiNode("diEnableOutput", node, ioModule);
  55. _doEnableIn = ParseDoNode("doEnableIn", node, ioModule);
  56. _doAutoManual = ParseDoNode("doAutoManual", node, ioModule);
  57. _doSelect = ParseDoNode("doMainPVSelect", node, ioModule);
  58. _doCascadeMode = ParseDoNode("doCascadeMode", node, ioModule);
  59. _scRoot = node.GetAttribute("scRoot");
  60. }
  61. #region fields
  62. private AIAccessor _aiCascadePV;
  63. private AIAccessor _aiHeaterPV;
  64. private AIAccessor _aiWorkingOutput;
  65. private AIAccessor _aiOverTemp;
  66. private AOAccessor _aoCascadeControlModeSetPoint;
  67. private AOAccessor _aoHeaterControlModeSetPoint;
  68. private AOAccessor _aoCascadePID_P;
  69. private AOAccessor _aoCascadePID_I;
  70. private AOAccessor _aoCascadePID_D;
  71. private AOAccessor _aoHeaterPID_P;
  72. private AOAccessor _aoHeaterPID_I;
  73. private AOAccessor _aoHeaterPID_D;
  74. private AOAccessor _aoUpRate;
  75. private AOAccessor _aoDownRate;
  76. private DIAccessor _diCascadePVSBrk;
  77. private DIAccessor _diHeaterPVSBrk;
  78. private DIAccessor _diEnableOutput;
  79. private DOAccessor _doEnableIn;
  80. private DOAccessor _doAutoManual;
  81. private DOAccessor _doSelect;
  82. private DOAccessor _doCascadeMode;
  83. private string formatString;
  84. private const int physicalMax = 16000;
  85. private ToleranceChecker _toleranceCheckerWarning = new ToleranceChecker();
  86. private ToleranceChecker _toleranceCheckerAlarm = new ToleranceChecker();
  87. //tolerance check
  88. private float _alarmJudgmentRange;
  89. private float _warningJudgmentRange;
  90. private float _alarmJudgmentTime;
  91. private float _warningJudgmentTime;
  92. private float _toleranceJudgmentDelayTime;
  93. private DeviceTimer _toleranceJudgmentDelayTimer = new DeviceTimer();
  94. //stable check
  95. private Stopwatch _stableJudgmentTimer = new Stopwatch();
  96. private float _stableJudgmentTime = 1;
  97. private float _stableMinValue;
  98. private float _stableMaxValue;
  99. private SCConfigItem _scEnableCalibration;
  100. private SCConfigItem _scCalibrationTable;
  101. private SCConfigItem _scRange;
  102. private SCConfigItem _scRampRate;//°C/min
  103. private List<CalibrationItem> _calibrationTable = new List<CalibrationItem>();
  104. private string _previousSetting;
  105. private DeviceTimer _rampTimer = new DeviceTimer();
  106. private double _rampTarget;
  107. private double _rampInitValue;
  108. private int _rampTime;
  109. private DeviceTimer _stableTimer = new DeviceTimer();
  110. private bool _isWarned;
  111. private string _uniqueName;
  112. private float _tempSetpoint = 0.0f;
  113. private string _scRoot;
  114. private bool _isStartRamp = false;
  115. private bool _isFloatAioType = false;
  116. private Dictionary<string, int> _pidTableAssociate;
  117. #region temp correct
  118. private float _profileTemp = 0;
  119. private float _profileCorrect = 0;
  120. private float _profileTCCalib = 0;
  121. private float _cascadeTCCorrect = 0;
  122. public string CurrentCorrectFileName { get; private set; }
  123. public int CurrentCorrectIndex { get; private set; }
  124. private string _writeLog = "";
  125. #endregion
  126. #region temp profile
  127. private float _preheatTime = 0;
  128. private float _checkTime = 0;
  129. private float _checkLimit = 0;
  130. private float _alarmLimit = 0;
  131. private float _totalTime = 0;
  132. private Stopwatch _profileTimer = new Stopwatch();
  133. private Stopwatch _profileStableTimer = new Stopwatch();
  134. public bool IsProfileMode => _profileTimer != null && _profileTimer.IsRunning;
  135. public bool IsProfileSuccess { get; set; }
  136. private R_TRIG _profileTotalTimeoutTrig = new R_TRIG();
  137. private R_TRIG _profileAlarmLimitTrig = new R_TRIG();
  138. private R_TRIG _profileSuccessTrig = new R_TRIG();
  139. private bool _isWait;
  140. private float _waitHigh;
  141. private float _waitLow;
  142. private bool _isInit = false;
  143. private Stopwatch _initTimer = new Stopwatch();
  144. #endregion
  145. #endregion
  146. #region properties
  147. public string InstallZone { get; set; }
  148. public double Range => _scRange.DoubleValue;
  149. public AlarmEventItem AlarmToleranceWarning { get; set; }
  150. public AlarmEventItem AlarmToleranceAlarm { get; set; }
  151. public AlarmEventItem InterlockAlarm { get; set; }
  152. public AlarmEventItem HeaterErrorAlarm { get; set; }
  153. public AlarmEventItem HeaterErrorRecoveryWarning { get; set; }
  154. public AlarmEventItem HeaterStripBreakAlarm { get; set; }
  155. public AlarmEventItem HeaterStripBreakWarning { get; set; }
  156. public bool IsHeaterStripBreak { get; set; }
  157. private RD_TRIG _trigHeaterErrorSignalOn = new RD_TRIG();
  158. public R_TRIG TrigHeaterStripBreakSignalOn = new R_TRIG();
  159. public DeviceTimer HeaterStripBreakTimer = new DeviceTimer();
  160. public string InstallPosition => SC.GetStringValue($"{_scRoot}.Heater.{InstallZone}.{Name}.InstallPosition");
  161. public bool IsError => _diCascadePVSBrk == null || _diHeaterPVSBrk == null ? false : _diCascadePVSBrk.Value || _diHeaterPVSBrk.Value;
  162. public bool IsStable
  163. {
  164. get
  165. {
  166. if (_stableJudgmentTimer.IsRunning)
  167. {
  168. if (DeviceData.FeedBack < (DeviceData.SetPoint - _stableMinValue) ||
  169. DeviceData.FeedBack > (DeviceData.SetPoint + _stableMaxValue))
  170. {
  171. _stableJudgmentTimer.Restart();
  172. }
  173. if (_stableJudgmentTimer.ElapsedMilliseconds >= _stableJudgmentTime * 1000)
  174. {
  175. return true;
  176. }
  177. }
  178. else
  179. {
  180. _stableJudgmentTimer.Restart();
  181. }
  182. return false;
  183. }
  184. }
  185. public override float TempSetPoint
  186. {
  187. get
  188. {
  189. return _tempSetpoint;
  190. }
  191. set
  192. {
  193. if (_aoCascadeControlModeSetPoint != null && _aoHeaterControlModeSetPoint != null)
  194. {
  195. if (_isFloatAioType)
  196. {
  197. if(ControlMode == 0)
  198. {
  199. if (Math.Abs(_aoCascadeControlModeSetPoint.FloatValue - value) > 0.0001)
  200. _aoCascadeControlModeSetPoint.FloatValue = value;
  201. }
  202. else
  203. {
  204. if (Math.Abs(_aoHeaterControlModeSetPoint.FloatValue - value) > 0.0001)
  205. _aoHeaterControlModeSetPoint.FloatValue = value;
  206. }
  207. }
  208. }
  209. }
  210. }
  211. public float HeaterPID_P
  212. {
  213. get
  214. {
  215. return _aoHeaterPID_P.FloatValue;
  216. }
  217. set
  218. {
  219. if (Math.Abs(_aoHeaterPID_P.FloatValue - value) > 0.0001)
  220. _aoHeaterPID_P.FloatValue = value;
  221. }
  222. }
  223. public float HeaterPID_I
  224. {
  225. get
  226. {
  227. return _aoHeaterPID_I.FloatValue;
  228. }
  229. set
  230. {
  231. if (Math.Abs(_aoHeaterPID_I.FloatValue - value) > 0.0001)
  232. _aoHeaterPID_I.FloatValue = value;
  233. }
  234. }
  235. public float HeaterPID_D
  236. {
  237. get
  238. {
  239. return _aoHeaterPID_D.FloatValue;
  240. }
  241. set
  242. {
  243. if (Math.Abs(_aoHeaterPID_D.FloatValue - value) > 0.0001)
  244. _aoHeaterPID_D.FloatValue = value;
  245. }
  246. }
  247. public float CascadePID_P
  248. {
  249. get
  250. {
  251. return _aoCascadePID_P.FloatValue;
  252. }
  253. set
  254. {
  255. if (Math.Abs(_aoCascadePID_P.FloatValue - value) > 0.0001)
  256. _aoCascadePID_P.FloatValue = value;
  257. }
  258. }
  259. public float CascadePID_I
  260. {
  261. get
  262. {
  263. return _aoCascadePID_I.FloatValue;
  264. }
  265. set
  266. {
  267. if (Math.Abs(_aoCascadePID_I.FloatValue - value) > 0.0001)
  268. _aoCascadePID_I.FloatValue = value;
  269. }
  270. }
  271. public float CascadePID_D
  272. {
  273. get
  274. {
  275. return _aoCascadePID_D.FloatValue;
  276. }
  277. set
  278. {
  279. if (Math.Abs(_aoCascadePID_D.FloatValue - value) > 0.0001)
  280. _aoCascadePID_D.FloatValue = value;
  281. }
  282. }
  283. public float UpRate
  284. {
  285. get
  286. {
  287. return _aoUpRate.FloatValue;
  288. }
  289. set
  290. {
  291. if (Math.Abs(_aoUpRate.FloatValue - value) > 0.0001)
  292. _aoUpRate.FloatValue = value;
  293. }
  294. }
  295. public float DownRate
  296. {
  297. get
  298. {
  299. return _aoDownRate.FloatValue;
  300. }
  301. set
  302. {
  303. if (Math.Abs(_aoDownRate.FloatValue - value) > 0.0001)
  304. _aoDownRate.FloatValue = value;
  305. }
  306. }
  307. public int ControlMode
  308. {
  309. get
  310. {
  311. if (_doSelect != null && _doCascadeMode != null)
  312. {
  313. if (!_doSelect.Value && !_doCascadeMode.Value)
  314. {
  315. // Furnace control
  316. return 0;
  317. }
  318. else if (!_doSelect.Value && _doCascadeMode.Value)
  319. {
  320. // Heater control
  321. return 1;
  322. }
  323. else if (_doSelect.Value && _doCascadeMode.Value)
  324. {
  325. //Furnace Diect control
  326. return 2;
  327. }
  328. }
  329. return 0;
  330. }
  331. }
  332. public override float TempFeedback => (float)(ControlMode == 1 ? (_aiHeaterPV == null ? 0 : _aiHeaterPV.FloatValue - _profileTCCalib) : (_aiCascadePV == null ? 0 : _aiCascadePV.FloatValue - _profileTCCalib));
  333. #endregion
  334. public override bool Initialize()
  335. {
  336. DeviceData = new AITHeaterData()
  337. {
  338. DeviceName = Name,
  339. DeviceSchematicId = DeviceID,
  340. DisplayName = Display,
  341. Module = Module,
  342. //Scale = SC.GetValue<double>($"{_scRoot}.{Name}.Range"),
  343. Scale = 1200,
  344. Unit = "°C",
  345. //SetPoint = TempSetPoint,
  346. FeedBack = TempFeedback,
  347. };
  348. _pidTableAssociate = new Dictionary<string, int>()
  349. {
  350. { "HeaterU",0 },
  351. { "HeaterCU",1 },
  352. { "HeaterC",2 },
  353. { "HeaterCL",3 },
  354. { "HeaterL",4 },
  355. };
  356. _scEnableCalibration = SC.GetConfigItem($"{_scRoot}.{Name}.EnableCalibration");
  357. _scCalibrationTable = SC.GetConfigItem($"{_scRoot}.{Name}.CalibrationTable");
  358. //_scRange = SC.GetConfigItem($"{_scRoot}.{Name}.Range");
  359. _scRampRate = SC.GetConfigItem($"{_scRoot}.{Name}.RampRate");
  360. //AlarmToleranceWarning = SubscribeAlarm($"{_scRoot}.{Name}.ToleranceWarning", "", ResetWarningChecker, EventLevel.Warning);
  361. //AlarmToleranceAlarm = SubscribeAlarm($"{_scRoot}.{Name}.ToleranceAlarm", "", ResetAlarmChecker);
  362. //AlarmToleranceWarning.Id = SC.ContainsItem($"{_scRoot}.{Name}.ToleranceWarningID") ? SC.GetValue<int>($"{_scRoot}.{Name}.ToleranceWarningID") : 0;
  363. //AlarmToleranceAlarm.Id = SC.ContainsItem($"{_scRoot}.{Name}.ToleranceAlarmID") ? SC.GetValue<int>($"{_scRoot}.{Name}.ToleranceAlarmID") : 0;
  364. //_stableJudgmentTime = (float)SC.GetValue<double>($"{_scRoot}.{Name}.Stabilize.JudgmentTime");
  365. //_stableMinValue = (float)SC.GetValue<double>($"{_scRoot}.{Name}.Stabilize.MinusValue");
  366. //_stableMaxValue = (float)SC.GetValue<double>($"{_scRoot}.{Name}.Stabilize.PlusValue");
  367. DATA.Subscribe($"{Module}.{Name}.CascadePV", () => (float)DeviceData.CascadePV);
  368. DATA.Subscribe($"{Module}.{Name}.HeaterPV", () => (float)DeviceData.HeaterPV);
  369. DATA.Subscribe($"{Module}.{Name}.CascadePID_P", () => (float)DeviceData.CascadePID_P);
  370. DATA.Subscribe($"{Module}.{Name}.CascadePID_I", () => (float)DeviceData.CascadePID_I);
  371. DATA.Subscribe($"{Module}.{Name}.CascadePID_D", () => (float)DeviceData.CascadePID_D);
  372. DATA.Subscribe($"{Module}.{Name}.HeaterPID_P", () => (float)DeviceData.HeaterPID_P);
  373. DATA.Subscribe($"{Module}.{Name}.HeaterPID_I", () => (float)DeviceData.HeaterPID_I);
  374. DATA.Subscribe($"{Module}.{Name}.HeaterPID_D", () => (float)DeviceData.HeaterPID_D);
  375. DATA.Subscribe($"{Module}.{Name}.CascadeControlModeSV", () => _aoCascadeControlModeSetPoint != null ? _aoCascadeControlModeSetPoint.FloatValue : 0.0f);
  376. DATA.Subscribe($"{Module}.{Name}.HeaterControlModeSV", () => _aoHeaterControlModeSetPoint != null ? _aoHeaterControlModeSetPoint.FloatValue : 0.0f);
  377. DATA.Subscribe($"{Module}.{Name}.UpRate", () => UpRate);
  378. DATA.Subscribe($"{Module}.{Name}.DownRate", () => DownRate);
  379. DATA.Subscribe($"{Module}.{Name}.WorkingOutput", () => _aiWorkingOutput.FloatValue);
  380. DATA.Subscribe($"{Module}.{Name}.OverTemp", () => _aiOverTemp.FloatValue);
  381. DATA.Subscribe($"{Module}.{Name}.IsCascadePVBreak", () => _diCascadePVSBrk.Value);
  382. DATA.Subscribe($"{Module}.{Name}.IsHeaterPVBreak", () => _diHeaterPVSBrk.Value);
  383. DATA.Subscribe($"{Module}.{Name}.IsEnableOutput", () => _diEnableOutput.Value);
  384. DATA.Subscribe($"{Module}.{Name}.IsEnableIn", () => _doEnableIn.Value);
  385. DATA.Subscribe($"{Module}.{Name}.IsAutoManual", () => _doAutoManual.Value);
  386. DATA.Subscribe($"{Module}.{Name}.IsSelect", () => _doSelect.Value);
  387. DATA.Subscribe($"{Module}.{Name}.IsCascadeMode", () => _doCascadeMode.Value);
  388. DATA.Subscribe($"{Module}.{Name}.ControlMode", () => ControlMode);
  389. OP.Subscribe($"{Module}.{Name}.SetRemoteMode", SetRemoteMode);
  390. OP.Subscribe($"{Module}.{Name}.SetAutoTuning", SetAutoTuning);
  391. OP.Subscribe($"{Module}.{Name}.SetOnOff", SetOnOff);
  392. OP.Subscribe($"{Module}.{Name}.SetUpDownRate", (out string reason, int time, object[] param) =>
  393. {
  394. reason = string.Empty;
  395. SetUpDownRate(param);
  396. return true;
  397. });
  398. OP.Subscribe($"{Module}.{Name}.SetManualParameters", (out string reason, int time, object[] param) =>
  399. {
  400. reason = string.Empty;
  401. SetManualParameters(param);
  402. return true;
  403. });
  404. //recipe
  405. OP.Subscribe($"PM1.{Name}.SetParameters", (out string reason, int time, object[] param) =>
  406. {
  407. reason = string.Empty;
  408. SetParameters(param);
  409. return true;
  410. });
  411. _doEnableIn?.SetValue(true, out _);
  412. SetCorrectParameters(SC.GetStringValue("PM1.TempCorrection"));
  413. return base.Initialize();
  414. }
  415. public override void Monitor()
  416. {
  417. if(!string.IsNullOrEmpty(_writeLog))
  418. {
  419. LOG.Write(_writeLog);
  420. _writeLog = "";
  421. }
  422. if (!_isInit)
  423. {
  424. if (!_initTimer.IsRunning)
  425. _initTimer.Start();
  426. if (_initTimer.ElapsedMilliseconds > 5 * 1000)
  427. {
  428. _initTimer.Stop();
  429. _isInit = true;
  430. if (_tempSetpoint == 0)
  431. {
  432. if(ControlMode == 0)
  433. {
  434. if(_aoCascadeControlModeSetPoint != null && _aoCascadeControlModeSetPoint.FloatValue > 0)
  435. {
  436. _tempSetpoint = _aoCascadeControlModeSetPoint.FloatValue;
  437. }
  438. }
  439. else
  440. {
  441. if (_aoCascadeControlModeSetPoint != null && _aoHeaterControlModeSetPoint.FloatValue > 0)
  442. {
  443. _tempSetpoint = _aoHeaterControlModeSetPoint.FloatValue;
  444. }
  445. }
  446. }
  447. SetPIDParameters(SC.GetStringValue("PM1.Heater.PID"));
  448. }
  449. }
  450. if(DeviceData != null)
  451. {
  452. DeviceData.CascadePID_P = _aoCascadePID_P == null ? 0 : _aoCascadePID_P.FloatValue;
  453. DeviceData.CascadePID_I = _aoCascadePID_I == null ? 0 : _aoCascadePID_I.FloatValue;
  454. DeviceData.CascadePID_D = _aoCascadePID_D == null ? 0 : _aoCascadePID_D.FloatValue;
  455. DeviceData.HeaterPID_P = _aoHeaterPID_P == null ? 0 : _aoHeaterPID_P.FloatValue;
  456. DeviceData.HeaterPID_I = _aoHeaterPID_I == null ? 0 : _aoHeaterPID_I.FloatValue;
  457. DeviceData.HeaterPID_D = _aoHeaterPID_D == null ? 0 : _aoHeaterPID_D.FloatValue;
  458. DeviceData.OverTemp = _aiOverTemp == null ? 0 : _aiOverTemp.FloatValue;
  459. DeviceData.CascadePV = _aiCascadePV == null ? 0 : _aiCascadePV.FloatValue;
  460. DeviceData.HeaterPV = _aiHeaterPV == null ? 0 : _aiHeaterPV.FloatValue;
  461. DeviceData.FeedBack = TempFeedback;
  462. DeviceData.SetPoint = _tempSetpoint;
  463. DeviceData.ManipulatedVariable = _aiWorkingOutput == null ? 0 : _aiWorkingOutput.FloatValue;
  464. DeviceData.RampSetPoint = TempSetPoint;//Ramp的过程值
  465. DeviceData.Ramping = _aoUpRate == null ? 0 : _aoUpRate.FloatValue;
  466. DeviceData.ControlMode = ControlMode;// 控制模式
  467. DeviceData.IsAlarm = IsError;
  468. DeviceData.UpRateSetPoint = UpRate;
  469. DeviceData.DownRateSetPoint = DownRate;
  470. DeviceData.EnableOutput = _diEnableOutput.Value;
  471. DeviceData.IsCascadePVBreak = _diCascadePVSBrk.Value;
  472. DeviceData.IsHeaterPVBreak = _diHeaterPVSBrk.Value;
  473. DeviceData.IsProfiling = IsProfileMode;
  474. if(_profileTimer != null && _profileTimer.IsRunning)
  475. {
  476. DeviceData.ProfileTotalTime = _totalTime - _profileTimer.ElapsedMilliseconds / 1000 > 0 ? _totalTime - _profileTimer.ElapsedMilliseconds / 1000 : 0;
  477. DeviceData.ProfilePreheatTime = _preheatTime - _profileTimer.ElapsedMilliseconds / 1000 > 0 ? _preheatTime - _profileTimer.ElapsedMilliseconds / 1000 : 0;
  478. }
  479. if(_profileStableTimer != null && _profileStableTimer.IsRunning)
  480. {
  481. DeviceData.ProfileCheckTime = _checkTime - _profileStableTimer.ElapsedMilliseconds / 1000 > 0 ? _checkTime - _profileStableTimer.ElapsedMilliseconds / 1000 : 0;
  482. }
  483. }
  484. MonitorTolerance();
  485. Ramping();
  486. base.Monitor();
  487. }
  488. public override void SetTemperature(float temperature)
  489. {
  490. //if (temperature != SetpointFeedback)
  491. {
  492. var _rampTime = _scRampRate.DoubleValue != 0 ? (Math.Abs(temperature - TempFeedback) / _scRampRate.DoubleValue) * 60 * 1000 : 0;
  493. Ramp(temperature, (int)_rampTime);
  494. }
  495. }
  496. public void SetRamping(float ramping)
  497. {
  498. SaveRampRate(ramping.ToString("F1"));
  499. }
  500. private void SetManualParameters(object[] param)
  501. {
  502. //value:ramp
  503. if (param == null || param.Length < 1)
  504. {
  505. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature set parameter");
  506. return;
  507. }
  508. var array = param[0].ToString().Split(';');
  509. if (array == null || array.Length < 2)
  510. {
  511. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature set parameter");
  512. return;
  513. }
  514. float.TryParse(array[0], out float temperature);
  515. float.TryParse(array[1], out float rampTime);//°C/min
  516. DeviceData.SetPoint = temperature;
  517. DeviceData.RampSetPoint = rampTime;
  518. var profileCorrect = 0.0f;
  519. var profileTCCalib = 0.0f;
  520. //var actualSet = temperature - profileCorrect < 0 ? 0 : temperature - profileCorrect;
  521. var actualSet = temperature + _profileTCCalib;//加上flat zone的值
  522. UpRate = rampTime;
  523. DownRate = rampTime;
  524. var controlMode = "";
  525. if (array.Length > 2)
  526. {
  527. controlMode = array.Length > 2 ? array[2].ToString() : "";
  528. SetControlMode(controlMode);
  529. }
  530. _tempSetpoint = temperature;
  531. TempSetPoint = actualSet;
  532. LOG.Write($"{Name} setpoint={temperature} control mode={controlMode}");
  533. //Ramp(actualSet, (int)rampTime);
  534. }
  535. public void SetControlMode(string mode, string recipeProfileFileName = "")
  536. {
  537. var reason = "";
  538. DeviceData.ControlModeSetpoint = mode;
  539. switch(mode.ToLower())
  540. {
  541. case "heater":
  542. case "heater control":
  543. if(_doSelect.Value)
  544. _doSelect.SetValue(false, out reason);
  545. if (!_doCascadeMode.Value)
  546. _doCascadeMode.SetValue(true, out reason);
  547. break;
  548. case "furnace":
  549. case "furnace control":
  550. if (_doSelect.Value)
  551. _doSelect.SetValue(false, out reason);
  552. if (_doCascadeMode.Value)
  553. _doCascadeMode.SetValue(false, out reason);
  554. break;
  555. case "furnace direct":
  556. case "furnace direct control":
  557. if (!_doSelect.Value)
  558. _doSelect.SetValue(true, out reason);
  559. if (!_doCascadeMode.Value)
  560. _doCascadeMode.SetValue(true, out reason);
  561. break;
  562. default:
  563. if(mode.ToLower().StartsWith("profile"))
  564. {
  565. var arry = mode.Replace(")","").Split('(');
  566. if(arry != null && arry.Length > 1)
  567. {
  568. var profileArray = arry[1].Split(',');
  569. if(profileArray != null && profileArray.Length > 2)
  570. {
  571. var profileFileName = profileArray[0];
  572. int.TryParse(profileArray[1], out int profileTableIndex);
  573. GetProfileParameters(profileFileName, profileTableIndex, recipeProfileFileName);
  574. _profileTimer.Restart();
  575. _profileStableTimer.Stop();
  576. _profileTotalTimeoutTrig.RST = true;
  577. _profileAlarmLimitTrig.RST = true;
  578. _profileSuccessTrig.RST = true;
  579. IsProfileSuccess = false;
  580. DeviceData.ProfileResult = 0;
  581. LOG.Write($"{Name} profile start preheatTime={_preheatTime} checkTime={_checkTime} totalTime={_totalTime} checkLimit={_checkLimit} alarmLimit={_alarmLimit}");
  582. }
  583. }
  584. }
  585. break;
  586. }
  587. }
  588. private void SetUpDownRate(object[] param)
  589. {
  590. }
  591. public void SetParameters(object[] param)
  592. {
  593. if (param != null && param.Length > 0)
  594. {
  595. string zoneName = "";
  596. float temperature = 0.0f;
  597. string tempUnit = "";
  598. float ramp = 0.0f;
  599. string rampUnit = "";
  600. string controlMode = "";
  601. string correct = "";
  602. string PID = "";
  603. var array = param[0].ToString().Split(';');//zoneName;temp;tempUnit;ramp;rampUnit;checkWait;tempHigh;tempLow;unitStepCompletionCondition;controlMode;correct;PID
  604. if (System.Text.RegularExpressions.Regex.Match(array[1].ToString(), @"[a-zA-Z]").Success)
  605. {
  606. var table = array[1].ToString().Split(':');//AssociateParameterTable
  607. if (SC.ContainsItem($"PM1.RecipeEditParameter.TempSetting.{table[0]}.{Name}"))
  608. {
  609. temperature = (float)SC.GetValue<double>($"PM1.RecipeEditParameter.TempSetting.{table[0]}.{Name}");
  610. }
  611. }
  612. else
  613. {
  614. float.TryParse(array[1].ToString(), out temperature);
  615. }
  616. tempUnit = array.Length > 2 ? array[2].ToString() : "";
  617. if (array.Length > 3)
  618. {
  619. float.TryParse(array[3], out ramp);
  620. }
  621. rampUnit = array.Length > 4 ? array[4].ToString() : "";
  622. if (array.Length > 5)
  623. {
  624. bool.TryParse(array[5], out _isWait);
  625. }
  626. if (array.Length > 6)
  627. {
  628. float.TryParse(array[6], out _waitHigh);
  629. }
  630. if (array.Length > 7)
  631. {
  632. float.TryParse(array[7], out _waitLow);
  633. }
  634. var unitStepCompletionCondition = array.Length > 8 ? array[8].ToString() : "";
  635. _stableJudgmentTimer.Stop();
  636. controlMode = array.Length > 9 ? array[9].ToString() : "";
  637. correct = array.Length > 10 ? array[10].ToString() : "";
  638. PID = array.Length > 11 ? array[11].ToString() : "";
  639. var correctileName = array.Length > 12 ? array[12].ToString() : "";
  640. var PIDFileName = array.Length > 13 ? array[13].ToString() : "";
  641. var profileFileName = array.Length > 14 ? array[14].ToString() : "";
  642. var DPR = array.Length > 16 ? (array[15].ToString().ToLower() == "open" ? true : false) : false;
  643. var BWR = array.Length > 16 ? (array[15].ToString().ToLower() == "open" ? true : false) : false;
  644. SetControlMode(controlMode, profileFileName);
  645. SetPIDParameters(PID, PIDFileName);
  646. SetCorrectParameters(correct, correctileName, profileFileName);
  647. var profileCorrect = 0.0f;
  648. var profileTCCalib = 0.0f;
  649. //var actualSet = temperature - profileCorrect < 0 ? 0 : temperature - profileCorrect;
  650. var actualSet = temperature + _profileTCCalib;//加上flat zone的值
  651. float _rampTime = 0;
  652. if(DPR && BWR)
  653. {
  654. DownRate = 0;
  655. UpRate = 0;
  656. }
  657. else
  658. {
  659. if (ramp == 0)
  660. {
  661. DownRate = Math.Abs(TempFeedback - actualSet);//单位是°C/min
  662. UpRate = Math.Abs(TempFeedback - actualSet);//单位是°C/min
  663. }
  664. else if (rampUnit.ToLower() == "time")
  665. {
  666. DownRate = Math.Abs(TempFeedback - actualSet) / ramp;//单位是°C/min
  667. UpRate = Math.Abs(TempFeedback - actualSet) / ramp;//单位是°C/min
  668. }
  669. else
  670. {
  671. DownRate = ramp;//单位是°C/min
  672. UpRate = ramp;//单位是°C/min
  673. }
  674. }
  675. DeviceData.SetPoint = temperature;
  676. DeviceData.RampSetPoint = _rampTime;
  677. _tempSetpoint = temperature;
  678. TempSetPoint = actualSet;
  679. //LOG.Write($"{Name} setpoint={temperature} control mode={controlMode}, PID={PID}, correct={correct}");
  680. _writeLog = $"{Name} setpoint={temperature} control mode={controlMode}, PID={PID}, correct={correct}";
  681. //Ramp(actualSet, (int)_rampTime);
  682. }
  683. return;
  684. }
  685. private bool SetRemoteMode(out string reason, int time, params object[] param)
  686. {
  687. reason = string.Empty;
  688. if (param == null || param.Length == 0)
  689. {
  690. reason = $"invalid parameter";
  691. return false;
  692. }
  693. bool.TryParse(param[0].ToString(), out bool isRemoteMode);
  694. //_doRemoteControl.SetValue(isRemoteMode, out _);
  695. return true;
  696. }
  697. private bool SetOnOff(out string reason, int time, params object[] param)
  698. {
  699. reason = string.Empty;
  700. if (param == null || param.Length == 0)
  701. {
  702. reason = $"invalid parameter";
  703. return false;
  704. }
  705. bool.TryParse(param[0].ToString(), out bool isOn);
  706. //if (!_doStartHeating.Check(isOn, out reason))
  707. //{
  708. // return false;
  709. //}
  710. //return _doStartHeating.SetValue(isOn, out reason);
  711. return true;
  712. }
  713. public void SetRun(bool isOn)
  714. {
  715. //_doStartHeating.SetValue(isOn, out _);
  716. EV.PostInfoLog(Name, $"{Name}.SetRun({isOn})");
  717. }
  718. public void SetRemote(bool isRemote)
  719. {
  720. //_doRemoteControl.SetValue(isRemote, out _);
  721. }
  722. private bool SetAutoTuning(out string reason, int time, params object[] param)
  723. {
  724. reason = string.Empty;
  725. if (param == null || param.Length == 0)
  726. {
  727. reason = $"invalid parameter";
  728. return false;
  729. }
  730. bool.TryParse(param[0].ToString(), out bool isAutoSetAutoTuning);
  731. if (isAutoSetAutoTuning)
  732. {
  733. //_doCanWritePara.SetPulseValue(true, 2000);
  734. //_doStopAutoTunningMode.SetValue(false, out _);
  735. //_doStartAutoTunningMode.SetPulseValue(true, 2000);
  736. }
  737. else
  738. {
  739. //_doCanWritePara.SetPulseValue(true, 2000);
  740. //_doStartAutoTunningMode.SetValue(false, out _);
  741. //_doStopAutoTunningMode.SetPulseValue(true, 2000);
  742. }
  743. return true;
  744. }
  745. public override void Terminate()
  746. {
  747. ProfileFinish();
  748. base.Terminate();
  749. }
  750. public void ProfileFinish()
  751. {
  752. _profileTimer.Stop();
  753. _profileStableTimer.Stop();
  754. _profileTotalTimeoutTrig.RST = true;
  755. _profileAlarmLimitTrig.RST = true;
  756. _profileSuccessTrig.RST = true;
  757. IsProfileSuccess = false;
  758. DeviceData.ProfileTable = "";
  759. DeviceData.ProfileTotalTime = 0;
  760. DeviceData.ProfilePreheatTime = 0;
  761. DeviceData.ProfileCheckTime = 0;
  762. DeviceData.ProfileAlarmLimit = 0;
  763. DeviceData.ProfileCheckLimit = 0;
  764. }
  765. public bool SetEnable(bool isEnable)
  766. {
  767. return _doEnableIn.SetValue(isEnable, out _);
  768. }
  769. public bool ResetWarningChecker()
  770. {
  771. _toleranceCheckerWarning.Reset(_warningJudgmentTime);
  772. return true;
  773. }
  774. public bool ResetAlarmChecker()
  775. {
  776. _toleranceCheckerAlarm.Reset(_alarmJudgmentTime);
  777. return true;
  778. }
  779. public override void Reset()
  780. {
  781. AlarmToleranceWarning?.Reset();
  782. AlarmToleranceAlarm?.Reset();
  783. _toleranceJudgmentDelayTimer?.Stop();
  784. }
  785. public void ResetHeaterError()
  786. {
  787. _trigHeaterErrorSignalOn.RST = true;
  788. if (HeaterErrorAlarm != null)
  789. HeaterErrorAlarm.IsAcknowledged = true;
  790. }
  791. public void ResetHeaterStripBreak()
  792. {
  793. TrigHeaterStripBreakSignalOn.RST = true;
  794. if (HeaterStripBreakAlarm != null)
  795. HeaterStripBreakAlarm.IsAcknowledged = true;
  796. }
  797. private void MonitorTolerance()
  798. {
  799. if (IsHeaterStripBreak || TempSetPoint < 0.001 || _toleranceJudgmentDelayTimer.IsIdle() || _toleranceJudgmentDelayTimer.GetElapseTime() < _toleranceJudgmentDelayTime * 1000)
  800. {
  801. _toleranceCheckerWarning.RST = true;
  802. _toleranceCheckerAlarm.RST = true;
  803. return;
  804. }
  805. if (_alarmJudgmentRange != 0 && _alarmJudgmentTime > 0)
  806. {
  807. _toleranceCheckerAlarm.Monitor(DeviceData.FeedBack, DeviceData.RampSetPoint - Math.Abs(_alarmJudgmentRange), DeviceData.RampSetPoint + Math.Abs(_alarmJudgmentRange), _alarmJudgmentTime);
  808. }
  809. if (_warningJudgmentRange != 0 && _warningJudgmentTime > 0)
  810. {
  811. _toleranceCheckerWarning.Monitor(DeviceData.FeedBack, DeviceData.RampSetPoint - Math.Abs(_warningJudgmentRange), DeviceData.RampSetPoint + Math.Abs(_warningJudgmentRange), _warningJudgmentTime);
  812. }
  813. }
  814. public override bool CheckToleranceAlarm()
  815. {
  816. return _toleranceCheckerAlarm.Result;
  817. }
  818. public override bool CheckToleranceWarning()
  819. {
  820. return _toleranceCheckerWarning.Result;
  821. }
  822. public void SetToleranceAlarm()
  823. {
  824. AlarmToleranceAlarm.Description = $"{Display} temperature out of range {_alarmJudgmentRange} °C in {_alarmJudgmentTime:F0} seconds";
  825. AlarmToleranceAlarm.Set();
  826. }
  827. public void SetToleranceWarning()
  828. {
  829. AlarmToleranceWarning.Description = $"{Display} temperature out of range {_warningJudgmentRange} °C in {_warningJudgmentTime:F0} seconds";
  830. AlarmToleranceWarning.Set();
  831. }
  832. public void Ramp(double target, int time)
  833. {
  834. target = Math.Max(0, target);
  835. //target = Math.Min(Range, target);
  836. _rampInitValue = TempFeedback; //ramp 初始值取当前设定值,而非实际读取值.零漂问题
  837. _rampTime = time;
  838. _rampTarget = target;
  839. _rampTimer.Start(_rampTime);
  840. _isStartRamp = true;
  841. }
  842. private void Ramping()
  843. {
  844. //只有修改了温度,才开始ramp,避免一开机温度设定值大于0的问题。
  845. if (!_isStartRamp)
  846. return;
  847. if (_rampTimer.IsTimeout() || _rampTime == 0)
  848. {
  849. TempSetPoint = (float)_rampTarget;
  850. }
  851. else
  852. {
  853. TempSetPoint = (float)(_rampInitValue + (_rampTarget - _rampInitValue) * _rampTimer.GetElapseTime() / _rampTime);
  854. }
  855. }
  856. private void SaveRampRate(string ramping)
  857. {
  858. SC.SetItemValueFromString($"{_scRoot}.{Name}.RampRate", ramping);
  859. }
  860. public void SetCorrectParameters(string name, string recipeCorrectFileName = null, string recipeProfileFileName = null)
  861. {
  862. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  863. //var defaultPID = SC.GetStringValue("PM1.APCPID");
  864. if (string.IsNullOrEmpty(name))
  865. {
  866. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file is empty");
  867. name = SC.GetStringValue("PM1.TempCorrection");
  868. }
  869. var array = name.Split(',');
  870. if (array == null || array.Length < 2)
  871. {
  872. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature correct parameter");
  873. name = SC.GetStringValue("PM1.TempCorrection");
  874. array = name.Split(',');
  875. }
  876. if (!File.Exists($"{PathManager.GetParameterDir()}\\{array[0]}.rcp"))
  877. {
  878. name = SC.GetStringValue("PM1.TempCorrection");
  879. var temp = name.Split(',');
  880. if (temp != null && array.Length > 0)
  881. {
  882. array[0] = temp[0];
  883. name = string.Join(",", array);
  884. }
  885. }
  886. if (array == null || array.Length < 2)
  887. {
  888. return;
  889. }
  890. var fileNameAndPath = array[0];
  891. int.TryParse(array[1], out int index);
  892. var para = fileNameAndPath.Split('\\').ToList().Skip(2);//"Parameter\\TempCorrection"
  893. if (para == null)
  894. {
  895. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file is empty");
  896. return;
  897. }
  898. var fileName = string.Join("\\", para.ToArray());
  899. if (!string.IsNullOrEmpty(recipeCorrectFileName))
  900. fileName = recipeCorrectFileName;
  901. CurrentCorrectFileName = fileName;
  902. CurrentCorrectIndex = index;
  903. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\TempCorrection", fileName, false);
  904. if (string.IsNullOrEmpty(content))
  905. {
  906. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"{fileNameAndPath} heater temperature correct file is empty");
  907. return;
  908. }
  909. var doc = new XmlDocument();
  910. doc.LoadXml(content);
  911. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  912. if (nodeSteps == null)
  913. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  914. if (nodeSteps == null)
  915. {
  916. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature correct file {fileNameAndPath}");
  917. return;
  918. }
  919. Dictionary<int, CorrectTableParameter> dic = new Dictionary<int, CorrectTableParameter>();
  920. for(int i= 0;i < nodeSteps.Count;i++)
  921. {
  922. var step = nodeSteps[i];
  923. XmlElement stepNode = step as XmlElement;
  924. var correctTableParameter = new CorrectTableParameter();
  925. correctTableParameter.CorrectParameterLst = new List<CorrectParameter>();
  926. int tableIndex = i + 1;
  927. foreach (XmlAttribute att in stepNode.Attributes)
  928. {
  929. switch (att.Name.ToLower())
  930. {
  931. case "index":
  932. int.TryParse(att.Value, out int no);
  933. correctTableParameter.No = no;
  934. break;
  935. case "name":
  936. correctTableParameter.Name = att.Value;
  937. break;
  938. case "tableuserangemax":
  939. float.TryParse(att.Value, out float tableuserangemax);
  940. correctTableParameter.TableUseRangeMax = tableuserangemax;
  941. break;
  942. case "tableuserangemin":
  943. float.TryParse(att.Value, out float tableuserangemin);
  944. correctTableParameter.TableUseRangeMin = tableuserangemin;
  945. break;
  946. case "profileconditiontableno":
  947. int.TryParse(att.Value, out int profileconditiontableno);
  948. correctTableParameter.ProfileConditionTableNo = profileconditiontableno;
  949. break;
  950. case "pemppidtableno":
  951. int.TryParse(att.Value, out int pemppidtableno);
  952. correctTableParameter.TempPIDTableNo = pemppidtableno;
  953. break;
  954. case "profiletccalibtemp":
  955. float.TryParse(att.Value, out float profiletccalibtemp);
  956. correctTableParameter.ProfileTCCalibTemp = profiletccalibtemp;
  957. break;
  958. }
  959. if (att.Name.ToLower() == "correctiondata" && !dic.ContainsKey(tableIndex))
  960. {
  961. //"Index:1;Name:U;ProfileTemp:0;ProfileCorrect:0;CascadeTCCorrect:0;ProfileTCCalib:0|Index:2;Name:CU;ProfileTemp:0;ProfileCorrect:0;CascadeTCCorrect:0;ProfileTCCalib:0|Index:3;Name:C;ProfileTemp:0;ProfileCorrect:0;CascadeTCCorrect:0;ProfileTCCalib:0|Index:4;Name:CL;ProfileTemp:0;ProfileCorrect:0;CascadeTCCorrect:0;ProfileTCCalib:0|Index:5;Name:L;ProfileTemp:0;ProfileCorrect:0;CascadeTCCorrect:0;ProfileTCCalib:0"
  962. var correctionDataString = att.Value;
  963. if (string.IsNullOrEmpty(correctionDataString))
  964. {
  965. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file is empty");
  966. return;
  967. }
  968. var correctionDatas = correctionDataString.Split('|');
  969. if (correctionDatas.Length < 5)
  970. {
  971. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file data length is invalid");
  972. return;
  973. }
  974. foreach (var datas in correctionDatas)
  975. {
  976. var dataArry = datas.Split(';');
  977. if (dataArry.Length < 6)
  978. {
  979. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file data length is invalid");
  980. return;
  981. }
  982. var correctParameter = new CorrectParameter();
  983. foreach (var item in dataArry)
  984. {
  985. var itemArry = item.Split(':');
  986. if (itemArry.Length < 2)
  987. {
  988. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file data length is invalid");
  989. return;
  990. }
  991. switch (itemArry[0].ToLower())
  992. {
  993. case "index":
  994. int.TryParse(itemArry[1], out int no);
  995. correctParameter.No = no;
  996. break;
  997. case "name":
  998. correctParameter.Name = itemArry[1];
  999. break;
  1000. case "profiletemp":
  1001. float.TryParse(itemArry[1], out float profiletemp);
  1002. correctParameter.ProfileTemp = profiletemp;
  1003. break;
  1004. case "profilecorrect":
  1005. float.TryParse(itemArry[1], out float profilecorrect);
  1006. correctParameter.ProfileCorrect = profilecorrect;
  1007. break;
  1008. case "cascadetccorrect":
  1009. float.TryParse(itemArry[1], out float cascadetccorrect);
  1010. correctParameter.CascadeTCCorrect = cascadetccorrect;
  1011. break;
  1012. case "profiletccalib":
  1013. float.TryParse(itemArry[1], out float profiletccalib);
  1014. correctParameter.ProfileTCCalib = profiletccalib;
  1015. break;
  1016. }
  1017. }
  1018. correctTableParameter.CorrectParameterLst.Add(correctParameter);
  1019. }
  1020. break;
  1021. }
  1022. }
  1023. dic.Add(tableIndex, correctTableParameter);
  1024. }
  1025. if(dic.ContainsKey(index))
  1026. {
  1027. var item = dic[index];
  1028. var heaterIndex = GetHeaterIndex() - 1;//U的index是0
  1029. if(item.CorrectParameterLst.Count > heaterIndex)
  1030. {
  1031. _profileTemp = item.CorrectParameterLst[heaterIndex].ProfileTemp;
  1032. _profileCorrect = item.CorrectParameterLst[heaterIndex].ProfileCorrect;
  1033. _profileTCCalib = item.CorrectParameterLst[heaterIndex].ProfileTCCalib;
  1034. _cascadeTCCorrect = item.CorrectParameterLst[heaterIndex].CascadeTCCorrect;
  1035. }
  1036. else
  1037. {
  1038. _profileTemp = 0;
  1039. _profileCorrect = 0;
  1040. _profileTCCalib = 0;
  1041. _cascadeTCCorrect = 0;
  1042. }
  1043. GetProfileParameters(SC.GetStringValue("PM1.TempProfile"), item.ProfileConditionTableNo, recipeProfileFileName);
  1044. }
  1045. else
  1046. {
  1047. _profileTemp = 0;
  1048. _profileCorrect = 0;
  1049. _profileTCCalib = 0;
  1050. _cascadeTCCorrect = 0;
  1051. //auto select
  1052. }
  1053. var temperature = DeviceData.SetPoint;
  1054. var actualSet = temperature + _profileTCCalib;
  1055. if(temperature > 0)
  1056. TempSetPoint = (float)actualSet;
  1057. DeviceData.CorrectTable = name;
  1058. if (SC.GetStringValue("PM1.TempCorrection") != name)
  1059. SC.SetItemValueFromString("PM1.TempCorrection", name);
  1060. }
  1061. public void SetPIDParameters(string name, string recipePIDFileName = null)
  1062. {
  1063. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  1064. //var defaultPID = SC.GetStringValue("PM1.APCPID");
  1065. if (string.IsNullOrEmpty(name))
  1066. {
  1067. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file is empty");
  1068. return;
  1069. }
  1070. var array = name.Split(',');
  1071. if (array == null || array.Length < 2)
  1072. {
  1073. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature PID parameter");
  1074. return;
  1075. }
  1076. if (!File.Exists($"{PathManager.GetParameterDir()}\\{array[0]}.rcp"))
  1077. return;
  1078. var fileNameAndPath = array[0];
  1079. int.TryParse(array[1], out int index);
  1080. var para = fileNameAndPath.Split('\\').ToList().Skip(2);//"Parameter\\TempPID"
  1081. if (para == null)
  1082. {
  1083. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file is empty");
  1084. return;
  1085. }
  1086. var fileName = string.Join("\\", para.ToArray());
  1087. if (!string.IsNullOrEmpty(recipePIDFileName))
  1088. fileName = recipePIDFileName;
  1089. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\TempPID", fileName, false);
  1090. if (string.IsNullOrEmpty(content))
  1091. {
  1092. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"{fileNameAndPath} heater temperature PID file is empty");
  1093. return;
  1094. }
  1095. var doc = new XmlDocument();
  1096. doc.LoadXml(content);
  1097. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  1098. if (nodeSteps == null)
  1099. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  1100. if (nodeSteps == null)
  1101. {
  1102. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature PID file {fileNameAndPath}");
  1103. return;
  1104. }
  1105. Dictionary<int, List<PIDParameter>> dic = new Dictionary<int, List<PIDParameter>>();
  1106. for (int i = 0; i < nodeSteps.Count; i++)
  1107. {
  1108. var step = nodeSteps[i];
  1109. XmlElement stepNode = step as XmlElement;
  1110. var pidParameters = new List<PIDParameter>();
  1111. int tableIndex = i + 1;
  1112. foreach (XmlAttribute att in stepNode.Attributes)
  1113. {
  1114. if (att.Name == "PIDData" && !dic.ContainsKey(tableIndex))
  1115. {
  1116. //"Index:1;Name:HT.U;P:11.5;I:12;D:13|Index:2;Name:HTCU;P:21.5;I:22;D:23|Index:3;Name:HT.C;P:31.5;I:32;D:33|Index:4;Name:HTCL;P:41.5;I:42;D:43|Index:5;Name:HT.L;P:51.5;I:52;D:53|Index:6;Name:PR.U;P:0.5;I:10;D:0|Index:7;Name:PRCU;P:0.5;I:10;D:0|Index:8;Name:PR.C;P:0.5;I:10;D:0|Index:9;Name:PRCL;P:0.5;I:10;D:0|Index:10;Name:PR.L;P:0.5;I:10;D:0"
  1117. var PIDDataString = att.Value;
  1118. if (string.IsNullOrEmpty(PIDDataString))
  1119. {
  1120. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file is empty");
  1121. return;
  1122. }
  1123. var pidDatas = PIDDataString.Split('|');
  1124. if (pidDatas.Length < 5)
  1125. {
  1126. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file data length is invalid");
  1127. return;
  1128. }
  1129. foreach (var datas in pidDatas)
  1130. {
  1131. var dataArry = datas.Split(';');
  1132. if (dataArry.Length < 5)
  1133. {
  1134. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file data length is invalid");
  1135. return;
  1136. }
  1137. var pidParameter = new PIDParameter();
  1138. foreach (var item in dataArry)
  1139. {
  1140. var itemArry = item.Split(':');
  1141. if (itemArry.Length < 2)
  1142. {
  1143. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature PID file data length is invalid");
  1144. return;
  1145. }
  1146. switch (itemArry[0].ToLower())
  1147. {
  1148. case "index":
  1149. int.TryParse(itemArry[1], out int no);
  1150. pidParameter.No = no;
  1151. break;
  1152. case "name":
  1153. pidParameter.Name = itemArry[1];
  1154. break;
  1155. case "p":
  1156. float.TryParse(itemArry[1], out float p);
  1157. pidParameter.P = p;
  1158. break;
  1159. case "i":
  1160. float.TryParse(itemArry[1], out float ii);
  1161. pidParameter.I = ii;
  1162. break;
  1163. case "d":
  1164. float.TryParse(itemArry[1], out float d);
  1165. pidParameter.D = d;
  1166. break;
  1167. }
  1168. }
  1169. pidParameters.Add(pidParameter);
  1170. }
  1171. break;
  1172. }
  1173. }
  1174. dic.Add(tableIndex, pidParameters);
  1175. }
  1176. if (dic.ContainsKey(index))
  1177. {
  1178. var item = dic[index];
  1179. if (_pidTableAssociate.ContainsKey(Name) && item.Count > _pidTableAssociate[Name] + 5)
  1180. {
  1181. HeaterPID_P = item[_pidTableAssociate[Name]].P;
  1182. HeaterPID_I = item[_pidTableAssociate[Name]].I;
  1183. HeaterPID_D = item[_pidTableAssociate[Name]].D;
  1184. CascadePID_P = item[_pidTableAssociate[Name] + 5].P;
  1185. CascadePID_I = item[_pidTableAssociate[Name] + 5].I;
  1186. CascadePID_D = item[_pidTableAssociate[Name] + 5].D;
  1187. }
  1188. }
  1189. else
  1190. {
  1191. //auto select
  1192. }
  1193. if (SC.GetStringValue("PM1.Heater.PID") != name)
  1194. SC.SetItemValueFromString("PM1.Heater.PID", name);
  1195. DeviceData.PIDTable = name;
  1196. }
  1197. public void GetProfileParameters(string fileNameAndPath, int index, string recipeProfileFileName = null)
  1198. {
  1199. //"Heater;Parameter\\TempCorrection\\tempCorrect,2,Name2;Parameter\\TempPID\\tempPID,3,Name3"
  1200. if (string.IsNullOrEmpty(fileNameAndPath))
  1201. {
  1202. DeviceData.ProfileTable = "";
  1203. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature Profile file is empty");
  1204. return;
  1205. }
  1206. if (!File.Exists($"{PathManager.GetParameterDir()}\\{fileNameAndPath}.rcp"))
  1207. return;
  1208. var para = fileNameAndPath.Split('\\').ToList().Skip(2);//"Parameter\\TempPID"
  1209. if (para == null)
  1210. {
  1211. DeviceData.ProfileTable = "";
  1212. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature Profile file is empty");
  1213. return;
  1214. }
  1215. var fileName = string.Join("\\", para.ToArray());
  1216. if (!string.IsNullOrEmpty(recipeProfileFileName))
  1217. fileName = recipeProfileFileName;
  1218. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\TempProfile", fileName, false);
  1219. if (string.IsNullOrEmpty(content))
  1220. {
  1221. DeviceData.ProfileTable = "";
  1222. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"{fileNameAndPath} heater temperature Profile file is empty");
  1223. return;
  1224. }
  1225. var doc = new XmlDocument();
  1226. doc.LoadXml(content);
  1227. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  1228. if (nodeSteps == null)
  1229. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  1230. if (nodeSteps == null)
  1231. {
  1232. DeviceData.ProfileTable = "";
  1233. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid heater temperature Profile file {fileNameAndPath}");
  1234. return;
  1235. }
  1236. Dictionary<int, ProfileParameter> dic = new Dictionary<int, ProfileParameter>();
  1237. for (int i = 0; i < nodeSteps.Count; i++)
  1238. {
  1239. var step = nodeSteps[i];
  1240. XmlElement stepNode = step as XmlElement;
  1241. var profileParameter = new ProfileParameter();
  1242. int tableIndex = i + 1;
  1243. foreach (XmlAttribute att in stepNode.Attributes)
  1244. {
  1245. switch (att.Name.ToLower())
  1246. {
  1247. case "index":
  1248. int.TryParse(att.Value, out int no);
  1249. profileParameter.No = no;
  1250. break;
  1251. case "name":
  1252. profileParameter.Name = att.Value;
  1253. break;
  1254. case "preheattime":
  1255. float.TryParse(att.Value, out float preheattime);
  1256. profileParameter.PreheatTime = preheattime;
  1257. break;
  1258. case "checktime":
  1259. float.TryParse(att.Value, out float checktime);
  1260. profileParameter.CheckTime = checktime;
  1261. break;
  1262. case "totaltime":
  1263. int.TryParse(att.Value, out int totaltime);
  1264. profileParameter.TotalTime = totaltime;
  1265. break;
  1266. case "alarmlimit":
  1267. int.TryParse(att.Value, out int alarmlimit);
  1268. profileParameter.AlarmLimit = alarmlimit;
  1269. break;
  1270. case "u":
  1271. float.TryParse(att.Value, out float u);
  1272. profileParameter.U = u;
  1273. break;
  1274. case "cu":
  1275. float.TryParse(att.Value, out float cu);
  1276. profileParameter.CU = cu;
  1277. break;
  1278. case "c":
  1279. float.TryParse(att.Value, out float c);
  1280. profileParameter.C = c;
  1281. break;
  1282. case "cl":
  1283. float.TryParse(att.Value, out float cl);
  1284. profileParameter.CL = cl;
  1285. break;
  1286. case "l":
  1287. float.TryParse(att.Value, out float l);
  1288. profileParameter.L = l;
  1289. break;
  1290. }
  1291. }
  1292. dic.Add(tableIndex, profileParameter);
  1293. }
  1294. if (dic.ContainsKey(index))
  1295. {
  1296. var item = dic[index];
  1297. _preheatTime = item.PreheatTime;
  1298. _checkTime = item.CheckTime;
  1299. _alarmLimit = item.AlarmLimit;
  1300. _totalTime = item.TotalTime;
  1301. DeviceData.ProfileTable = $"{fileNameAndPath},{index},{item.Name}";
  1302. switch (Name)
  1303. {
  1304. case "HeaterU":
  1305. _checkLimit = item.U;
  1306. break;
  1307. case "HeaterCU":
  1308. _checkLimit = item.CU;
  1309. break;
  1310. case "HeaterC":
  1311. _checkLimit = item.C;
  1312. break;
  1313. case "HeaterCL":
  1314. _checkLimit = item.CL;
  1315. break;
  1316. case "HeaterL":
  1317. _checkLimit = item.L;
  1318. break;
  1319. }
  1320. DeviceData.ProfileTotalTime = _totalTime;
  1321. DeviceData.ProfilePreheatTime = _preheatTime;
  1322. DeviceData.ProfileCheckTime = _checkTime;
  1323. DeviceData.ProfileAlarmLimit = _alarmLimit;
  1324. DeviceData.ProfileCheckLimit = _checkLimit;
  1325. DeviceData.ProfileStatus = "PreHeat";
  1326. }
  1327. else
  1328. {
  1329. _checkLimit = 0;
  1330. _preheatTime = 0;
  1331. _checkTime = 0;
  1332. _alarmLimit = 0;
  1333. _totalTime = 0;
  1334. DeviceData.ProfileTable = "";
  1335. DeviceData.ProfileTotalTime = 0;
  1336. DeviceData.ProfilePreheatTime = 0;
  1337. DeviceData.ProfileCheckTime = 0;
  1338. DeviceData.ProfileAlarmLimit = 0;
  1339. DeviceData.ProfileCheckLimit = 0;
  1340. }
  1341. }
  1342. public bool CheckProfileFinish(out string reason)
  1343. {
  1344. reason = "";
  1345. if (_profileTimer != null && _profileTimer.IsRunning)
  1346. {
  1347. _profileTotalTimeoutTrig.CLK = _profileTimer.ElapsedMilliseconds >= _totalTime * 1000;
  1348. if (_profileTotalTimeoutTrig.Q)
  1349. {
  1350. LOG.Write($"{Name} profile timeout={_totalTime}");
  1351. EV.PostWarningLog(ModuleName.PM1.ToString(), $"{Name} profile timeout={_totalTime}");//超过total time之后,只是报warning提示
  1352. }
  1353. if (_profileTimer.ElapsedMilliseconds >= _preheatTime * 1000)//preheat time之后,才开始判断
  1354. {
  1355. DeviceData.ProfileStatus = "Profile Check";
  1356. if (_profileStableTimer != null)
  1357. {
  1358. if (!_profileStableTimer.IsRunning)
  1359. _profileStableTimer.Restart();
  1360. if(Math.Abs(TempFeedback - TempSetPoint) > _checkLimit)
  1361. _profileStableTimer.Restart();
  1362. _profileAlarmLimitTrig.CLK = Math.Abs(TempFeedback - TempSetPoint) > _alarmLimit && _alarmLimit > 0;
  1363. if (_profileAlarmLimitTrig.Q)
  1364. EV.PostWarningLog(ModuleName.PM1.ToString(), $"{Name} profile success setpoint={TempSetPoint} feedback={TempFeedback}, difference={Math.Abs(TempFeedback - TempSetPoint)} is more than alarm limit={_alarmLimit}");
  1365. _profileSuccessTrig.CLK = _profileStableTimer.ElapsedMilliseconds > _checkTime * 1000;
  1366. if (_profileStableTimer.ElapsedMilliseconds > _checkTime * 1000)
  1367. {
  1368. IsProfileSuccess = true;
  1369. if(_profileSuccessTrig.Q)
  1370. LOG.Write($"{Name} profile success setpoint={TempSetPoint} feedback={TempFeedback}");
  1371. return true;
  1372. }
  1373. }
  1374. }
  1375. reason = $"{Name} profile not finish";
  1376. return false;
  1377. }
  1378. else
  1379. {
  1380. return true;
  1381. }
  1382. }
  1383. private int GetHeaterIndex()
  1384. {
  1385. int.TryParse(Name.Replace("Heater", ""), out int heaterIndex);//改了heater数量这边需要改
  1386. switch (Name)
  1387. {
  1388. case "HeaterU":
  1389. heaterIndex = 1;
  1390. break;
  1391. case "HeaterCU":
  1392. heaterIndex = 2;
  1393. break;
  1394. case "HeaterC":
  1395. heaterIndex = 3;
  1396. break;
  1397. case "HeaterCL":
  1398. heaterIndex = 4;
  1399. break;
  1400. case "HeaterL":
  1401. heaterIndex = 5;
  1402. break;
  1403. }
  1404. return heaterIndex;
  1405. }
  1406. public bool CheckWaitCondition(out string reason)
  1407. {
  1408. reason = "";
  1409. if (!_isWait || _waitHigh == 0 || _waitLow == 0)
  1410. return true;
  1411. if (_stableJudgmentTimer.IsRunning)
  1412. {
  1413. if (TempFeedback < _tempSetpoint - _waitLow ||
  1414. TempFeedback > _tempSetpoint + _waitHigh)
  1415. {
  1416. _stableJudgmentTimer.Restart();
  1417. }
  1418. if (_stableJudgmentTimer.ElapsedMilliseconds >= _stableJudgmentTime * 1000)
  1419. {
  1420. return true;
  1421. }
  1422. }
  1423. else
  1424. {
  1425. _stableJudgmentTimer.Restart();
  1426. }
  1427. reason = $"{Name} feedback={TempFeedback}, wait limit is ({_tempSetpoint - _waitLow}, {_tempSetpoint + _waitHigh})";
  1428. return false;
  1429. }
  1430. struct PIDParameter
  1431. {
  1432. public int No { get; set; }
  1433. public string Name { get; set; }
  1434. public float P { get; set; }
  1435. public float I { get; set; }
  1436. public float D { get; set; }
  1437. }
  1438. struct CorrectTableParameter
  1439. {
  1440. public int No { get; set; }
  1441. public string Name { get; set; }
  1442. public float ProfileTCCalibTemp { get; set; }
  1443. public float TableUseRangeMin { get; set; }
  1444. public float TableUseRangeMax { get; set; }
  1445. public int ProfileConditionTableNo { get; set; }
  1446. public int TempPIDTableNo { get; set; }
  1447. public List<CorrectParameter> CorrectParameterLst{ get; set; }
  1448. }
  1449. struct ProfileParameter
  1450. {
  1451. public int No { get; set; }
  1452. public string Name { get; set; }
  1453. public float PreheatTime { get; set; }
  1454. public float CheckTime { get; set; }
  1455. public float TotalTime { get; set; }
  1456. public float AlarmLimit { get; set; }
  1457. public float U { get; set; }
  1458. public float CU { get; set; }
  1459. public float C { get; set; }
  1460. public float CL { get; set; }
  1461. public float L { get; set; }
  1462. }
  1463. }
  1464. public struct CorrectParameter
  1465. {
  1466. public int No { get; set; }
  1467. public string Name { get; set; }
  1468. public float ProfileTemp { get; set; }
  1469. public float ProfileTCCalib { get; set; }
  1470. public float ProfileCorrect { get; set; }
  1471. public float CascadeTCCorrect { get; set; }
  1472. }
  1473. }