SimulatorPlcService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using Aitex.Core.RT.IOCore;
  2. using MECF.Framework.Common.Equipment;
  3. using MECF.Framework.Common.IOCore;
  4. using MECF.Framework.Common.PLC;
  5. using MECF.Framework.RT.Core.IoProviders;
  6. using MECF.Framework.Simulator.Core.IoProviders;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace FurnaceSimulator.Instances
  14. {
  15. public class SimulatorPlc1 : SimulatorPlcService, IWcfPlcService
  16. {
  17. public SimulatorPlc1()
  18. {
  19. Module = ModuleName.System;
  20. }
  21. }
  22. public class SimulatorPlc2 : SimulatorPlcService, IWcfPlcService
  23. {
  24. public SimulatorPlc2()
  25. {
  26. Module = ModuleName.System;
  27. Name = "Heater";
  28. }
  29. }
  30. public class SimulatorPlc3 : SimulatorPlcService, IWcfPlcService
  31. {
  32. public SimulatorPlc3()
  33. {
  34. Module = ModuleName.System;
  35. Name = "GasLine1";
  36. }
  37. }
  38. public class SimulatorPlc4 : SimulatorPlcService, IWcfPlcService
  39. {
  40. public SimulatorPlc4()
  41. {
  42. Module = ModuleName.System;
  43. Name = "GasLine2";
  44. }
  45. }
  46. public class SimulatorPlc5 : SimulatorPlcService, IWcfPlcService
  47. {
  48. public SimulatorPlc5()
  49. {
  50. Module = ModuleName.System;
  51. Name = "GasLine3";
  52. }
  53. }
  54. public class SimulatorPlc6 : SimulatorPlcService, IWcfPlcService
  55. {
  56. public SimulatorPlc6()
  57. {
  58. Module = ModuleName.System;
  59. Name = "GasLine4";
  60. }
  61. }
  62. public class SimulatorPlc7 : SimulatorPlcService, IWcfPlcService
  63. {
  64. public SimulatorPlc7()
  65. {
  66. Module = ModuleName.System;
  67. Name = "GasLine6";
  68. }
  69. }
  70. public class SimulatorPlc8 : SimulatorPlcService, IWcfPlcService
  71. {
  72. public SimulatorPlc8()
  73. {
  74. Module = ModuleName.System;
  75. Name = "GasLine7";
  76. }
  77. }
  78. public class SimulatorPlc9 : SimulatorPlcService, IWcfPlcService
  79. {
  80. public SimulatorPlc9()
  81. {
  82. Module = ModuleName.System;
  83. Name = "GasLine8";
  84. }
  85. }
  86. public class SimulatorPlcService : IWcfPlcService
  87. {
  88. public ModuleName Module { get; set; }
  89. public string Name { get; set; } = "PM1";
  90. //diVariable="" doVariable="" aiVariable="" aoVariable=""
  91. public bool CheckIsConnected()
  92. {
  93. return true;
  94. }
  95. public bool Read(string variable, out object data, string type, int length, out string reason)
  96. {
  97. reason = string.Empty;
  98. data = null;
  99. return true;
  100. }
  101. public bool WriteArrayElement(string variable, int index, object value, out string reason)
  102. {
  103. reason = string.Empty;
  104. return true;
  105. }
  106. public bool[] ReadDi(int offset, int size, out string reason)
  107. {
  108. bool[] result = IoManager.Instance.GetDiBuffer($"{Module}.{Name}")[0];
  109. reason = string.Empty;
  110. return result;
  111. }
  112. public float[] ReadAiFloat(int offset, int size, out string reason)
  113. {
  114. float[] result = IoManager.Instance.GetAiBufferFloat($"{Module}.{Name}")[0];
  115. reason = string.Empty;
  116. return result;
  117. }
  118. public int[] ReadAiInt(int offset, int size, out string reason)
  119. {
  120. reason = string.Empty;
  121. return null;
  122. }
  123. public short[] ReadAiInt16(int offset, int size, out string reason)
  124. {
  125. short[] result = IoManager.Instance.GetAiBuffer($"{Module}.{Name}")[0];
  126. reason = string.Empty;
  127. return result;
  128. }
  129. public bool WriteDo(int offset, bool[] buffer, out string reason)
  130. {
  131. reason = string.Empty;
  132. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetDoBuffer($"{Module}.{Name}")[0].Length; i++)
  133. {
  134. IoManager.Instance.GetDoBuffer($"{Module}.{Name}")[0][i] = buffer[i];
  135. }
  136. return true;
  137. }
  138. public bool WriteAoFloat(int offset, float[] buffer, out string reason)
  139. {
  140. reason = string.Empty;
  141. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetAoBufferFloat($"{Module}.{Name}")[0].Length; i++)
  142. {
  143. IoManager.Instance.GetAoBufferFloat($"{Module}.{Name}")[0][i] = buffer[i];
  144. }
  145. return true;
  146. }
  147. public bool WriteAoInt(int offset, int[] buffer, out string reason)
  148. {
  149. reason = string.Empty;
  150. return true;
  151. }
  152. public bool WriteAoInt16(int offset, short[] buffer, out string reason)
  153. {
  154. reason = string.Empty;
  155. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetAoBuffer($"{Module}.{Name}")[0].Length; i++)
  156. {
  157. IoManager.Instance.GetAoBuffer($"{Module}.{Name}")[0][i] = buffer[i];
  158. }
  159. return true;
  160. }
  161. public int Heartbeat(int counter)
  162. {
  163. return counter;
  164. }
  165. }
  166. }