SimulatorPlcService.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 SimulatorPlcService : IWcfPlcService
  31. {
  32. public ModuleName Module { get; set; }
  33. public string Name { get; set; } = "PM1";
  34. //diVariable="" doVariable="" aiVariable="" aoVariable=""
  35. public bool CheckIsConnected()
  36. {
  37. return true;
  38. }
  39. public bool Read(string variable, out object data, string type, int length, out string reason)
  40. {
  41. reason = string.Empty;
  42. data = null;
  43. return true;
  44. }
  45. public bool WriteArrayElement(string variable, int index, object value, out string reason)
  46. {
  47. reason = string.Empty;
  48. return true;
  49. }
  50. public bool[] ReadDi(int offset, int size, out string reason)
  51. {
  52. bool[] result = IoManager.Instance.GetDiBuffer($"{Module}.{Name}")[0];
  53. reason = string.Empty;
  54. return result;
  55. }
  56. public float[] ReadAiFloat(int offset, int size, out string reason)
  57. {
  58. float[] result = IoManager.Instance.GetAiBufferFloat($"{Module}.{Name}")[0];
  59. reason = string.Empty;
  60. return result;
  61. }
  62. public int[] ReadAiInt(int offset, int size, out string reason)
  63. {
  64. reason = string.Empty;
  65. return null;
  66. }
  67. public short[] ReadAiInt16(int offset, int size, out string reason)
  68. {
  69. short[] result = IoManager.Instance.GetAiBuffer($"{Module}.{Name}")[0];
  70. reason = string.Empty;
  71. return result;
  72. }
  73. public bool WriteDo(int offset, bool[] buffer, out string reason)
  74. {
  75. reason = string.Empty;
  76. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetDoBuffer($"{Module}.{Name}")[0].Length; i++)
  77. {
  78. IoManager.Instance.GetDoBuffer($"{Module}.{Name}")[0][i] = buffer[i];
  79. }
  80. return true;
  81. }
  82. public bool WriteAoFloat(int offset, float[] buffer, out string reason)
  83. {
  84. reason = string.Empty;
  85. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetAoBufferFloat($"{Module}.{Name}")[0].Length; i++)
  86. {
  87. IoManager.Instance.GetAoBufferFloat($"{Module}.{Name}")[0][i] = buffer[i];
  88. }
  89. return true;
  90. }
  91. public bool WriteAoInt(int offset, int[] buffer, out string reason)
  92. {
  93. reason = string.Empty;
  94. return true;
  95. }
  96. public bool WriteAoInt16(int offset, short[] buffer, out string reason)
  97. {
  98. reason = string.Empty;
  99. for (int i = 0; i < buffer.Length && i < IoManager.Instance.GetAoBuffer($"{Module}.{Name}")[0].Length; i++)
  100. {
  101. IoManager.Instance.GetAoBuffer($"{Module}.{Name}")[0][i] = buffer[i];
  102. }
  103. return true;
  104. }
  105. public int Heartbeat(int counter)
  106. {
  107. return counter;
  108. }
  109. }
  110. }