PlcPoint.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using Prism.Mvvm;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using TeamAAS_VP.Core.PLCs;
  9. using TeamAAS_VP.Interfaces;
  10. namespace TeamAAS_VP.Models.PLC
  11. {
  12. public class PlcPoint : BindableBase
  13. {
  14. private int _Number;
  15. public int Number
  16. {
  17. get { return _Number; }
  18. set { SetProperty(ref _Number, value); }
  19. }
  20. private string _Label;
  21. public string Label
  22. {
  23. get { return _Label; }
  24. set { SetProperty(ref _Label, value); }
  25. }
  26. private float _X_Position;
  27. public float X_Position
  28. {
  29. get { return _X_Position; }
  30. set { SetProperty(ref _X_Position, value); }
  31. }
  32. private float _X_Velocity;
  33. public float X_Velocity
  34. {
  35. get { return _X_Velocity; }
  36. set { SetProperty(ref _X_Velocity, value); }
  37. }
  38. private float _Y_Position;
  39. public float Y_Position
  40. {
  41. get { return _Y_Position; }
  42. set { SetProperty(ref _Y_Position, value); }
  43. }
  44. private float _Y_Velocity;
  45. public float Y_Velocity
  46. {
  47. get { return _Y_Velocity; }
  48. set { SetProperty(ref _Y_Velocity, value); }
  49. }
  50. private float _Z_Position_Start;
  51. public float Z_Position_Start
  52. {
  53. get { return _Z_Position_Start; }
  54. set { SetProperty(ref _Z_Position_Start, value); }
  55. }
  56. private float _Z_Velocity_Start;
  57. public float Z_Velocity_Start
  58. {
  59. get { return _Z_Velocity_Start; }
  60. set { SetProperty(ref _Z_Velocity_Start, value); }
  61. }
  62. private float _Z_Position_Stop;
  63. public float Z_Position_Stop
  64. {
  65. get { return _Z_Position_Stop; }
  66. set { SetProperty(ref _Z_Position_Stop, value); }
  67. }
  68. private float _Z_Velocity_Stop;
  69. public float Z_Velocity_Stop
  70. {
  71. get { return _Z_Velocity_Stop; }
  72. set { SetProperty(ref _Z_Velocity_Stop, value); }
  73. }
  74. private float _U_Position;
  75. public float U_Position
  76. {
  77. get { return _U_Position; }
  78. set { SetProperty(ref _U_Position, value); }
  79. }
  80. private float _U_Velocity;
  81. public float U_Velocity
  82. {
  83. get { return _U_Velocity; }
  84. set { SetProperty(ref _U_Velocity, value); }
  85. }
  86. private float _R_Position;
  87. public float R_Position
  88. {
  89. get { return _R_Position; }
  90. set { SetProperty(ref _R_Position, value); }
  91. }
  92. private float _R_Velocity;
  93. public float R_Velocity
  94. {
  95. get { return _R_Velocity; }
  96. set { SetProperty(ref _R_Velocity, value); }
  97. }
  98. private float _Torque;
  99. public float Torque
  100. {
  101. get { return _Torque; }
  102. set { SetProperty(ref _Torque, value); }
  103. }
  104. private Int16 _Feeder;
  105. public Int16 Feeder
  106. {
  107. get { return _Feeder; }
  108. set { SetProperty(ref _Feeder, value); }
  109. }
  110. private Int16 _ScrewProNum;
  111. public Int16 ScrewProNum
  112. {
  113. get { return _ScrewProNum; }
  114. set { SetProperty(ref _ScrewProNum, value); }
  115. }
  116. //描述
  117. private string _Description;
  118. public string Description
  119. {
  120. get { return _Description; }
  121. set { SetProperty(ref _Description, value); }
  122. }
  123. public PlcPoint()
  124. {
  125. Number = 0;
  126. X_Position = 0;
  127. X_Velocity = 0;
  128. Y_Position = 0;
  129. Y_Velocity = 0;
  130. Z_Position_Start = 0;
  131. Z_Velocity_Start = 0;
  132. Z_Position_Stop = 0;
  133. Z_Velocity_Stop = 0;
  134. U_Position = 0;
  135. U_Velocity = 0;
  136. R_Position = 0;
  137. R_Velocity = 0;
  138. Torque = 0;
  139. Feeder = 0;
  140. ScrewProNum = 0;
  141. }
  142. public PlcPoint Clone()
  143. {
  144. return new PlcPoint
  145. {
  146. Number = this.Number,
  147. Label = this.Label,
  148. X_Position = this.X_Position,
  149. X_Velocity = this.X_Velocity,
  150. Y_Position = this.Y_Position,
  151. Y_Velocity = this.Y_Velocity,
  152. Z_Position_Start = this.Z_Position_Start,
  153. Z_Velocity_Start = this.Z_Velocity_Start,
  154. Z_Position_Stop = this.Z_Position_Stop,
  155. Z_Velocity_Stop = this.Z_Velocity_Stop,
  156. U_Position = this.U_Position,
  157. U_Velocity = this.U_Velocity,
  158. R_Position = this.R_Position,
  159. R_Velocity = this.R_Velocity,
  160. Torque = this.Torque,
  161. Feeder = this.Feeder,
  162. ScrewProNum = this.ScrewProNum,
  163. Description = this.Description
  164. };
  165. }
  166. /// <summary>
  167. /// 将点位数据写入到PLC地址
  168. /// </summary>
  169. /// <param name="plcAddress"></param>
  170. /// <param name="pLC"></param>
  171. /// <returns></returns>
  172. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  173. {
  174. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  175. nodeValues.Add(string.Format(plcAddress.X_Position.Address, Number), X_Position);
  176. nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, Number), X_Velocity);
  177. nodeValues.Add(string.Format(plcAddress.Y_Position.Address, Number), Y_Position);
  178. nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, Number), Y_Velocity);
  179. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  180. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  181. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  182. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  183. nodeValues.Add(string.Format(plcAddress.U_Position.Address, Number), U_Position);
  184. nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, Number), U_Velocity);
  185. nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  186. nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  187. nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  188. nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  189. nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  190. return await pLC.WriteNodesAsync(nodeValues);
  191. }
  192. /// <summary>
  193. /// 将点位数据写入到PLC地址
  194. /// </summary>
  195. /// <param name="plcAddress"></param>
  196. /// <param name="pLC"></param>
  197. /// <returns></returns>
  198. public async Task<bool> WriteToPlcAddressEx(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  199. {
  200. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  201. //nodeValues.Add(string.Format(plcAddress.X_Position.Address, Number), X_Position);
  202. //nodeValues.Add(string.Format(plcAddress.X_Velocity.Address, Number), X_Velocity);
  203. //nodeValues.Add(string.Format(plcAddress.Y_Position.Address, Number), Y_Position);
  204. //nodeValues.Add(string.Format(plcAddress.Y_Velocity.Address, Number), Y_Velocity);
  205. //nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  206. //nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  207. //nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  208. //nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  209. //nodeValues.Add(string.Format(plcAddress.U_Position.Address, Number), U_Position);
  210. //nodeValues.Add(string.Format(plcAddress.U_Velocity.Address, Number), U_Velocity);
  211. //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  212. //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  213. //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  214. nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  215. nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  216. return await pLC.WriteNodesAsync(nodeValues);
  217. }
  218. }
  219. }