PlcPoint.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. using TeamAAS_VP.Services;
  11. namespace TeamAAS_VP.Models.PLC
  12. {
  13. public class PlcPoint : BindableBase
  14. {
  15. private int _Number;
  16. public int Number
  17. {
  18. get { return _Number; }
  19. set { SetProperty(ref _Number, value); }
  20. }
  21. private string _Label;
  22. public string Label
  23. {
  24. get { return _Label; }
  25. set { SetProperty(ref _Label, value); }
  26. }
  27. private float _X_Position_Start;
  28. public float X_Position_Start
  29. {
  30. get { return _X_Position_Start; }
  31. set { SetProperty(ref _X_Position_Start, value); }
  32. }
  33. private float _X_Velocity_Start;
  34. public float X_Velocity_Start
  35. {
  36. get { return _X_Velocity_Start; }
  37. set { SetProperty(ref _X_Velocity_Start, value); }
  38. }
  39. private float _X_Position_Stop;
  40. public float X_Position_Stop
  41. {
  42. get { return _X_Position_Stop; }
  43. set { SetProperty(ref _X_Position_Stop, value); }
  44. }
  45. private float _X_Velocity_Stop;
  46. public float X_Velocity_Stop
  47. {
  48. get { return _X_Velocity_Stop; }
  49. set { SetProperty(ref _X_Velocity_Stop, value); }
  50. }
  51. private float _Y_Position_Start;
  52. public float Y_Position_Start
  53. {
  54. get { return _Y_Position_Start; }
  55. set { SetProperty(ref _Y_Position_Start, value); }
  56. }
  57. private float _Y_Velocity_Start;
  58. public float Y_Velocity_Start
  59. {
  60. get { return _Y_Velocity_Start; }
  61. set { SetProperty(ref _Y_Velocity_Start, value); }
  62. }
  63. private float _Y_Position_Stop;
  64. public float Y_Position_Stop
  65. {
  66. get { return _Y_Position_Stop; }
  67. set { SetProperty(ref _Y_Position_Stop, value); }
  68. }
  69. private float _Y_Velocity_Stop;
  70. public float Y_Velocity_Stop
  71. {
  72. get { return _Y_Velocity_Stop; }
  73. set { SetProperty(ref _Y_Velocity_Stop, value); }
  74. }
  75. private float _Z_Position_Start;
  76. public float Z_Position_Start
  77. {
  78. get { return _Z_Position_Start; }
  79. set { SetProperty(ref _Z_Position_Start, value); }
  80. }
  81. private float _Z_Velocity_Start;
  82. public float Z_Velocity_Start
  83. {
  84. get { return _Z_Velocity_Start; }
  85. set { SetProperty(ref _Z_Velocity_Start, value); }
  86. }
  87. private float _Z_Position_Stop;
  88. public float Z_Position_Stop
  89. {
  90. get { return _Z_Position_Stop; }
  91. set { SetProperty(ref _Z_Position_Stop, value); }
  92. }
  93. private float _Z_Velocity_Stop;
  94. public float Z_Velocity_Stop
  95. {
  96. get { return _Z_Velocity_Stop; }
  97. set { SetProperty(ref _Z_Velocity_Stop, value); }
  98. }
  99. private float _U_Position_Start;
  100. public float U_Position_Start
  101. {
  102. get { return _U_Position_Start; }
  103. set { SetProperty(ref _U_Position_Start, value); }
  104. }
  105. private float _U_Velocity_Start;
  106. public float U_Velocity_Start
  107. {
  108. get { return _U_Velocity_Start; }
  109. set { SetProperty(ref _U_Velocity_Start, value); }
  110. }
  111. private float _U_Position_Stop;
  112. public float U_Position_Stop
  113. {
  114. get { return _U_Position_Stop; }
  115. set { SetProperty(ref _U_Position_Stop, value); }
  116. }
  117. private float _U_Velocity_Stop;
  118. public float U_Velocity_Stop
  119. {
  120. get { return _U_Velocity_Stop; }
  121. set { SetProperty(ref _U_Velocity_Stop, value); }
  122. }
  123. private float _V_Position_Start;
  124. public float V_Position_Start
  125. {
  126. get { return _V_Position_Start; }
  127. set { SetProperty(ref _V_Position_Start, value); }
  128. }
  129. private float _V_Velocity_Start;
  130. public float V_Velocity_Start
  131. {
  132. get { return _V_Velocity_Start; }
  133. set { SetProperty(ref _V_Velocity_Start, value); }
  134. }
  135. private float _V_Position_Stop;
  136. public float V_Position_Stop
  137. {
  138. get { return _V_Position_Stop; }
  139. set { SetProperty(ref _V_Position_Stop, value); }
  140. }
  141. private float _V_Velocity_Stop;
  142. public float V_Velocity_Stop
  143. {
  144. get { return _V_Velocity_Stop; }
  145. set { SetProperty(ref _V_Velocity_Stop, value); }
  146. }
  147. private float _W_Position_Start;
  148. public float W_Position_Start
  149. {
  150. get { return _W_Position_Start; }
  151. set { SetProperty(ref _W_Position_Start, value); }
  152. }
  153. private float _W_Velocity_Start;
  154. public float W_Velocity_Start
  155. {
  156. get { return _W_Velocity_Start; }
  157. set { SetProperty(ref _W_Velocity_Start, value); }
  158. }
  159. private float _W_Position_Stop;
  160. public float W_Position_Stop
  161. {
  162. get { return _W_Position_Stop; }
  163. set { SetProperty(ref _W_Position_Stop, value); }
  164. }
  165. private float _W_Velocity_Stop;
  166. public float W_Velocity_Stop
  167. {
  168. get { return _W_Velocity_Stop; }
  169. set { SetProperty(ref _W_Velocity_Stop, value); }
  170. }
  171. private Int16 _Enable_Start_Node;
  172. public Int16 Enable_Start_Node
  173. {
  174. get { return _Enable_Start_Node; }
  175. set { SetProperty(ref _Enable_Start_Node, value); }
  176. }
  177. private Int16 _Enable_Pulse;
  178. public Int16 Enable_Pulse
  179. {
  180. get { return _Enable_Pulse; }
  181. set { SetProperty(ref _Enable_Pulse, value); }
  182. }
  183. private Int16 _Enable_3D;
  184. public Int16 Enable_3D
  185. {
  186. get { return _Enable_3D; }
  187. set { SetProperty(ref _Enable_3D, value); }
  188. }
  189. private Int16 _Enable_Wait_Finish;
  190. public Int16 Enable_Wait_Finish
  191. {
  192. get { return _Enable_Wait_Finish; }
  193. set { SetProperty(ref _Enable_Wait_Finish, value); }
  194. }
  195. private Int16 _Enable_Light1;
  196. public Int16 Enable_Light1
  197. {
  198. get { return _Enable_Light1; }
  199. set { SetProperty(ref _Enable_Light1, value); }
  200. }
  201. private Int16 _Enable_Light2;
  202. public Int16 Enable_Light2
  203. {
  204. get { return _Enable_Light2; }
  205. set { SetProperty(ref _Enable_Light2, value); }
  206. }
  207. private Int16 _Enable_Light3;
  208. public Int16 Enable_Light3
  209. {
  210. get { return _Enable_Light3; }
  211. set { SetProperty(ref _Enable_Light3, value); }
  212. }
  213. private Int16 _Enable_Light4;
  214. public Int16 Enable_Light4
  215. {
  216. get { return _Enable_Light4; }
  217. set { SetProperty(ref _Enable_Light4, value); }
  218. }
  219. private Guid _CameraProcedureId1 = Guid.Empty;
  220. /// <summary>
  221. /// Camera 对应的视觉流程 Id
  222. /// </summary>
  223. public Guid CameraProcedureId1
  224. {
  225. get { return _CameraProcedureId1; }
  226. set { SetProperty(ref _CameraProcedureId1, value); }
  227. }
  228. private Guid _CameraProcedureId2 = Guid.Empty;
  229. /// <summary>
  230. /// Camera 对应的视觉流程 Id
  231. /// </summary>
  232. public Guid CameraProcedureId2
  233. {
  234. get { return _CameraProcedureId2; }
  235. set { SetProperty(ref _CameraProcedureId2, value); }
  236. }
  237. private Guid _CameraProcedureId3 = Guid.Empty;
  238. /// <summary>
  239. /// Camera 对应的视觉流程 Id
  240. /// </summary>
  241. public Guid CameraProcedureId3
  242. {
  243. get { return _CameraProcedureId3; }
  244. set { SetProperty(ref _CameraProcedureId3, value); }
  245. }
  246. private Guid _CameraProcedureId4 = Guid.Empty;
  247. /// <summary>
  248. /// Camera 对应的视觉流程 Id
  249. /// </summary>
  250. public Guid CameraProcedureId4
  251. {
  252. get { return _CameraProcedureId4; }
  253. set { SetProperty(ref _CameraProcedureId4, value); }
  254. }
  255. private Guid _CameraProcedureId5 = Guid.Empty;
  256. /// <summary>
  257. /// Camera 对应的视觉流程 Id
  258. /// </summary>
  259. public Guid CameraProcedureId5
  260. {
  261. get { return _CameraProcedureId5; }
  262. set { SetProperty(ref _CameraProcedureId5, value); }
  263. }
  264. private Guid _CameraProcedureId6 = Guid.Empty;
  265. /// <summary>
  266. /// Camera 对应的视觉流程 Id
  267. /// </summary>
  268. public Guid CameraProcedureId6
  269. {
  270. get { return _CameraProcedureId6; }
  271. set { SetProperty(ref _CameraProcedureId6, value); }
  272. }
  273. private Guid _CameraProcedureId7 = Guid.Empty;
  274. /// <summary>
  275. /// Camera 对应的视觉流程 Id
  276. /// </summary>
  277. public Guid CameraProcedureId7
  278. {
  279. get { return _CameraProcedureId7; }
  280. set { SetProperty(ref _CameraProcedureId7, value); }
  281. }
  282. private Guid _CameraProcedureId8 = Guid.Empty;
  283. /// <summary>
  284. /// Camera 对应的视觉流程 Id
  285. /// </summary>
  286. public Guid CameraProcedureId8
  287. {
  288. get { return _CameraProcedureId8; }
  289. set { SetProperty(ref _CameraProcedureId8, value); }
  290. }
  291. private Int16 _Camera_Data1;
  292. public Int16 Camera_Data1
  293. {
  294. get { return _Camera_Data1; }
  295. set { SetProperty(ref _Camera_Data1, value); }
  296. }
  297. private Int16 _Camera_Data2;
  298. public Int16 Camera_Data2
  299. {
  300. get { return _Camera_Data2; }
  301. set { SetProperty(ref _Camera_Data2, value); }
  302. }
  303. private Int16 _Camera_Data3;
  304. public Int16 Camera_Data3
  305. {
  306. get { return _Camera_Data3; }
  307. set { SetProperty(ref _Camera_Data3, value); }
  308. }
  309. private Int16 _Camera_Data4;
  310. public Int16 Camera_Data4
  311. {
  312. get { return _Camera_Data4; }
  313. set { SetProperty(ref _Camera_Data4, value); }
  314. }
  315. private Int16 _Camera_Product1;
  316. public Int16 Camera_Product1
  317. {
  318. get { return _Camera_Product1; }
  319. set { SetProperty(ref _Camera_Product1, value); }
  320. }
  321. private Int16 _Camera_Product2;
  322. public Int16 Camera_Product2
  323. {
  324. get { return _Camera_Product2; }
  325. set { SetProperty(ref _Camera_Product2, value); }
  326. }
  327. private Int16 _Camera_Product3;
  328. public Int16 Camera_Product3
  329. {
  330. get { return _Camera_Product3; }
  331. set { SetProperty(ref _Camera_Product3, value); }
  332. }
  333. private Int16 _Camera_Product4;
  334. public Int16 Camera_Product4
  335. {
  336. get { return _Camera_Product4; }
  337. set { SetProperty(ref _Camera_Product4, value); }
  338. }
  339. private float _R_Position;
  340. public float R_Position
  341. {
  342. get { return _R_Position; }
  343. set { SetProperty(ref _R_Position, value); }
  344. }
  345. private float _R_Velocity;
  346. public float R_Velocity
  347. {
  348. get { return _R_Velocity; }
  349. set { SetProperty(ref _R_Velocity, value); }
  350. }
  351. private float _Torque;
  352. public float Torque
  353. {
  354. get { return _Torque; }
  355. set { SetProperty(ref _Torque, value); }
  356. }
  357. private Int16 _Feeder;
  358. public Int16 Feeder
  359. {
  360. get { return _Feeder; }
  361. set { SetProperty(ref _Feeder, value); }
  362. }
  363. private Int16 _ScrewProNum;
  364. public Int16 ScrewProNum
  365. {
  366. get { return _ScrewProNum; }
  367. set { SetProperty(ref _ScrewProNum, value); }
  368. }
  369. //描述
  370. private string _Description;
  371. public string Description
  372. {
  373. get { return _Description; }
  374. set { SetProperty(ref _Description, value); }
  375. }
  376. private Int16 _AiVision;
  377. public Int16 AiVision
  378. {
  379. get { return _AiVision; }
  380. set { SetProperty(ref _AiVision, value); }
  381. }
  382. public PlcPoint()
  383. {
  384. Number = 0;
  385. X_Position_Start = 0;
  386. X_Velocity_Start = 0;
  387. X_Position_Stop = 0;
  388. X_Velocity_Stop = 0;
  389. Y_Position_Start = 0;
  390. Y_Velocity_Start = 0;
  391. Y_Position_Stop = 0;
  392. Y_Velocity_Stop = 0;
  393. Z_Position_Start = 0;
  394. Z_Velocity_Start = 0;
  395. Z_Position_Stop = 0;
  396. Z_Velocity_Stop = 0;
  397. U_Position_Start = 0;
  398. U_Velocity_Start = 0;
  399. U_Position_Stop = 0;
  400. U_Velocity_Stop = 0;
  401. V_Position_Start = 0;
  402. V_Velocity_Start = 0;
  403. V_Position_Stop = 0;
  404. V_Velocity_Stop = 0;
  405. W_Position_Start = 0;
  406. W_Velocity_Start = 0;
  407. W_Position_Stop = 0;
  408. W_Velocity_Stop = 0;
  409. Enable_Start_Node = 0;
  410. Enable_Pulse = 0;
  411. Enable_3D = 0;
  412. Enable_Wait_Finish = 0;
  413. Enable_Light1 = 0;
  414. Enable_Light2 = 0;
  415. Enable_Light3 = 0;
  416. Enable_Light4 = 0;
  417. AiVision = 0;
  418. //R_Position = 0;
  419. //R_Velocity = 0;
  420. //Torque = 0;
  421. //Feeder = 0;
  422. //ScrewProNum = 0;
  423. }
  424. public PlcPoint Clone()
  425. {
  426. return new PlcPoint
  427. {
  428. Number = this.Number,
  429. Label = this.Label,
  430. X_Position_Start = this.X_Position_Start,
  431. X_Velocity_Start= this.X_Velocity_Start,
  432. X_Position_Stop = this.X_Position_Stop,
  433. X_Velocity_Stop = this.X_Velocity_Stop,
  434. Y_Position_Start = this.Y_Position_Start,
  435. Y_Velocity_Start = this.Y_Velocity_Start,
  436. Y_Position_Stop = this.Y_Position_Stop,
  437. Y_Velocity_Stop = this.Y_Velocity_Stop,
  438. Z_Position_Start = this.Z_Position_Start,
  439. Z_Velocity_Start = this.Z_Velocity_Start,
  440. AiVision = this.AiVision,
  441. Z_Position_Stop = this.Z_Position_Stop,
  442. Z_Velocity_Stop = this.Z_Velocity_Stop,
  443. U_Position_Start = this.U_Position_Start,
  444. U_Velocity_Start = this.U_Velocity_Start,
  445. U_Position_Stop = this.U_Position_Stop,
  446. U_Velocity_Stop = this.U_Velocity_Stop,
  447. V_Position_Start = this.V_Position_Start,
  448. V_Velocity_Start = this.V_Velocity_Start,
  449. V_Position_Stop = this.V_Position_Stop,
  450. V_Velocity_Stop = this.V_Velocity_Stop,
  451. W_Position_Start = this.W_Position_Start,
  452. W_Velocity_Start = this.W_Velocity_Start,
  453. W_Position_Stop = this.W_Position_Stop,
  454. W_Velocity_Stop = this.W_Velocity_Stop,
  455. Enable_Start_Node = this.Enable_Start_Node,
  456. Enable_Pulse = this.Enable_Pulse,
  457. Enable_3D = this.Enable_3D,
  458. Enable_Wait_Finish = this.Enable_Wait_Finish,
  459. Enable_Light1 = this.Enable_Light1,
  460. Enable_Light2 = this.Enable_Light2,
  461. Enable_Light3 = this.Enable_Light3,
  462. Enable_Light4 = this.Enable_Light4,
  463. CameraProcedureId1 = this.CameraProcedureId1,
  464. CameraProcedureId2 = this.CameraProcedureId2,
  465. CameraProcedureId3 = this.CameraProcedureId3,
  466. CameraProcedureId4 = this.CameraProcedureId4,
  467. CameraProcedureId5 = this.CameraProcedureId5,
  468. CameraProcedureId6 = this.CameraProcedureId6,
  469. CameraProcedureId7 = this.CameraProcedureId7,
  470. CameraProcedureId8 = this.CameraProcedureId8,
  471. Camera_Data1 = this.Camera_Data1,
  472. Camera_Data2 = this.Camera_Data2,
  473. Camera_Data3 = this.Camera_Data3,
  474. Camera_Data4 = this.Camera_Data4,
  475. Camera_Product1 = this.Camera_Product1,
  476. Camera_Product2 = this.Camera_Product2,
  477. Camera_Product3 = this.Camera_Product3,
  478. Camera_Product4 = this.Camera_Product4,
  479. //R_Position = this.R_Position,
  480. //R_Velocity = this.R_Velocity,
  481. //Torque = this.Torque,
  482. //Feeder = this.Feeder,
  483. //ScrewProNum = this.ScrewProNum,
  484. //Description = this.Description
  485. };
  486. }
  487. /// <summary>
  488. /// 将点位数据写入到PLC地址
  489. /// </summary>
  490. /// <param name="plcAddress"></param>
  491. /// <param name="pLC"></param>
  492. /// <returns></returns>
  493. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  494. {
  495. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  496. nodeValues.Add(string.Format(plcAddress.X_Position_Start.Address, Number), X_Position_Start);
  497. nodeValues.Add(string.Format(plcAddress.X_Velocity_Start.Address, Number), X_Velocity_Start);
  498. nodeValues.Add(string.Format(plcAddress.X_Position_Stop.Address, Number), X_Position_Stop);
  499. nodeValues.Add(string.Format(plcAddress.X_Velocity_Stop.Address, Number), X_Velocity_Stop);
  500. nodeValues.Add(string.Format(plcAddress.Y_Position_Start.Address, Number), Y_Position_Start);
  501. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Start.Address, Number), Y_Velocity_Start);
  502. nodeValues.Add(string.Format(plcAddress.Y_Position_Stop.Address, Number), Y_Position_Stop);
  503. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Stop.Address, Number), Y_Velocity_Stop);
  504. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  505. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  506. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  507. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  508. nodeValues.Add(string.Format(plcAddress.U_Position_Start.Address, Number), U_Position_Start);
  509. nodeValues.Add(string.Format(plcAddress.U_Velocity_Start.Address, Number), U_Velocity_Start);
  510. nodeValues.Add(string.Format(plcAddress.U_Position_Stop.Address, Number), U_Position_Stop);
  511. nodeValues.Add(string.Format(plcAddress.U_Velocity_Stop.Address, Number), U_Velocity_Stop);
  512. nodeValues.Add(string.Format(plcAddress.V_Position_Start.Address, Number), V_Position_Start);
  513. nodeValues.Add(string.Format(plcAddress.V_Velocity_Start.Address, Number), V_Velocity_Start);
  514. nodeValues.Add(string.Format(plcAddress.V_Position_Stop.Address, Number), V_Position_Stop);
  515. nodeValues.Add(string.Format(plcAddress.V_Velocity_Stop.Address, Number), V_Velocity_Stop);
  516. nodeValues.Add(string.Format(plcAddress.W_Position_Start.Address, Number), W_Position_Start);
  517. nodeValues.Add(string.Format(plcAddress.W_Velocity_Start.Address, Number), W_Velocity_Start);
  518. nodeValues.Add(string.Format(plcAddress.W_Position_Stop.Address, Number), W_Position_Stop);
  519. nodeValues.Add(string.Format(plcAddress.W_Velocity_Stop.Address, Number), W_Velocity_Stop);
  520. nodeValues.Add(string.Format(plcAddress.Enable_Start_Node.Address, Number), Enable_Start_Node);
  521. nodeValues.Add(string.Format(plcAddress.Enable_Pulse.Address, Number), Enable_Pulse);
  522. nodeValues.Add(string.Format(plcAddress.Enable_3D.Address, Number), Enable_3D);
  523. nodeValues.Add(string.Format(plcAddress.Enable_Wait_Finish.Address, Number), Enable_Wait_Finish);
  524. nodeValues.Add(string.Format(plcAddress.Enable_Light1.Address, Number), Enable_Light1);
  525. nodeValues.Add(string.Format(plcAddress.Enable_Light2.Address, Number), Enable_Light2);
  526. nodeValues.Add(string.Format(plcAddress.Enable_Light3.Address, Number), Enable_Light3);
  527. nodeValues.Add(string.Format(plcAddress.Enable_Light4.Address, Number), Enable_Light4);
  528. //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  529. //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  530. //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  531. //nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  532. //nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  533. return await pLC.WriteNodesAsync(nodeValues);
  534. }
  535. }
  536. }