IO2Provider.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MECF.Framework.Common.DataCenter;
  8. using MECF.Framework.Common.IOCore;
  9. using OpenSEMI.ClientBase.IO;
  10. using OpenSEMI.ClientBase.ServiceProvider;
  11. namespace VirgoUI.Client.Models.Common.IO
  12. {
  13. public class IO2Provider : IProvider
  14. {
  15. private static IO2Provider _Instance = null;
  16. public static IO2Provider Instance
  17. {
  18. get
  19. {
  20. if (_Instance == null)
  21. {
  22. _Instance = new IO2Provider();
  23. _Instance.Create();
  24. }
  25. return _Instance;
  26. }
  27. }
  28. private const string Provider = "System.io2";
  29. public void Create()
  30. {
  31. }
  32. public Dictionary<string, T> GetIOData<T>(string type)
  33. {
  34. //get only value by keys
  35. Dictionary<string, T> da = new Dictionary<string, T>();
  36. if (type == "PLC1.DIList")
  37. {
  38. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList");
  39. if (diList != null)
  40. {
  41. List<NotifiableIoItem> di = (List<NotifiableIoItem>)diList;
  42. for (int i = 0; i < di.Count; i++)
  43. {
  44. if (di[i].Provider != Provider)
  45. continue;
  46. bool value = true;
  47. if (value is T)
  48. {
  49. da[di[i].Name] = (T)(object)di[i].BoolValue;
  50. }
  51. }
  52. }
  53. }
  54. if (type == "PLC1.DOList")
  55. {
  56. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DOList");
  57. if (diList != null)
  58. {
  59. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  60. for (int i = 0; i < item.Count; i++)
  61. {
  62. if (item[i].Provider != Provider)
  63. continue;
  64. bool value = true;
  65. if (value is T)
  66. {
  67. da[item[i].Name] = (T)(object)item[i].BoolValue;
  68. }
  69. }
  70. }
  71. }
  72. if (type == "PLC1.AIList")
  73. {
  74. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  75. if (diList != null)
  76. {
  77. List<NotifiableIoItem> di = (List<NotifiableIoItem>)diList;
  78. for (int i = 0; i < di.Count; i++)
  79. {
  80. if (di[i].Provider != Provider)
  81. continue;
  82. da[di[i].Name] = (T)(object)di[i].ShortValue;
  83. }
  84. }
  85. }
  86. if (type == "PLC1.AOList")
  87. {
  88. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");
  89. if (diList != null)
  90. {
  91. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  92. for (int i = 0; i < item.Count; i++)
  93. {
  94. if (item[i].Provider != Provider)
  95. continue;
  96. da[item[i].Name] = (T)(object)item[i].ShortValue;
  97. }
  98. }
  99. }
  100. return da;
  101. }
  102. public ObservableCollection<IOItem<T>> InitIOData<T>(string type)
  103. {
  104. //get the whole informations
  105. ObservableCollection<IOItem<T>> da = new ObservableCollection<IOItem<T>>();
  106. if (type == "PLC1.DIList")
  107. {
  108. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList");
  109. if (diList != null)
  110. {
  111. List<NotifiableIoItem> di = (List<NotifiableIoItem>)diList;
  112. for (int i = 0; i < di.Count; i++)
  113. {
  114. if (di[i].Provider != Provider)
  115. continue;
  116. bool value = true;
  117. if (value is T)
  118. {
  119. da.Add(new IOItem<T>()
  120. {
  121. Index = di[i].Index,
  122. Name = di[i].Name,
  123. Value = (T)(object)di[i].BoolValue,
  124. Address = di[i].Address
  125. });
  126. }
  127. }
  128. }
  129. }
  130. if (type == "PLC1.DOList")
  131. {
  132. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DOList");
  133. if (diList != null)
  134. {
  135. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  136. for (int i = 0; i < item.Count; i++)
  137. {
  138. if (item[i].Provider != Provider)
  139. continue;
  140. bool value = true;
  141. if (value is T)
  142. {
  143. da.Add(new IOItem<T>()
  144. {
  145. Index = item[i].Index,
  146. Name = item[i].Name,
  147. Value = (T)(object)item[i].BoolValue,
  148. Address = item[i].Address
  149. });
  150. }
  151. }
  152. }
  153. }
  154. if (type == "PLC1.AIList")
  155. {
  156. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  157. if (diList != null)
  158. {
  159. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  160. for (int i = 0; i < item.Count; i++)
  161. {
  162. if (item[i].Provider != Provider)
  163. continue;
  164. da.Add(new IOItem<T>()
  165. {
  166. Index = item[i].Index,
  167. Name = item[i].Name,
  168. Value = (T)(object)item[i].ShortValue,
  169. Address = item[i].Address
  170. });
  171. }
  172. }
  173. }
  174. return da;
  175. }
  176. public ObservableCollection<AOItem> InitIOData(string type)
  177. {
  178. //get the whole informations
  179. ObservableCollection<AOItem> da = new ObservableCollection<AOItem>();
  180. if (type == "PLC1.AOList")
  181. {
  182. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");
  183. if (diList != null)
  184. {
  185. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  186. for (int i = 0; i < item.Count; i++)
  187. {
  188. if (item[i].Provider != Provider)
  189. continue;
  190. //bool value = true;
  191. //if (value is T)
  192. {
  193. da.Add(new AOItem()
  194. {
  195. Index = item[i].Index,
  196. Name = item[i].Name,
  197. Value = item[i].ShortValue,
  198. Address = item[i].Address
  199. });
  200. }
  201. }
  202. }
  203. }
  204. return da;
  205. }
  206. public void SetAO(string name, float value)
  207. {
  208. }
  209. public void SetDO(string name, bool value)
  210. {
  211. }
  212. }
  213. }