PlcPoint.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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_Start;
  27. public float X_Position_Start
  28. {
  29. get { return _X_Position_Start; }
  30. set { SetProperty(ref _X_Position_Start, value); }
  31. }
  32. private float _X_Velocity_Start;
  33. public float X_Velocity_Start
  34. {
  35. get { return _X_Velocity_Start; }
  36. set { SetProperty(ref _X_Velocity_Start, value); }
  37. }
  38. private float _X_Position_Stop;
  39. public float X_Position_Stop
  40. {
  41. get { return _X_Position_Stop; }
  42. set { SetProperty(ref _X_Position_Stop, value); }
  43. }
  44. private float _X_Velocity_Stop;
  45. public float X_Velocity_Stop
  46. {
  47. get { return _X_Velocity_Stop; }
  48. set { SetProperty(ref _X_Velocity_Stop, value); }
  49. }
  50. private float _Y_Position_Start;
  51. public float Y_Position_Start
  52. {
  53. get { return _Y_Position_Start; }
  54. set { SetProperty(ref _Y_Position_Start, value); }
  55. }
  56. private float _Y_Velocity_Start;
  57. public float Y_Velocity_Start
  58. {
  59. get { return _Y_Velocity_Start; }
  60. set { SetProperty(ref _Y_Velocity_Start, value); }
  61. }
  62. private float _Y_Position_Stop;
  63. public float Y_Position_Stop
  64. {
  65. get { return _Y_Position_Stop; }
  66. set { SetProperty(ref _Y_Position_Stop, value); }
  67. }
  68. private float _Y_Velocity_Stop;
  69. public float Y_Velocity_Stop
  70. {
  71. get { return _Y_Velocity_Stop; }
  72. set { SetProperty(ref _Y_Velocity_Stop, value); }
  73. }
  74. private float _Z_Position_Start;
  75. public float Z_Position_Start
  76. {
  77. get { return _Z_Position_Start; }
  78. set { SetProperty(ref _Z_Position_Start, value); }
  79. }
  80. private float _Z_Velocity_Start;
  81. public float Z_Velocity_Start
  82. {
  83. get { return _Z_Velocity_Start; }
  84. set { SetProperty(ref _Z_Velocity_Start, value); }
  85. }
  86. private float _Z_Position_Stop;
  87. public float Z_Position_Stop
  88. {
  89. get { return _Z_Position_Stop; }
  90. set { SetProperty(ref _Z_Position_Stop, value); }
  91. }
  92. private float _Z_Velocity_Stop;
  93. public float Z_Velocity_Stop
  94. {
  95. get { return _Z_Velocity_Stop; }
  96. set { SetProperty(ref _Z_Velocity_Stop, value); }
  97. }
  98. private float _U_Position_Start;
  99. public float U_Position_Start
  100. {
  101. get { return _U_Position_Start; }
  102. set { SetProperty(ref _U_Position_Start, value); }
  103. }
  104. private float _U_Velocity_Start;
  105. public float U_Velocity_Start
  106. {
  107. get { return _U_Velocity_Start; }
  108. set { SetProperty(ref _U_Velocity_Start, value); }
  109. }
  110. private float _U_Position_Stop;
  111. public float U_Position_Stop
  112. {
  113. get { return _U_Position_Stop; }
  114. set { SetProperty(ref _U_Position_Stop, value); }
  115. }
  116. private float _U_Velocity_Stop;
  117. public float U_Velocity_Stop
  118. {
  119. get { return _U_Velocity_Stop; }
  120. set { SetProperty(ref _U_Velocity_Stop, value); }
  121. }
  122. private Int16 _Enable_Start_Node;
  123. public Int16 Enable_Start_Node
  124. {
  125. get { return _Enable_Start_Node; }
  126. set { SetProperty(ref _Enable_Start_Node, value); }
  127. }
  128. private Int16 _Enable_Pulse;
  129. public Int16 Enable_Pulse
  130. {
  131. get { return _Enable_Pulse; }
  132. set { SetProperty(ref _Enable_Pulse, value); }
  133. }
  134. private Int16 _Enable_3D;
  135. public Int16 Enable_3D
  136. {
  137. get { return _Enable_3D; }
  138. set { SetProperty(ref _Enable_3D, value); }
  139. }
  140. private Int16 _Enable_Wait_Finish;
  141. public Int16 Enable_Wait_Finish
  142. {
  143. get { return _Enable_Wait_Finish; }
  144. set { SetProperty(ref _Enable_Wait_Finish, value); }
  145. }
  146. private Int16 _Enable_Light1;
  147. public Int16 Enable_Light1
  148. {
  149. get { return _Enable_Light1; }
  150. set { SetProperty(ref _Enable_Light1, value); }
  151. }
  152. private Int16 _Enable_Light2;
  153. public Int16 Enable_Light2
  154. {
  155. get { return _Enable_Light2; }
  156. set { SetProperty(ref _Enable_Light2, value); }
  157. }
  158. private Int16 _Enable_Light3;
  159. public Int16 Enable_Light3
  160. {
  161. get { return _Enable_Light3; }
  162. set { SetProperty(ref _Enable_Light3, value); }
  163. }
  164. private Int16 _Enable_Light4;
  165. public Int16 Enable_Light4
  166. {
  167. get { return _Enable_Light4; }
  168. set { SetProperty(ref _Enable_Light4, value); }
  169. }
  170. private float _R_Position;
  171. public float R_Position
  172. {
  173. get { return _R_Position; }
  174. set { SetProperty(ref _R_Position, value); }
  175. }
  176. private float _R_Velocity;
  177. public float R_Velocity
  178. {
  179. get { return _R_Velocity; }
  180. set { SetProperty(ref _R_Velocity, value); }
  181. }
  182. private float _Torque;
  183. public float Torque
  184. {
  185. get { return _Torque; }
  186. set { SetProperty(ref _Torque, value); }
  187. }
  188. private Int16 _Feeder;
  189. public Int16 Feeder
  190. {
  191. get { return _Feeder; }
  192. set { SetProperty(ref _Feeder, value); }
  193. }
  194. private Int16 _ScrewProNum;
  195. public Int16 ScrewProNum
  196. {
  197. get { return _ScrewProNum; }
  198. set { SetProperty(ref _ScrewProNum, value); }
  199. }
  200. //描述
  201. private string _Description;
  202. public string Description
  203. {
  204. get { return _Description; }
  205. set { SetProperty(ref _Description, value); }
  206. }
  207. public PlcPoint()
  208. {
  209. Number = 0;
  210. X_Position_Start = 0;
  211. X_Velocity_Start = 0;
  212. X_Position_Stop = 0;
  213. X_Velocity_Stop = 0;
  214. Y_Position_Start = 0;
  215. Y_Velocity_Start = 0;
  216. Y_Position_Stop = 0;
  217. Y_Velocity_Stop = 0;
  218. Z_Position_Start = 0;
  219. Z_Velocity_Start = 0;
  220. Z_Position_Stop = 0;
  221. Z_Velocity_Stop = 0;
  222. U_Position_Start = 0;
  223. U_Velocity_Start = 0;
  224. U_Position_Stop = 0;
  225. U_Velocity_Stop = 0;
  226. Enable_Start_Node = 0;
  227. Enable_Pulse = 0;
  228. Enable_3D = 0;
  229. Enable_Wait_Finish = 0;
  230. Enable_Light1 = 0;
  231. Enable_Light2 = 0;
  232. Enable_Light3 = 0;
  233. Enable_Light4 = 0;
  234. //R_Position = 0;
  235. //R_Velocity = 0;
  236. //Torque = 0;
  237. //Feeder = 0;
  238. //ScrewProNum = 0;
  239. }
  240. public PlcPoint Clone()
  241. {
  242. return new PlcPoint
  243. {
  244. Number = this.Number,
  245. Label = this.Label,
  246. X_Position_Start = this.X_Position_Start,
  247. X_Velocity_Start= this.X_Velocity_Start,
  248. X_Position_Stop = this.X_Position_Stop,
  249. X_Velocity_Stop = this.X_Velocity_Stop,
  250. Y_Position_Start = this.Y_Position_Start,
  251. Y_Velocity_Start = this.Y_Velocity_Start,
  252. Y_Position_Stop = this.Y_Position_Stop,
  253. Y_Velocity_Stop = this.Y_Velocity_Stop,
  254. Z_Position_Start = this.Z_Position_Start,
  255. Z_Velocity_Start = this.Z_Velocity_Start,
  256. Z_Position_Stop = this.Z_Position_Stop,
  257. Z_Velocity_Stop = this.Z_Velocity_Stop,
  258. U_Position_Start = this.U_Position_Start,
  259. U_Velocity_Start = this.U_Velocity_Start,
  260. U_Position_Stop = this.U_Position_Stop,
  261. U_Velocity_Stop = this.U_Velocity_Stop,
  262. Enable_Start_Node = this.Enable_Start_Node,
  263. Enable_Pulse = this.Enable_Pulse,
  264. Enable_3D = this.Enable_3D,
  265. Enable_Wait_Finish = this.Enable_Wait_Finish,
  266. Enable_Light1 = this.Enable_Light1,
  267. Enable_Light2 = this.Enable_Light2,
  268. Enable_Light3 = this.Enable_Light3,
  269. Enable_Light4 = this.Enable_Light4,
  270. //R_Position = this.R_Position,
  271. //R_Velocity = this.R_Velocity,
  272. //Torque = this.Torque,
  273. //Feeder = this.Feeder,
  274. //ScrewProNum = this.ScrewProNum,
  275. //Description = this.Description
  276. };
  277. }
  278. /// <summary>
  279. /// 将点位数据写入到PLC地址
  280. /// </summary>
  281. /// <param name="plcAddress"></param>
  282. /// <param name="pLC"></param>
  283. /// <returns></returns>
  284. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  285. {
  286. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  287. nodeValues.Add(string.Format(plcAddress.X_Position_Start.Address, Number), X_Position_Start);
  288. nodeValues.Add(string.Format(plcAddress.X_Velocity_Start.Address, Number), X_Velocity_Start);
  289. nodeValues.Add(string.Format(plcAddress.X_Position_Stop.Address, Number), X_Position_Stop);
  290. nodeValues.Add(string.Format(plcAddress.X_Velocity_Stop.Address, Number), X_Velocity_Stop);
  291. nodeValues.Add(string.Format(plcAddress.Y_Position_Start.Address, Number), Y_Position_Start);
  292. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Start.Address, Number), Y_Velocity_Start);
  293. nodeValues.Add(string.Format(plcAddress.Y_Position_Stop.Address, Number), Y_Position_Stop);
  294. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Stop.Address, Number), Y_Velocity_Stop);
  295. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  296. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  297. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  298. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  299. nodeValues.Add(string.Format(plcAddress.U_Position_Start.Address, Number), U_Position_Start);
  300. nodeValues.Add(string.Format(plcAddress.U_Velocity_Start.Address, Number), U_Velocity_Start);
  301. nodeValues.Add(string.Format(plcAddress.U_Position_Stop.Address, Number), U_Position_Stop);
  302. nodeValues.Add(string.Format(plcAddress.U_Velocity_Stop.Address, Number), U_Velocity_Stop);
  303. nodeValues.Add(string.Format(plcAddress.Enable_Start_Node.Address, Number), Enable_Start_Node);
  304. nodeValues.Add(string.Format(plcAddress.Enable_Pulse.Address, Number), Enable_Pulse);
  305. nodeValues.Add(string.Format(plcAddress.Enable_3D.Address, Number), Enable_3D);
  306. nodeValues.Add(string.Format(plcAddress.Enable_Wait_Finish.Address, Number), Enable_Wait_Finish);
  307. nodeValues.Add(string.Format(plcAddress.Enable_Light1.Address, Number), Enable_Light1);
  308. nodeValues.Add(string.Format(plcAddress.Enable_Light2.Address, Number), Enable_Light2);
  309. nodeValues.Add(string.Format(plcAddress.Enable_Light3.Address, Number), Enable_Light3);
  310. nodeValues.Add(string.Format(plcAddress.Enable_Light4.Address, Number), Enable_Light4);
  311. //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  312. //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  313. //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  314. //nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  315. //nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  316. return await pLC.WriteNodesAsync(nodeValues);
  317. }
  318. }
  319. }