IO3Provider.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 IO3Provider : IProvider
  14. {
  15. private static IO3Provider _Instance = null;
  16. public static IO3Provider Instance
  17. {
  18. get
  19. {
  20. if (_Instance == null)
  21. {
  22. _Instance = new IO3Provider();
  23. _Instance.Create();
  24. }
  25. return _Instance;
  26. }
  27. }
  28. private const string Provider = "System.io3";
  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.AIList")
  37. {
  38. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  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].ShortValue;
  50. }
  51. }
  52. }
  53. }
  54. return da;
  55. }
  56. public ObservableCollection<IOItem<T>> InitIOData<T>(string type)
  57. {
  58. //get the whole informations
  59. ObservableCollection<IOItem<T>> da = new ObservableCollection<IOItem<T>>();
  60. if (type == "PLC1.AIList")
  61. {
  62. var diList = QueryDataClient.Instance.Service.GetData($"{Provider}.AIList");
  63. if (diList != null)
  64. {
  65. List<NotifiableIoItem> di = (List<NotifiableIoItem>)diList;
  66. for (int i = 0; i < di.Count; i++)
  67. {
  68. if (di[i].Provider != Provider)
  69. continue;
  70. //bool value = true;
  71. //if (value is T)
  72. {
  73. da.Add(new IOItem<T>()
  74. {
  75. Index = di[i].Index,
  76. Name = di[i].Name,
  77. Value = (T)(object)di[i].ShortValue,
  78. Address = di[i].Address
  79. });
  80. }
  81. }
  82. }
  83. }
  84. return da;
  85. }
  86. public ObservableCollection<AOItem> InitIOData(string type)
  87. {
  88. //get the whole informations
  89. ObservableCollection<AOItem> da = new ObservableCollection<AOItem>();
  90. return da;
  91. }
  92. public void SetAO(string name, float value)
  93. {
  94. }
  95. public void SetDO(string name, bool value)
  96. {
  97. }
  98. }
  99. }