IO1Provider.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 IO1Provider : IProvider
  14. {
  15. private static IO1Provider _Instance = null;
  16. public static IO1Provider Instance
  17. {
  18. get
  19. {
  20. if (_Instance == null)
  21. {
  22. _Instance = new IO1Provider();
  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 aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  75. if (aiList != null)
  76. {
  77. List<NotifiableIoItem> ai = (List<NotifiableIoItem>)aiList;
  78. for (int i = 0; i < ai.Count; i++)
  79. {
  80. if (ai[i].Provider != Provider)
  81. continue;
  82. short value = 0;
  83. if (value is T)
  84. {
  85. da[ai[i].Name] = (T)(object)ai[i].ShortValue;
  86. }
  87. }
  88. }
  89. }
  90. if (type == "PLC1.AOList")
  91. {
  92. var aoList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");
  93. if (aoList != null)
  94. {
  95. List<NotifiableIoItem> item = (List<NotifiableIoItem>)aoList;
  96. for (int i = 0; i < item.Count; i++)
  97. {
  98. if (item[i].Provider != Provider)
  99. continue;
  100. short value = 0;
  101. if (value is T)
  102. {
  103. da[item[i].Name] = (T)(object)item[i].ShortValue;
  104. }
  105. }
  106. }
  107. }
  108. return da;
  109. }
  110. public ObservableCollection<IOItem<T>> InitIOData<T>(string type)
  111. {
  112. //get the whole information
  113. ObservableCollection<IOItem<T>> da = new ObservableCollection<IOItem<T>>();
  114. if (type == "PLC1.DIList")
  115. {
  116. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DIList");
  117. if (diList != null)
  118. {
  119. List<NotifiableIoItem> di = (List<NotifiableIoItem>) diList;
  120. for (int i = 0; i < di.Count; i++)
  121. {
  122. if (di[i].Provider != Provider)
  123. continue;
  124. bool value = true;
  125. if (value is T)
  126. {
  127. da.Add(new IOItem<T>()
  128. {
  129. Index = di[i].Index,
  130. Name = di[i].Name,
  131. Value = (T) (object)di[i].BoolValue,
  132. Address = di[i].Address
  133. });
  134. }
  135. }
  136. }
  137. }
  138. if (type == "PLC1.DOList")
  139. {
  140. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.DOList");
  141. if (diList != null)
  142. {
  143. List<NotifiableIoItem> item = (List<NotifiableIoItem>)diList;
  144. for (int i = 0; i < item.Count; i++)
  145. {
  146. if (item[i].Provider != Provider)
  147. continue;
  148. bool value = true;
  149. if (value is T)
  150. {
  151. da.Add(new IOItem<T>()
  152. {
  153. Index = item[i].Index,
  154. Name = item[i].Name,
  155. Value = (T)(object)item[i].BoolValue,
  156. Address = item[i].Address
  157. });
  158. }
  159. }
  160. }
  161. }
  162. if (type == "PLC1.AIList")
  163. {
  164. var aiList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  165. if (aiList != null)
  166. {
  167. List<NotifiableIoItem> ai = (List<NotifiableIoItem>)aiList;
  168. for (int i = 0; i < ai.Count; i++)
  169. {
  170. if (ai[i].Provider != Provider)
  171. continue;
  172. short value = 0;
  173. if (value is T)
  174. {
  175. da.Add(new IOItem<T>()
  176. {
  177. Index = ai[i].Index,
  178. Name = ai[i].Name,
  179. Value = (T)(object)ai[i].ShortValue,
  180. Address = ai[i].Address
  181. });
  182. }
  183. }
  184. }
  185. }
  186. return da;
  187. }
  188. public ObservableCollection<AOItem> InitIOData(string type)
  189. {
  190. //get the whole information
  191. ObservableCollection<AOItem> da = new ObservableCollection<AOItem>();
  192. if (type == "PLC1.AOList")
  193. {
  194. var aoList = QueryDataClient.Instance.Service.GetData($"{Provider}.AOList");
  195. if (aoList != null)
  196. {
  197. List<NotifiableIoItem> item = (List<NotifiableIoItem>)aoList;
  198. for (int i = 0; i < item.Count; i++)
  199. {
  200. if (item[i].Provider != Provider)
  201. continue;
  202. da.Add(new AOItem
  203. {
  204. Index = item[i].Index,
  205. Name = item[i].Name,
  206. Value = item[i].ShortValue,
  207. Address = item[i].Address
  208. });
  209. }
  210. }
  211. }
  212. return da;
  213. }
  214. public void SetAO(string name, float value)
  215. {
  216. }
  217. public void SetDO(string name, bool value)
  218. {
  219. }
  220. }
  221. }