PLCData.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Aitex.Core.RT.IOCore;
  4. using Aitex.Core.RT.PLC;
  5. namespace Aitex.Triton160.RT.PLC
  6. {
  7. public class CPLCBuffer : IDataBuffer<PLC_INPUT_DATA, PLC_OUTPUT_DATA>
  8. {
  9. private PLC_INPUT_DATA input;
  10. private PLC_OUTPUT_DATA output;
  11. public PLC_INPUT_DATA Input
  12. {
  13. get
  14. {
  15. return input;
  16. }
  17. set
  18. {
  19. input = value;
  20. }
  21. }
  22. public PLC_OUTPUT_DATA Output
  23. {
  24. get
  25. {
  26. return output;
  27. }
  28. set
  29. {
  30. output = value;
  31. }
  32. }
  33. public void UpdateDI(bool[] values)
  34. {
  35. for (int i = 0; i < input.DI.Length && i < values.Length; i++)
  36. {
  37. values[i] = input.DI[i] != 0 ? true : false;;
  38. }
  39. }
  40. public void UpdateAI(float[] values)
  41. {
  42. for (int i = 0; i < input.AI.Length && i < values.Length; i++)
  43. {
  44. values[i] = input.AI[i];
  45. }
  46. }
  47. public void UpdateDO(bool[] values)
  48. {
  49. for (int i = 0; i < output.DO.Length && i < values.Length; i++)
  50. {
  51. output.DO[i] = values[i] ? (byte)1 : (byte)0;
  52. //System.Diagnostics.Debug.Assert(!values[i]);
  53. }
  54. }
  55. public void UpdateAO(float[] values)
  56. {
  57. for (int i = 0; i < output.AO.Length && i < values.Length; i++)
  58. {
  59. output.AO[i] = values[i];
  60. }
  61. }
  62. public CPLCBuffer()
  63. {
  64. input = new PLC_INPUT_DATA();
  65. input.DI = new Byte[IOGroupManager.DioBlockLength];
  66. input.AI = new float[IOGroupManager.AioBlockLength];
  67. output = new PLC_OUTPUT_DATA();
  68. output.DO = new Byte[IOGroupManager.DioBlockLength];
  69. output.AO = new float[IOGroupManager.AioBlockLength];
  70. }
  71. }
  72. }