PlcPoint.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 Guid _CameraProcedureId = Guid.Empty;
  171. /// <summary>
  172. /// Camera 对应的视觉流程 Id
  173. /// </summary>
  174. public Guid CameraProcedureId
  175. {
  176. get { return _CameraProcedureId; }
  177. set { SetProperty(ref _CameraProcedureId, value); }
  178. }
  179. private float _R_Position;
  180. public float R_Position
  181. {
  182. get { return _R_Position; }
  183. set { SetProperty(ref _R_Position, value); }
  184. }
  185. private float _R_Velocity;
  186. public float R_Velocity
  187. {
  188. get { return _R_Velocity; }
  189. set { SetProperty(ref _R_Velocity, value); }
  190. }
  191. private float _Torque;
  192. public float Torque
  193. {
  194. get { return _Torque; }
  195. set { SetProperty(ref _Torque, value); }
  196. }
  197. private Int16 _Feeder;
  198. public Int16 Feeder
  199. {
  200. get { return _Feeder; }
  201. set { SetProperty(ref _Feeder, value); }
  202. }
  203. private Int16 _ScrewProNum;
  204. public Int16 ScrewProNum
  205. {
  206. get { return _ScrewProNum; }
  207. set { SetProperty(ref _ScrewProNum, value); }
  208. }
  209. //描述
  210. private string _Description;
  211. public string Description
  212. {
  213. get { return _Description; }
  214. set { SetProperty(ref _Description, value); }
  215. }
  216. public PlcPoint()
  217. {
  218. Number = 0;
  219. X_Position_Start = 0;
  220. X_Velocity_Start = 0;
  221. X_Position_Stop = 0;
  222. X_Velocity_Stop = 0;
  223. Y_Position_Start = 0;
  224. Y_Velocity_Start = 0;
  225. Y_Position_Stop = 0;
  226. Y_Velocity_Stop = 0;
  227. Z_Position_Start = 0;
  228. Z_Velocity_Start = 0;
  229. Z_Position_Stop = 0;
  230. Z_Velocity_Stop = 0;
  231. U_Position_Start = 0;
  232. U_Velocity_Start = 0;
  233. U_Position_Stop = 0;
  234. U_Velocity_Stop = 0;
  235. Enable_Start_Node = 0;
  236. Enable_Pulse = 0;
  237. Enable_3D = 0;
  238. Enable_Wait_Finish = 0;
  239. Enable_Light1 = 0;
  240. Enable_Light2 = 0;
  241. Enable_Light3 = 0;
  242. Enable_Light4 = 0;
  243. //R_Position = 0;
  244. //R_Velocity = 0;
  245. //Torque = 0;
  246. //Feeder = 0;
  247. //ScrewProNum = 0;
  248. }
  249. public PlcPoint Clone()
  250. {
  251. return new PlcPoint
  252. {
  253. Number = this.Number,
  254. Label = this.Label,
  255. X_Position_Start = this.X_Position_Start,
  256. X_Velocity_Start= this.X_Velocity_Start,
  257. X_Position_Stop = this.X_Position_Stop,
  258. X_Velocity_Stop = this.X_Velocity_Stop,
  259. Y_Position_Start = this.Y_Position_Start,
  260. Y_Velocity_Start = this.Y_Velocity_Start,
  261. Y_Position_Stop = this.Y_Position_Stop,
  262. Y_Velocity_Stop = this.Y_Velocity_Stop,
  263. Z_Position_Start = this.Z_Position_Start,
  264. Z_Velocity_Start = this.Z_Velocity_Start,
  265. Z_Position_Stop = this.Z_Position_Stop,
  266. Z_Velocity_Stop = this.Z_Velocity_Stop,
  267. U_Position_Start = this.U_Position_Start,
  268. U_Velocity_Start = this.U_Velocity_Start,
  269. U_Position_Stop = this.U_Position_Stop,
  270. U_Velocity_Stop = this.U_Velocity_Stop,
  271. Enable_Start_Node = this.Enable_Start_Node,
  272. Enable_Pulse = this.Enable_Pulse,
  273. Enable_3D = this.Enable_3D,
  274. Enable_Wait_Finish = this.Enable_Wait_Finish,
  275. Enable_Light1 = this.Enable_Light1,
  276. Enable_Light2 = this.Enable_Light2,
  277. Enable_Light3 = this.Enable_Light3,
  278. Enable_Light4 = this.Enable_Light4,
  279. CameraProcedureId = this.CameraProcedureId,
  280. //R_Position = this.R_Position,
  281. //R_Velocity = this.R_Velocity,
  282. //Torque = this.Torque,
  283. //Feeder = this.Feeder,
  284. //ScrewProNum = this.ScrewProNum,
  285. //Description = this.Description
  286. };
  287. }
  288. /// <summary>
  289. /// 将点位数据写入到PLC地址
  290. /// </summary>
  291. /// <param name="plcAddress"></param>
  292. /// <param name="pLC"></param>
  293. /// <returns></returns>
  294. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  295. {
  296. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  297. nodeValues.Add(string.Format(plcAddress.X_Position_Start.Address, Number), X_Position_Start);
  298. nodeValues.Add(string.Format(plcAddress.X_Velocity_Start.Address, Number), X_Velocity_Start);
  299. nodeValues.Add(string.Format(plcAddress.X_Position_Stop.Address, Number), X_Position_Stop);
  300. nodeValues.Add(string.Format(plcAddress.X_Velocity_Stop.Address, Number), X_Velocity_Stop);
  301. nodeValues.Add(string.Format(plcAddress.Y_Position_Start.Address, Number), Y_Position_Start);
  302. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Start.Address, Number), Y_Velocity_Start);
  303. nodeValues.Add(string.Format(plcAddress.Y_Position_Stop.Address, Number), Y_Position_Stop);
  304. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Stop.Address, Number), Y_Velocity_Stop);
  305. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  306. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  307. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  308. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  309. nodeValues.Add(string.Format(plcAddress.U_Position_Start.Address, Number), U_Position_Start);
  310. nodeValues.Add(string.Format(plcAddress.U_Velocity_Start.Address, Number), U_Velocity_Start);
  311. nodeValues.Add(string.Format(plcAddress.U_Position_Stop.Address, Number), U_Position_Stop);
  312. nodeValues.Add(string.Format(plcAddress.U_Velocity_Stop.Address, Number), U_Velocity_Stop);
  313. nodeValues.Add(string.Format(plcAddress.Enable_Start_Node.Address, Number), Enable_Start_Node);
  314. nodeValues.Add(string.Format(plcAddress.Enable_Pulse.Address, Number), Enable_Pulse);
  315. nodeValues.Add(string.Format(plcAddress.Enable_3D.Address, Number), Enable_3D);
  316. nodeValues.Add(string.Format(plcAddress.Enable_Wait_Finish.Address, Number), Enable_Wait_Finish);
  317. nodeValues.Add(string.Format(plcAddress.Enable_Light1.Address, Number), Enable_Light1);
  318. nodeValues.Add(string.Format(plcAddress.Enable_Light2.Address, Number), Enable_Light2);
  319. nodeValues.Add(string.Format(plcAddress.Enable_Light3.Address, Number), Enable_Light3);
  320. nodeValues.Add(string.Format(plcAddress.Enable_Light4.Address, Number), Enable_Light4);
  321. //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  322. //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  323. //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  324. //nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  325. //nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  326. return await pLC.WriteNodesAsync(nodeValues);
  327. }
  328. }
  329. }