IoHeater.cs 70 KB

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