IOManager.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing.Drawing2D;
  4. using System.Linq;
  5. using System.Xml;
  6. using Aitex.Common.Util;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.IOCore;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.RT.Core.IoProviders;
  15. using Venus_Core;
  16. namespace MECF.Framework.Common.IOCore
  17. {
  18. public class IoManager : Singleton<IoManager>, IIoBuffer
  19. {
  20. private Dictionary<string, DIAccessor> _diMap = new Dictionary<string, DIAccessor>();
  21. private Dictionary<string, DOAccessor> _doMap = new Dictionary<string, DOAccessor>();
  22. private Dictionary<string, AIAccessor> _aiMap = new Dictionary<string, AIAccessor>();
  23. private Dictionary<string, AOAccessor> _aoMap = new Dictionary<string, AOAccessor>();
  24. private Dictionary<string, Dictionary<int, bool[]>> _diBuffer = new Dictionary<string, Dictionary<int, bool[]>>();
  25. private Dictionary<string, Dictionary<int, bool[]>> _doBuffer = new Dictionary<string, Dictionary<int, bool[]>>();
  26. private Dictionary<string, Dictionary<int, short[]>> _aiBuffer = new Dictionary<string, Dictionary<int, short[]>>();
  27. private Dictionary<string, Dictionary<int, short[]>> _aoBuffer = new Dictionary<string, Dictionary<int, short[]>>();
  28. private Dictionary<string, List<DIAccessor>> _diList = new Dictionary<string, List<DIAccessor>>();
  29. private Dictionary<string, List<DOAccessor>> _doList = new Dictionary<string, List<DOAccessor>>();
  30. private Dictionary<string, List<AIAccessor>> _aiList = new Dictionary<string, List<AIAccessor>>();
  31. private Dictionary<string, List<AOAccessor>> _aoList = new Dictionary<string, List<AOAccessor>>();
  32. private Dictionary<string, List<NotifiableIoItem>> _ioItemList = new Dictionary<string, List<NotifiableIoItem>>();
  33. private PeriodicJob _monitorThread;
  34. public void Initialize(string interlockConfigFile)
  35. {
  36. string reason = string.Empty;
  37. if (!InterlockManager.Instance.Initialize(interlockConfigFile, _doMap, _diMap, out reason))
  38. {
  39. throw new Exception(string.Format("interlock define file found error: \r\n {0}", reason));
  40. }
  41. _monitorThread = new PeriodicJob(200, OnTimer, "IO Monitor Thread", true);
  42. }
  43. public void Initialize()
  44. {
  45. string reason = string.Empty;
  46. string installedModules = SC.GetStringValue("System.InstalledModules");
  47. string[] ary= installedModules.Split(',');
  48. List<string> strList = new List<string>(ary);
  49. string[] pms = { "PMA", "PMB", "PMC", "PMD" };
  50. for (int i = 0; i < pms.Length; i++)
  51. {
  52. string pmName = pms[i];
  53. if (installedModules.Contains(pmName))
  54. {
  55. JetChamber jetChamber = (JetChamber)SC.GetValue<int>($"{pmName}.ChamberType");
  56. var InterlockPMConfigFile = PathManager.GetCfgDir() + "PM" + "\\" + jetChamber.ToString() + "\\" + $"{jetChamber.ToString()}Interlock.xml";
  57. if (!InterlockManager.Instance.Initialize(pmName, InterlockPMConfigFile, _doMap, _diMap, out reason))
  58. {
  59. throw new Exception(string.Format($"{pmName} interlock define file found error: \r\n {reason}"));
  60. }
  61. }
  62. }
  63. if (installedModules.Contains("SETM"))
  64. {
  65. var InterlockTMConfigFile = PathManager.GetCfgDir() + "TM" + "\\" + "SETMInterlock.xml";
  66. if (!InterlockManager.Instance.Initialize("SETM", InterlockTMConfigFile, _doMap, _diMap, out reason))
  67. {
  68. throw new Exception(string.Format("TM interlock define file found error: \r\n {0}", reason));
  69. }
  70. }
  71. if (strList.Contains("TM"))
  72. {
  73. var InterlockTMConfigFile = PathManager.GetCfgDir() + "TM" + "\\" + "TMInterlock.xml";
  74. if (!InterlockManager.Instance.Initialize("TM", InterlockTMConfigFile, _doMap, _diMap, out reason))
  75. {
  76. throw new Exception(string.Format("TM interlock define file found error: \r\n {0}", reason));
  77. }
  78. }
  79. _monitorThread = new PeriodicJob(200, OnTimer, "IO Monitor Thread", true);
  80. }
  81. public void Initialize(ConfigType configType)
  82. {
  83. string reason = string.Empty;
  84. string installedModules = SC.GetStringValue("System.InstalledModules");
  85. string[] ary = installedModules.Split(',');
  86. List<string> strList = new List<string>(ary);
  87. string[] pms = { "PMA", "PMB", "PMC", "PMD" };
  88. for (int i = 0; i < pms.Length; i++)
  89. {
  90. string pmName = pms[i];
  91. if (installedModules.Contains(pmName))
  92. {
  93. JetChamber jetChamber = (JetChamber)SC.GetValue<int>($"{pmName}.ChamberType");
  94. var InterlockPMConfigFile = PathManager.GetCfgDir() + "PM" + "\\" + jetChamber.ToString() + "\\" + $"{jetChamber.ToString()}Interlock.xml";
  95. if (!InterlockManager.Instance.Initialize(pmName, InterlockPMConfigFile, _doMap, _diMap, out reason))
  96. {
  97. throw new Exception(string.Format($"{pmName} interlock define file found error: \r\n {reason}"));
  98. }
  99. }
  100. }
  101. if (strList.Contains("TM") && configType == ConfigType.VenusSE)
  102. {
  103. var InterlockTMConfigFile = PathManager.GetCfgDir() + "TM" + "\\" + "SETMInterlock.xml";
  104. if (!InterlockManager.Instance.Initialize("TM", InterlockTMConfigFile, _doMap, _diMap, out reason))
  105. {
  106. throw new Exception(string.Format("TM interlock define file found error: \r\n {0}", reason));
  107. }
  108. }
  109. if (strList.Contains("TM") && configType == ConfigType.VenusDE)
  110. {
  111. var InterlockTMConfigFile = PathManager.GetCfgDir() + "TM" + "\\" + "DETMInterlock.xml";
  112. if (!InterlockManager.Instance.Initialize("TM", InterlockTMConfigFile, _doMap, _diMap, out reason))
  113. {
  114. throw new Exception(string.Format("TM interlock define file found error: \r\n {0}", reason));
  115. }
  116. }
  117. if (strList.Contains("TM") && (configType == ConfigType.Kepler2200 || configType == ConfigType.Kepler2300))
  118. {
  119. var InterlockTMConfigFile = PathManager.GetCfgDir() + "TM" + "\\" + "TMInterlock.xml";
  120. if (!InterlockManager.Instance.Initialize("TM", InterlockTMConfigFile, _doMap, _diMap, out reason))
  121. {
  122. throw new Exception(string.Format("TM interlock define file found error: \r\n {0}", reason));
  123. }
  124. }
  125. _monitorThread = new PeriodicJob(200, OnTimer, "IO Monitor Thread", true);
  126. }
  127. private bool OnTimer()
  128. {
  129. try
  130. {
  131. InterlockManager.Instance.Monitor();
  132. }
  133. catch (Exception ex)
  134. {
  135. LOG.WriteExeption(ex);
  136. }
  137. return true;
  138. }
  139. internal List<Tuple<int, int, string>> GetIONameList(string group, IOType ioType)
  140. {
  141. return null;
  142. }
  143. public bool CanSetDo(string doName, bool onOff, out string reason)
  144. {
  145. return InterlockManager.Instance.CanSetDo(doName, onOff, out reason);
  146. }
  147. public List<DIAccessor> GetDIList(string source)
  148. {
  149. return _diList.ContainsKey(source) ? _diList[source] : null;
  150. }
  151. public List<DOAccessor> GetDOList(string source)
  152. {
  153. return _doList.ContainsKey(source) ? _doList[source] : null;
  154. }
  155. public List<AIAccessor> GetAIList(string source)
  156. {
  157. return _aiList.ContainsKey(source) ? _aiList[source] : null;
  158. }
  159. public List<AOAccessor> GetAOList(string source)
  160. {
  161. return _aoList.ContainsKey(source) ? _aoList[source] : null;
  162. }
  163. public IoManager()
  164. {
  165. OP.Subscribe("System.SetDoValue", InvokeSetDo);
  166. OP.Subscribe("System.SetAoValue", InvokeSetAo);
  167. OP.Subscribe("System.SetAoValue32", InvokeSetAo32);
  168. OP.Subscribe("System.SetDoValueWithPrivoder", InvokeSetDoWithPrivoder);
  169. OP.Subscribe("System.SetAoValueWithPrivoder", InvokeSetAoWithPrivoder);
  170. OP.Subscribe("System.SetAiBuffer", InvokeSetAiBuffer);
  171. OP.Subscribe("System.SetDiBuffer", InvokeSetDiBuffer);
  172. }
  173. private bool InvokeSetDo(string arg1, object[] args)
  174. {
  175. string name = (string) args[0];
  176. bool setpoint = (bool) args[1];
  177. string reason;
  178. if (!CanSetDo(name, setpoint, out reason))
  179. {
  180. EV.PostWarningLog("System", $"Can not set DO {name} to {setpoint}, {reason}");
  181. return false;
  182. }
  183. DOAccessor do1 = GetIO<DOAccessor>(name);
  184. if (do1 == null)
  185. {
  186. EV.PostWarningLog("System", $"Can not set DO {name} to {setpoint}, not defined do");
  187. return false;
  188. }
  189. if (!do1.SetValue(setpoint, out reason))
  190. {
  191. EV.PostWarningLog("System", $"Can not set DO {name} to {setpoint}, {reason}");
  192. return false;
  193. }
  194. EV.PostInfoLog("System", $"Change DO {name} to {setpoint}");
  195. return true;
  196. }
  197. private bool InvokeSetAo(string arg1, object[] args)
  198. {
  199. string name = (string)args[0];
  200. short setpoint = (short)args[1];
  201. AOAccessor io = GetIO<AOAccessor>(name);
  202. if (io == null)
  203. {
  204. EV.PostWarningLog("System", $"Can not set AO {name} to {setpoint}, not defined do");
  205. return false;
  206. }
  207. io.Value = setpoint;
  208. EV.PostInfoLog("System", $"Change AO {name} to {setpoint}");
  209. return true;
  210. }
  211. private bool InvokeSetAo32(string arg1, object[] args)
  212. {
  213. string name = (string)args[0];
  214. float setpoint = (float)args[1];
  215. AOAccessor io = GetIO<AOAccessor>(name);
  216. if (io == null)
  217. {
  218. EV.PostWarningLog("System", $"Can not set AO {name} to {setpoint}, not defined do");
  219. return false;
  220. }
  221. byte[] flow = BitConverter.GetBytes(setpoint);
  222. int index = io.Index;
  223. Int16 value1= BitConverter.ToInt16(flow, 0);
  224. io.Buffer[index] = value1;
  225. if (io.Index < io.Buffer.Length - 1)
  226. {
  227. Int16 value2 = BitConverter.ToInt16(flow, 2);
  228. io.Buffer[index + 1] = value2;
  229. }
  230. EV.PostInfoLog("System", $"Change AO {name} to {setpoint}");
  231. return true;
  232. }
  233. private bool InvokeSetDoWithPrivoder(string arg1, object[] args)
  234. {
  235. string provider = (string)args[0];
  236. int offset = (int)args[1];
  237. string name = (string)args[2];
  238. bool setpoint = (bool)args[3];
  239. string reason;
  240. if (!CanSetDo(name, setpoint, out reason))
  241. {
  242. EV.PostWarningLog("System", $"Can not set DO {provider}.{name} to {setpoint}, {reason}");
  243. return false;
  244. }
  245. var doList = GetDOList(provider);
  246. if(doList == null)
  247. {
  248. EV.PostWarningLog("System", $"Can not set DO {provider}.{name} to {setpoint}, {reason}");
  249. return false;
  250. }
  251. var doAccessor = doList.FirstOrDefault(x => x.Name == name);
  252. if(doAccessor == default(DOAccessor))
  253. {
  254. EV.PostWarningLog("System", $"Can not set DO {provider}.{name} to {setpoint}, {reason}");
  255. return false;
  256. }
  257. if (!doAccessor.SetValue(setpoint, out reason))
  258. {
  259. EV.PostWarningLog("System", $"Can not set DO {provider}.{name} to {setpoint}, {reason}");
  260. return false;
  261. }
  262. EV.PostInfoLog("System", $"Change DO {provider}.{name} to {setpoint}");
  263. return true;
  264. }
  265. private bool InvokeSetAiBuffer(string arg1, object[] args)
  266. {
  267. string provider = (string)args[0];
  268. int offset = (int)args[1];
  269. short[] buffer = (short [])args[2];
  270. SetAiBuffer(provider, offset, buffer);
  271. return true;
  272. }
  273. private bool InvokeSetDiBuffer(string arg1, object[] args)
  274. {
  275. string provider = (string)args[0];
  276. int offset = (int)args[1];
  277. bool[] buffer = (bool[])args[2];
  278. SetDiBuffer(provider, offset, buffer);
  279. return true;
  280. }
  281. private bool InvokeSetAoWithPrivoder(string arg1, object[] args)
  282. {
  283. string provider = (string)args[0];
  284. int offset = (int)args[1];
  285. string name = (string)args[2];
  286. float setpoint = (float)args[3];
  287. string reason = "";
  288. var aoList = GetAOList(provider);
  289. if (aoList == null)
  290. {
  291. EV.PostWarningLog("System", $"Can not set AO {provider}.{name} to {setpoint}, {reason}");
  292. return false;
  293. }
  294. var aoAccessor = aoList.FirstOrDefault(x => x.Name == name);
  295. if (aoAccessor == default(AOAccessor))
  296. {
  297. EV.PostWarningLog("System", $"Can not set AO {provider}.{name} to {setpoint}, {reason}");
  298. return false;
  299. }
  300. aoAccessor.Value = (short)setpoint;
  301. EV.PostInfoLog("System", $"Change DO {provider}.{name} to {setpoint}");
  302. return true;
  303. }
  304. public T GetIO<T>(string name) where T : class
  305. {
  306. if (typeof(T) == typeof(DIAccessor) && _diMap.ContainsKey(name))
  307. {
  308. return _diMap[name] as T;
  309. }
  310. if (typeof(T) == typeof(DOAccessor) && _doMap.ContainsKey(name))
  311. {
  312. return _doMap[name] as T;
  313. }
  314. if (typeof(T) == typeof(AIAccessor) && _aiMap.ContainsKey(name))
  315. {
  316. return _aiMap[name] as T;
  317. }
  318. if (typeof(T) == typeof(AOAccessor) && _aoMap.ContainsKey(name))
  319. {
  320. return _aoMap[name] as T;
  321. }
  322. return null;
  323. }
  324. public Dictionary<int, bool[]> GetDiBuffer(string source)
  325. {
  326. if (_diBuffer.ContainsKey(source))
  327. {
  328. return _diBuffer[source];
  329. }
  330. return null;
  331. }
  332. public Dictionary<int, bool[]> GetDoBuffer(string source)
  333. {
  334. if (_doBuffer.ContainsKey(source))
  335. {
  336. return _doBuffer[source];
  337. }
  338. return null;
  339. }
  340. public Dictionary<int, short[]> GetAiBuffer(string source)
  341. {
  342. if (_aiBuffer.ContainsKey(source))
  343. {
  344. return _aiBuffer[source];
  345. }
  346. return null;
  347. }
  348. public Dictionary<int, short[]> GetAoBuffer(string source)
  349. {
  350. if (_aoBuffer.ContainsKey(source))
  351. {
  352. return _aoBuffer[source];
  353. }
  354. return null;
  355. }
  356. public void SetDiBuffer(string source, int offset, bool[] buffer)
  357. {
  358. if (_diBuffer.ContainsKey(source) && _diBuffer[source].ContainsKey(offset))
  359. {
  360. for (int i = 0; i < buffer.Length && i < _diBuffer[source][offset].Length; i++)
  361. {
  362. _diBuffer[source][offset][i] = buffer[i];
  363. }
  364. }
  365. }
  366. public void SetAiBuffer(string source, int offset, short[] buffer, int skipSize = 0)
  367. {
  368. if (_aiBuffer.ContainsKey(source) && _aiBuffer[source].ContainsKey(offset))
  369. {
  370. for (int i = 0; i < buffer.Length && i < _aiBuffer[source][offset].Length; i++)
  371. {
  372. _aiBuffer[source][offset][i + skipSize] = buffer[i];
  373. }
  374. }
  375. }
  376. public void SetDoBuffer(string source, int offset, bool[] buffer)
  377. {
  378. if (_doBuffer.ContainsKey(source) && _doBuffer[source].ContainsKey(offset))
  379. {
  380. for (int i = 0; i < buffer.Length && i < _doBuffer[source][offset].Length; i++)
  381. {
  382. _doBuffer[source][offset][i] = buffer[i];
  383. }
  384. }
  385. }
  386. public void SetAoBuffer(string source, int offset, short[] buffer)
  387. {
  388. if (_aoBuffer.ContainsKey(source) && _aoBuffer[source].ContainsKey(offset))
  389. {
  390. for (int i = 0; i < buffer.Length && i < _aoBuffer[source][offset].Length; i++)
  391. {
  392. _aoBuffer[source][offset][i] = buffer[i];
  393. }
  394. }
  395. }
  396. //spin recipe set
  397. public void SetAoBuffer(string source, int offset, short[] buffer, int bufferStartIndex)
  398. {
  399. if (_aoBuffer.ContainsKey(source) && _aoBuffer[source].ContainsKey(offset) && _aoBuffer[source][offset].Length > bufferStartIndex)
  400. {
  401. for (int i = 0; i < buffer.Length && bufferStartIndex + i < _aoBuffer[source][offset].Length; i++)
  402. {
  403. _aoBuffer[source][offset][bufferStartIndex + i] = buffer[i];
  404. }
  405. }
  406. }
  407. public void SetBufferBlock(string provider, List<IoBlockItem> lstBlocks)
  408. {
  409. foreach (var ioBlockItem in lstBlocks)
  410. {
  411. switch (ioBlockItem.Type)
  412. {
  413. case IoType.AI:
  414. if (!_aiBuffer.ContainsKey(provider))
  415. {
  416. _aiBuffer[provider] = new Dictionary<int, short[]>();
  417. }
  418. if (!_aiBuffer[provider].ContainsKey(ioBlockItem.Offset))
  419. {
  420. _aiBuffer[provider][ioBlockItem.Offset] = new short[ioBlockItem.Size];
  421. }
  422. break;
  423. case IoType.AO:
  424. if (!_aoBuffer.ContainsKey(provider))
  425. {
  426. _aoBuffer[provider] = new Dictionary<int, short[]>();
  427. }
  428. if (!_aoBuffer[provider].ContainsKey(ioBlockItem.Offset))
  429. {
  430. _aoBuffer[provider][ioBlockItem.Offset] = new short[ioBlockItem.Size];
  431. }
  432. break;
  433. case IoType.DI:
  434. if (!_diBuffer.ContainsKey(provider))
  435. {
  436. _diBuffer[provider] = new Dictionary<int, bool[]>();
  437. }
  438. if (!_diBuffer[provider].ContainsKey(ioBlockItem.Offset))
  439. {
  440. _diBuffer[provider][ioBlockItem.Offset] = new bool[ioBlockItem.Size];
  441. }
  442. break;
  443. case IoType.DO:
  444. if (!_doBuffer.ContainsKey(provider))
  445. {
  446. _doBuffer[provider] = new Dictionary<int, bool[]>();
  447. }
  448. if (!_doBuffer[provider].ContainsKey(ioBlockItem.Offset))
  449. {
  450. _doBuffer[provider][ioBlockItem.Offset] = new bool[ioBlockItem.Size];
  451. }
  452. break;
  453. }
  454. }
  455. }
  456. List<NotifiableIoItem> SubscribeDiData()
  457. {
  458. List<NotifiableIoItem> result = new List<NotifiableIoItem>();
  459. foreach (var ioDefine in _diMap)
  460. {
  461. NotifiableIoItem di = new NotifiableIoItem()
  462. {
  463. Address = ioDefine.Value.Addr,
  464. Name = ioDefine.Value.Name,
  465. Description = ioDefine.Value.Description,
  466. Index = ioDefine.Value.Index,
  467. BoolValue = ioDefine.Value.Value,
  468. Provider = ioDefine.Value.Provider,
  469. BlockOffset = ioDefine.Value.BlockOffset,
  470. BlockIndex = ioDefine.Value.Index,
  471. };
  472. result.Add(di);
  473. }
  474. return result;
  475. }
  476. List<NotifiableIoItem> SubscribeDoData()
  477. {
  478. List<NotifiableIoItem> result = new List<NotifiableIoItem>();
  479. foreach (var ioDefine in _doMap)
  480. {
  481. NotifiableIoItem io = new NotifiableIoItem()
  482. {
  483. Address = ioDefine.Value.Addr,
  484. Name = ioDefine.Value.Name,
  485. Description = ioDefine.Value.Description,
  486. Index = ioDefine.Value.Index,
  487. BoolValue = ioDefine.Value.Value,
  488. Provider = ioDefine.Value.Provider,
  489. BlockOffset = ioDefine.Value.BlockOffset,
  490. BlockIndex = ioDefine.Value.Index,
  491. };
  492. result.Add(io);
  493. }
  494. return result;
  495. }
  496. List<NotifiableIoItem> SubscribeAiData()
  497. {
  498. List<NotifiableIoItem> result = new List<NotifiableIoItem>();
  499. foreach (var ioDefine in _aiMap)
  500. {
  501. NotifiableIoItem di = new NotifiableIoItem()
  502. {
  503. Address = ioDefine.Value.Addr,
  504. Name = ioDefine.Value.Name,
  505. Description = ioDefine.Value.Description,
  506. Index = ioDefine.Value.Index,
  507. ShortValue = ioDefine.Value.Value,
  508. Provider = ioDefine.Value.Provider,
  509. BlockOffset = ioDefine.Value.BlockOffset,
  510. BlockIndex = ioDefine.Value.Index,
  511. };
  512. result.Add(di);
  513. }
  514. return result;
  515. }
  516. List<NotifiableIoItem> SubscribeAoData()
  517. {
  518. List<NotifiableIoItem> result = new List<NotifiableIoItem>();
  519. foreach (var ioDefine in _aoMap)
  520. {
  521. NotifiableIoItem ao = new NotifiableIoItem()
  522. {
  523. Address = ioDefine.Value.Addr,
  524. Name = ioDefine.Value.Name,
  525. Description = ioDefine.Value.Description,
  526. Index = ioDefine.Value.Index,
  527. ShortValue = ioDefine.Value.Value,
  528. Provider = ioDefine.Value.Provider,
  529. BlockOffset = ioDefine.Value.BlockOffset,
  530. BlockIndex = ioDefine.Value.Index,
  531. };
  532. result.Add(ao);
  533. }
  534. return result;
  535. }
  536. public void SetIoMap(string provider, int blockOffset, List<DIAccessor> ioList)
  537. {
  538. SubscribeIoItemList(provider);
  539. var scConfig = SC.GetConfigItem("System.IsIgnoreSaveDB");
  540. var isIgnoreSaveDB = scConfig != null && scConfig.BoolValue;
  541. foreach (var accessor in ioList)
  542. {
  543. accessor.Provider = provider;
  544. accessor.BlockOffset = blockOffset;
  545. _diMap[accessor.Name] = accessor;
  546. if (!_diList.ContainsKey(provider))
  547. _diList[provider] = new List<DIAccessor>();
  548. _diList[provider].Add(accessor);
  549. _ioItemList[$"{provider}.DIItemList"].Add(new NotifiableIoItem()
  550. {
  551. Address = accessor.Addr,
  552. Name = accessor.Name,
  553. Description = accessor.Description,
  554. Index = accessor.Index,
  555. Provider = provider,
  556. BlockOffset = blockOffset,
  557. BlockIndex = accessor.BlockOffset,
  558. });
  559. if (isIgnoreSaveDB)
  560. {
  561. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  562. }
  563. else
  564. {
  565. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value);
  566. }
  567. }
  568. }
  569. public void SetIoMap(string provider, int blockOffset, List<DOAccessor> ioList)
  570. {
  571. SubscribeIoItemList(provider);
  572. var scConfig = SC.GetConfigItem("System.IsIgnoreSaveDB");
  573. var isIgnoreSaveDB = scConfig != null && scConfig.BoolValue;
  574. foreach (var accessor in ioList)
  575. {
  576. accessor.Provider = provider;
  577. accessor.BlockOffset = blockOffset;
  578. _doMap[accessor.Name] = accessor;
  579. if (!_doList.ContainsKey(provider))
  580. _doList[provider] = new List<DOAccessor>();
  581. _doList[provider].Add(accessor);
  582. _ioItemList[$"{provider}.DOItemList"].Add(new NotifiableIoItem()
  583. {
  584. Address = accessor.Addr,
  585. Name = accessor.Name,
  586. Description = accessor.Description,
  587. Index = accessor.Index,
  588. Provider = provider,
  589. BlockOffset = blockOffset,
  590. BlockIndex = accessor.BlockOffset,
  591. });
  592. if (isIgnoreSaveDB)
  593. {
  594. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  595. }
  596. else
  597. {
  598. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value);
  599. }
  600. }
  601. }
  602. public void SetIoMap(string provider, int blockOffset, List<AIAccessor> ioList)
  603. {
  604. SubscribeIoItemList(provider);
  605. var scConfig = SC.GetConfigItem("System.IsIgnoreSaveDB");
  606. var isIgnoreSaveDB = scConfig != null && scConfig.BoolValue;
  607. foreach (var accessor in ioList)
  608. {
  609. accessor.Provider = provider;
  610. accessor.BlockOffset = blockOffset;
  611. _aiMap[accessor.Name] = accessor;
  612. if (!_aiList.ContainsKey(provider))
  613. _aiList[provider] = new List<AIAccessor>();
  614. _aiList[provider].Add(accessor);
  615. _ioItemList[$"{provider}.AIItemList"].Add(new NotifiableIoItem()
  616. {
  617. Address = accessor.Addr,
  618. Name = accessor.Name,
  619. Description = accessor.Description,
  620. Index = accessor.Index,
  621. Provider = provider,
  622. BlockOffset = blockOffset,
  623. BlockIndex = accessor.BlockOffset,
  624. });
  625. if (isIgnoreSaveDB)
  626. {
  627. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  628. DATA.Subscribe($"IO32.{accessor.Name}", () =>
  629. {
  630. if (accessor.Index < accessor.Buffer.Length - 1)
  631. {
  632. byte[] high = BitConverter.GetBytes(accessor.Buffer[accessor.Index]);
  633. byte[] low = BitConverter.GetBytes(accessor.Buffer[accessor.Index + 1]);
  634. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  635. }
  636. else
  637. {
  638. return accessor.Value;
  639. }
  640. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  641. }
  642. else
  643. {
  644. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value);
  645. DATA.Subscribe($"IO32.{accessor.Name}", () =>
  646. {
  647. if (accessor.Index < accessor.Buffer.Length - 1)
  648. {
  649. byte[] high = BitConverter.GetBytes(accessor.Buffer[accessor.Index]);
  650. byte[] low = BitConverter.GetBytes(accessor.Buffer[accessor.Index + 1]);
  651. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  652. }
  653. else
  654. {
  655. return accessor.Value;
  656. }
  657. });
  658. }
  659. }
  660. }
  661. public void SetIoMap(string provider, int blockOffset, List<AOAccessor> ioList)
  662. {
  663. SubscribeIoItemList(provider);
  664. var scConfig = SC.GetConfigItem("System.IsIgnoreSaveDB");
  665. var isIgnoreSaveDB = scConfig != null && scConfig.BoolValue;
  666. foreach (var accessor in ioList)
  667. {
  668. accessor.Provider = provider;
  669. accessor.BlockOffset = blockOffset;
  670. _aoMap[accessor.Name] = accessor;
  671. if (!_aoList.ContainsKey(provider))
  672. _aoList[provider] = new List<AOAccessor>();
  673. _aoList[provider].Add(accessor);
  674. _ioItemList[$"{provider}.AOItemList"].Add(new NotifiableIoItem()
  675. {
  676. Address = accessor.Addr,
  677. Name = accessor.Name,
  678. Description = accessor.Description,
  679. Index = accessor.Index,
  680. Provider = provider,
  681. BlockOffset = blockOffset,
  682. BlockIndex = accessor.BlockOffset,
  683. });
  684. if (isIgnoreSaveDB)
  685. {
  686. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  687. DATA.Subscribe($"IO32.{accessor.Name}", () =>
  688. {
  689. if (accessor.Index < accessor.Buffer.Length - 1)
  690. {
  691. byte[] high = BitConverter.GetBytes(accessor.Buffer[accessor.Index]);
  692. byte[] low = BitConverter.GetBytes(accessor.Buffer[accessor.Index + 1]);
  693. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  694. }
  695. else
  696. {
  697. return accessor.Value;
  698. }
  699. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  700. }
  701. else
  702. {
  703. DATA.Subscribe($"IO.{accessor.Name}", () => accessor.Value);
  704. DATA.Subscribe($"IO32.{accessor.Name}", () =>
  705. {
  706. if (accessor.Index < accessor.Buffer.Length - 1)
  707. {
  708. byte[] high = BitConverter.GetBytes(accessor.Buffer[accessor.Index]);
  709. byte[] low = BitConverter.GetBytes(accessor.Buffer[accessor.Index + 1]);
  710. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  711. }
  712. else
  713. {
  714. return accessor.Value;
  715. }
  716. });
  717. }
  718. }
  719. }
  720. public void SetIoMap(string provider, int blockOffset, string xmlPathFile, string module="")
  721. {
  722. SubscribeIoItemList(provider);
  723. XmlDocument xml = new XmlDocument();
  724. xml.Load(xmlPathFile);
  725. XmlNodeList lstDi = xml.SelectNodes("IO_DEFINE/Dig_In/DI_ITEM");
  726. var scConfig = SC.GetConfigItem("System.IsIgnoreSaveDB");
  727. var isIgnoreSaveDB = scConfig == null ? false : scConfig.BoolValue;
  728. //<DI_ITEM Index="0" Name="" BufferOffset="0" Addr="0" Description=""/>
  729. List<DIAccessor> diList = new List<DIAccessor>();
  730. foreach (var diItem in lstDi)
  731. {
  732. XmlElement element = diItem as XmlElement;
  733. if (element == null)
  734. continue;
  735. string index = element.GetAttribute("Index");
  736. string bufferOffset = element.GetAttribute("BufferOffset");
  737. if (string.IsNullOrEmpty(bufferOffset))
  738. bufferOffset = index;
  739. string name = element.GetAttribute("Name");
  740. string address = element.GetAttribute("Addr");
  741. string description = element.GetAttribute("Description");
  742. if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(index) || string.IsNullOrEmpty(bufferOffset))
  743. continue;
  744. name = name.Trim();
  745. index = index.Trim();
  746. bufferOffset = bufferOffset.Trim();
  747. string moduleName = string.IsNullOrEmpty(module) ? name : $"{module}.{name}";
  748. int intIndex;
  749. if (!int.TryParse(index, out intIndex))
  750. continue;
  751. int intBufferOffset;
  752. if (!int.TryParse(bufferOffset, out intBufferOffset))
  753. continue;
  754. if (!_diBuffer.ContainsKey(provider) || !_diBuffer[provider].ContainsKey(blockOffset))
  755. {
  756. throw new Exception("Not defined DI buffer from IO provider, " + provider);
  757. }
  758. DIAccessor diAccessor = new DIAccessor(moduleName, intBufferOffset, _diBuffer[provider][blockOffset], _diBuffer[provider][blockOffset]);
  759. diAccessor.IoTableIndex = intIndex;
  760. diAccessor.Addr = address;
  761. diAccessor.Provider = provider;
  762. diAccessor.BlockOffset = blockOffset;
  763. diAccessor.Description = description;
  764. diList.Add(diAccessor);
  765. _diMap[moduleName] = diAccessor;
  766. if (!_diList.ContainsKey(provider))
  767. _diList[provider] = new List<DIAccessor>();
  768. _diList[provider].Add(diAccessor);
  769. _ioItemList[$"{provider}.DIItemList"].Add(new NotifiableIoItem()
  770. {
  771. Address = address,
  772. Name = moduleName,
  773. Description = description,
  774. Index = intIndex,
  775. Provider = provider,
  776. BlockOffset = blockOffset,
  777. BlockIndex = intIndex,
  778. });
  779. if (isIgnoreSaveDB)
  780. {
  781. DATA.Subscribe($"IO.{moduleName}", () => diAccessor.Value, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  782. }
  783. else
  784. {
  785. DATA.Subscribe($"IO.{moduleName}", () => diAccessor.Value);
  786. }
  787. }
  788. XmlNodeList lstDo = xml.SelectNodes("IO_DEFINE/Dig_Out/DO_ITEM");
  789. // < DO_ITEM Index = "0" BufferOffset="0" Name = "" Addr = "0" Description = "" />
  790. foreach (var doItem in lstDo)
  791. {
  792. XmlElement element = doItem as XmlElement;
  793. if (element == null)
  794. continue;
  795. string index = element.GetAttribute("Index");
  796. string bufferOffset = element.GetAttribute("BufferOffset");
  797. if (string.IsNullOrEmpty(bufferOffset))
  798. bufferOffset = index;
  799. string name = element.GetAttribute("Name");
  800. string address = element.GetAttribute("Addr");
  801. string description = element.GetAttribute("Description");
  802. if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(index) || string.IsNullOrEmpty(bufferOffset))
  803. continue;
  804. name = name.Trim();
  805. index = index.Trim();
  806. bufferOffset = bufferOffset.Trim();
  807. string moduleName = string.IsNullOrEmpty(module) ? name : $"{module}.{name}";
  808. int intIndex;
  809. if (!int.TryParse(index, out intIndex))
  810. continue;
  811. int intBufferOffset;
  812. if (!int.TryParse(bufferOffset, out intBufferOffset))
  813. continue;
  814. if (!_doBuffer.ContainsKey(provider) || !_doBuffer[provider].ContainsKey(blockOffset))
  815. {
  816. throw new Exception("Not defined DO buffer from IO provider, " + provider);
  817. }
  818. DOAccessor doAccessor = new DOAccessor(moduleName, intBufferOffset, _doBuffer[provider][blockOffset]);
  819. _doMap[moduleName] = doAccessor;
  820. doAccessor.IoTableIndex = intIndex;
  821. doAccessor.Addr = address;
  822. doAccessor.Provider = provider;
  823. doAccessor.BlockOffset = blockOffset;
  824. doAccessor.Description = description;
  825. if (!_doList.ContainsKey(provider))
  826. _doList[provider] = new List<DOAccessor>();
  827. _doList[provider].Add(doAccessor);
  828. _ioItemList[$"{provider}.DOItemList"].Add(new NotifiableIoItem()
  829. {
  830. Address = address,
  831. Name = moduleName,
  832. Description = description,
  833. Index = intIndex,
  834. Provider = provider,
  835. BlockOffset = blockOffset,
  836. BlockIndex = intIndex,
  837. });
  838. if (isIgnoreSaveDB)
  839. {
  840. DATA.Subscribe($"IO.{moduleName}", () => doAccessor.Value,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  841. }
  842. else
  843. {
  844. DATA.Subscribe($"IO.{moduleName}", () => doAccessor.Value);
  845. }
  846. }
  847. XmlNodeList lstAo = xml.SelectNodes("IO_DEFINE/Ana_Out/AO_ITEM");
  848. // < AO_ITEM Index = "0" BufferOffset="0" Name = "" Addr = "0" Description = "" />
  849. foreach (var aoItem in lstAo)
  850. {
  851. XmlElement element = aoItem as XmlElement;
  852. if (element == null)
  853. continue;
  854. string index = element.GetAttribute("Index");
  855. string bufferOffset = element.GetAttribute("BufferOffset");
  856. if (string.IsNullOrEmpty(bufferOffset))
  857. bufferOffset = index;
  858. string name = element.GetAttribute("Name");
  859. string address = element.GetAttribute("Addr");
  860. string description = element.GetAttribute("Description");
  861. if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(index) || string.IsNullOrEmpty(bufferOffset))
  862. continue;
  863. name = name.Trim();
  864. index = index.Trim();
  865. bufferOffset = bufferOffset.Trim();
  866. string moduleName = string.IsNullOrEmpty(module) ? name : $"{module}.{name}";
  867. int intIndex;
  868. if (!int.TryParse(index, out intIndex))
  869. continue;
  870. int intBufferOffset;
  871. if (!int.TryParse(bufferOffset, out intBufferOffset))
  872. continue;
  873. if (!_aoBuffer.ContainsKey(provider) || !_aoBuffer[provider].ContainsKey(blockOffset))
  874. {
  875. throw new Exception("Not defined AO buffer from IO provider, " + provider);
  876. }
  877. AOAccessor aoAccessor = new AOAccessor(moduleName, intBufferOffset, _aoBuffer[provider][blockOffset]);
  878. _aoMap[moduleName] = aoAccessor;
  879. aoAccessor.IoTableIndex = intIndex;
  880. aoAccessor.Addr = address;
  881. aoAccessor.Provider = provider;
  882. aoAccessor.BlockOffset = blockOffset;
  883. aoAccessor.Description = description;
  884. if (!_aoList.ContainsKey(provider))
  885. _aoList[provider] = new List<AOAccessor>();
  886. _aoList[provider].Add(aoAccessor);
  887. _ioItemList[$"{provider}.AOItemList"].Add(new NotifiableIoItem()
  888. {
  889. Address = address,
  890. Name = moduleName,
  891. Description = description,
  892. Index = intIndex,
  893. Provider = provider,
  894. BlockOffset = blockOffset,
  895. BlockIndex = intIndex,
  896. });
  897. if (isIgnoreSaveDB)
  898. {
  899. DATA.Subscribe($"IO.{moduleName}", () => aoAccessor.Value,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  900. DATA.Subscribe($"IO32.{moduleName}", () =>
  901. {
  902. if (aoAccessor.Index < aoAccessor.Buffer.Length - 1)
  903. {
  904. byte[] high = BitConverter.GetBytes(aoAccessor.Buffer[aoAccessor.Index]);
  905. byte[] low = BitConverter.GetBytes(aoAccessor.Buffer[aoAccessor.Index + 1]);
  906. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  907. }
  908. else
  909. {
  910. return aoAccessor.Value;
  911. }
  912. },SubscriptionAttribute.FLAG.IgnoreSaveDB);
  913. }
  914. else
  915. {
  916. DATA.Subscribe($"IO.{moduleName}", () => aoAccessor.Value);
  917. DATA.Subscribe($"IO32.{moduleName}", () =>
  918. {
  919. if (aoAccessor.Index < aoAccessor.Buffer.Length - 1)
  920. {
  921. byte[] high = BitConverter.GetBytes(aoAccessor.Buffer[aoAccessor.Index]);
  922. byte[] low = BitConverter.GetBytes(aoAccessor.Buffer[aoAccessor.Index + 1]);
  923. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  924. }
  925. else
  926. {
  927. return aoAccessor.Value;
  928. }
  929. });
  930. }
  931. }
  932. XmlNodeList lstAi = xml.SelectNodes("IO_DEFINE/Ana_In/AI_ITEM");
  933. // < AO_ITEM Index = "0" BufferOffset="0" Name = "" Addr = "0" Description = "" />
  934. foreach (var aiItem in lstAi)
  935. {
  936. XmlElement element = aiItem as XmlElement;
  937. if (element == null)
  938. continue;
  939. string index = element.GetAttribute("Index");
  940. string bufferOffset = element.GetAttribute("BufferOffset");
  941. if (string.IsNullOrEmpty(bufferOffset))
  942. bufferOffset = index;
  943. string name = element.GetAttribute("Name");
  944. string address = element.GetAttribute("Addr");
  945. string description = element.GetAttribute("Description");
  946. if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(index) || string.IsNullOrEmpty(bufferOffset))
  947. continue;
  948. name = name.Trim();
  949. index = index.Trim();
  950. bufferOffset = bufferOffset.Trim();
  951. string moduleName = string.IsNullOrEmpty(module) ? name : $"{module}.{name}";
  952. int intIndex;
  953. if (!int.TryParse(index, out intIndex))
  954. continue;
  955. int intBufferOffset;
  956. if (!int.TryParse(bufferOffset, out intBufferOffset))
  957. continue;
  958. if (!_aiBuffer.ContainsKey(provider) || !_aiBuffer[provider].ContainsKey(blockOffset))
  959. {
  960. throw new Exception("Not defined AI buffer from IO provider, " + provider);
  961. }
  962. AIAccessor aiAccessor = new AIAccessor(moduleName, intBufferOffset, _aiBuffer[provider][blockOffset]);
  963. _aiMap[moduleName] = aiAccessor;
  964. aiAccessor.IoTableIndex = intIndex;
  965. aiAccessor.Addr = address;
  966. aiAccessor.Provider = provider;
  967. aiAccessor.BlockOffset = blockOffset;
  968. aiAccessor.Description = description;
  969. if (!_aiList.ContainsKey(provider))
  970. _aiList[provider] = new List<AIAccessor>();
  971. _aiList[provider].Add(aiAccessor);
  972. _ioItemList[$"{provider}.AIItemList"].Add(new NotifiableIoItem()
  973. {
  974. Address = address,
  975. Name = moduleName,
  976. Description = description,
  977. Index = intIndex,
  978. Provider = provider,
  979. BlockOffset = blockOffset,
  980. BlockIndex = intIndex,
  981. });
  982. if (isIgnoreSaveDB)
  983. {
  984. DATA.Subscribe($"IO.{moduleName}", () => aiAccessor.Value, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  985. DATA.Subscribe($"IO32.{moduleName}", () =>
  986. {
  987. if (aiAccessor.Index < aiAccessor.Buffer.Length - 1)
  988. {
  989. byte[] high = BitConverter.GetBytes(aiAccessor.Buffer[aiAccessor.Index]);
  990. byte[] low = BitConverter.GetBytes(aiAccessor.Buffer[aiAccessor.Index + 1]);
  991. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  992. }
  993. else
  994. {
  995. return aiAccessor.Value;
  996. }
  997. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  998. }
  999. else
  1000. {
  1001. DATA.Subscribe($"IO.{moduleName}", () => aiAccessor.Value);
  1002. DATA.Subscribe($"IO32.{moduleName}", () =>
  1003. {
  1004. if (aiAccessor.Index < aiAccessor.Buffer.Length - 1)
  1005. {
  1006. byte[] high = BitConverter.GetBytes(aiAccessor.Buffer[aiAccessor.Index]);
  1007. byte[] low = BitConverter.GetBytes(aiAccessor.Buffer[aiAccessor.Index + 1]);
  1008. return BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  1009. }
  1010. else
  1011. {
  1012. return aiAccessor.Value;
  1013. }
  1014. });
  1015. }
  1016. }
  1017. }
  1018. public void SetIoMap(string provider, Dictionary<int, string> ioMappingPathFile)
  1019. {
  1020. foreach (var map in ioMappingPathFile)
  1021. {
  1022. SetIoMap(provider, map.Key, map.Value);
  1023. }
  1024. DATA.Subscribe(provider, "DIList", SubscribeDiData);
  1025. DATA.Subscribe(provider, "DOList", SubscribeDoData);
  1026. DATA.Subscribe(provider, "AIList", SubscribeAiData);
  1027. DATA.Subscribe(provider, "AOList", SubscribeAoData);
  1028. }
  1029. public void SetIoMapByModule(string provider, int offset, string ioMappingPathFile, string module)
  1030. {
  1031. SetIoMap(provider, offset, ioMappingPathFile, module);
  1032. DATA.Subscribe(provider, "DIList", SubscribeDiData);
  1033. DATA.Subscribe(provider, "DOList", SubscribeDoData);
  1034. DATA.Subscribe(provider, "AIList", SubscribeAiData);
  1035. DATA.Subscribe(provider, "AOList", SubscribeAoData);
  1036. }
  1037. private void SubscribeIoItemList(string provider)
  1038. {
  1039. string diKey = $"{provider}.DIItemList";
  1040. if (!_ioItemList.ContainsKey(diKey))
  1041. {
  1042. _ioItemList[diKey] = new List<NotifiableIoItem>();
  1043. DATA.Subscribe(diKey, () => _ioItemList[diKey]);
  1044. }
  1045. string doKey = $"{provider}.DOItemList";
  1046. if (!_ioItemList.ContainsKey(doKey))
  1047. {
  1048. _ioItemList[doKey] = new List<NotifiableIoItem>();
  1049. DATA.Subscribe(doKey, () => _ioItemList[doKey]);
  1050. }
  1051. string aiKey = $"{provider}.AIItemList";
  1052. if (!_ioItemList.ContainsKey(aiKey))
  1053. {
  1054. _ioItemList[aiKey] = new List<NotifiableIoItem>();
  1055. DATA.Subscribe(aiKey, () => _ioItemList[aiKey]);
  1056. }
  1057. string aoKey = $"{provider}.AOItemList";
  1058. if (!_ioItemList.ContainsKey(aoKey))
  1059. {
  1060. _ioItemList[aoKey] = new List<NotifiableIoItem>();
  1061. DATA.Subscribe(aoKey, () => _ioItemList[aoKey]);
  1062. }
  1063. }
  1064. }
  1065. }