PlcPoint.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using TeamAAS_VP.Core.PLCs;
  8. using TeamAAS_VP.Interfaces;
  9. namespace TeamAAS_VP.Models.PLC
  10. {
  11. public class PlcPoint
  12. {
  13. public int Number { get; set; }
  14. public float X_Position { get; set; }
  15. public float X_Velocity { get; set; }
  16. public float Y_Position { get; set; }
  17. public float Y_Velocity { get; set; }
  18. public float Z_Position_Start { get; set; }
  19. public float Z_Velocity_Start { get; set; }
  20. public float Z_Position_Stop { get; set; }
  21. public float Z_Velocity_Stop { get; set; }
  22. public float U_Position { get; set; }
  23. public float U_Velocity { get; set; }
  24. public float R_Position { get; set; }
  25. public float R_Velocity { get; set; }
  26. public float Torque { get; set; }
  27. public Int16 Feeder { get; set; }
  28. public Int16 ScrewProNum { get; set; }
  29. public PlcPoint()
  30. {
  31. Number = 0;
  32. X_Position = 0;
  33. X_Velocity = 0;
  34. Y_Position = 0;
  35. Y_Velocity = 0;
  36. Z_Position_Start = 0;
  37. Z_Velocity_Start = 0;
  38. Z_Position_Stop = 0;
  39. Z_Velocity_Stop = 0;
  40. U_Position = 0;
  41. U_Velocity = 0;
  42. R_Position = 0;
  43. R_Velocity = 0;
  44. Torque = 0;
  45. Feeder = 0;
  46. ScrewProNum = 0;
  47. }
  48. public PlcPoint Clone()
  49. {
  50. return new PlcPoint
  51. {
  52. Number = this.Number,
  53. X_Position = this.X_Position,
  54. X_Velocity = this.X_Velocity,
  55. Y_Position = this.Y_Position,
  56. Y_Velocity = this.Y_Velocity,
  57. Z_Position_Start = this.Z_Position_Start,
  58. Z_Velocity_Start = this.Z_Velocity_Start,
  59. Z_Position_Stop = this.Z_Position_Stop,
  60. Z_Velocity_Stop = this.Z_Velocity_Stop,
  61. U_Position = this.U_Position,
  62. U_Velocity = this.U_Velocity,
  63. R_Position = this.R_Position,
  64. R_Velocity = this.R_Velocity,
  65. Torque = this.Torque,
  66. Feeder = this.Feeder,
  67. ScrewProNum = this.ScrewProNum
  68. };
  69. }
  70. /// <summary>
  71. /// 将点位数据写入到PLC地址
  72. /// </summary>
  73. /// <param name="plcAddress"></param>
  74. /// <param name="pLC"></param>
  75. /// <returns></returns>
  76. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  77. {
  78. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  79. nodeValues.Add(string.Format(plcAddress.X_Position.Address, Number), X_Position);
  80. nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, Number), X_Velocity);
  81. nodeValues.Add(string.Format(plcAddress.Y_Position.Address, Number), Y_Position);
  82. nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, Number), Y_Velocity);
  83. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  84. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  85. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  86. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  87. nodeValues.Add(string.Format(plcAddress.U_Position.Address, Number), U_Position);
  88. nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, Number), U_Velocity);
  89. nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  90. nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  91. nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  92. nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  93. nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  94. return await pLC.WriteNodesAsync(nodeValues);
  95. }
  96. }
  97. }