PlcPoint.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 float _R_Position;
  316. public float R_Position
  317. {
  318. get { return _R_Position; }
  319. set { SetProperty(ref _R_Position, value); }
  320. }
  321. private float _R_Velocity;
  322. public float R_Velocity
  323. {
  324. get { return _R_Velocity; }
  325. set { SetProperty(ref _R_Velocity, value); }
  326. }
  327. private float _Torque;
  328. public float Torque
  329. {
  330. get { return _Torque; }
  331. set { SetProperty(ref _Torque, value); }
  332. }
  333. private Int16 _Feeder;
  334. public Int16 Feeder
  335. {
  336. get { return _Feeder; }
  337. set { SetProperty(ref _Feeder, value); }
  338. }
  339. private Int16 _ScrewProNum;
  340. public Int16 ScrewProNum
  341. {
  342. get { return _ScrewProNum; }
  343. set { SetProperty(ref _ScrewProNum, value); }
  344. }
  345. //描述
  346. private string _Description;
  347. public string Description
  348. {
  349. get { return _Description; }
  350. set { SetProperty(ref _Description, value); }
  351. }
  352. public PlcPoint()
  353. {
  354. Number = 0;
  355. X_Position_Start = 0;
  356. X_Velocity_Start = 0;
  357. X_Position_Stop = 0;
  358. X_Velocity_Stop = 0;
  359. Y_Position_Start = 0;
  360. Y_Velocity_Start = 0;
  361. Y_Position_Stop = 0;
  362. Y_Velocity_Stop = 0;
  363. Z_Position_Start = 0;
  364. Z_Velocity_Start = 0;
  365. Z_Position_Stop = 0;
  366. Z_Velocity_Stop = 0;
  367. U_Position_Start = 0;
  368. U_Velocity_Start = 0;
  369. U_Position_Stop = 0;
  370. U_Velocity_Stop = 0;
  371. V_Position_Start = 0;
  372. V_Velocity_Start = 0;
  373. V_Position_Stop = 0;
  374. V_Velocity_Stop = 0;
  375. W_Position_Start = 0;
  376. W_Velocity_Start = 0;
  377. W_Position_Stop = 0;
  378. W_Velocity_Stop = 0;
  379. Enable_Start_Node = 0;
  380. Enable_Pulse = 0;
  381. Enable_3D = 0;
  382. Enable_Wait_Finish = 0;
  383. Enable_Light1 = 0;
  384. Enable_Light2 = 0;
  385. Enable_Light3 = 0;
  386. Enable_Light4 = 0;
  387. //R_Position = 0;
  388. //R_Velocity = 0;
  389. //Torque = 0;
  390. //Feeder = 0;
  391. //ScrewProNum = 0;
  392. }
  393. public PlcPoint Clone()
  394. {
  395. return new PlcPoint
  396. {
  397. Number = this.Number,
  398. Label = this.Label,
  399. X_Position_Start = this.X_Position_Start,
  400. X_Velocity_Start= this.X_Velocity_Start,
  401. X_Position_Stop = this.X_Position_Stop,
  402. X_Velocity_Stop = this.X_Velocity_Stop,
  403. Y_Position_Start = this.Y_Position_Start,
  404. Y_Velocity_Start = this.Y_Velocity_Start,
  405. Y_Position_Stop = this.Y_Position_Stop,
  406. Y_Velocity_Stop = this.Y_Velocity_Stop,
  407. Z_Position_Start = this.Z_Position_Start,
  408. Z_Velocity_Start = this.Z_Velocity_Start,
  409. Z_Position_Stop = this.Z_Position_Stop,
  410. Z_Velocity_Stop = this.Z_Velocity_Stop,
  411. U_Position_Start = this.U_Position_Start,
  412. U_Velocity_Start = this.U_Velocity_Start,
  413. U_Position_Stop = this.U_Position_Stop,
  414. U_Velocity_Stop = this.U_Velocity_Stop,
  415. V_Position_Start = this.V_Position_Start,
  416. V_Velocity_Start = this.V_Velocity_Start,
  417. V_Position_Stop = this.V_Position_Stop,
  418. V_Velocity_Stop = this.V_Velocity_Stop,
  419. W_Position_Start = this.W_Position_Start,
  420. W_Velocity_Start = this.W_Velocity_Start,
  421. W_Position_Stop = this.W_Position_Stop,
  422. W_Velocity_Stop = this.W_Velocity_Stop,
  423. Enable_Start_Node = this.Enable_Start_Node,
  424. Enable_Pulse = this.Enable_Pulse,
  425. Enable_3D = this.Enable_3D,
  426. Enable_Wait_Finish = this.Enable_Wait_Finish,
  427. Enable_Light1 = this.Enable_Light1,
  428. Enable_Light2 = this.Enable_Light2,
  429. Enable_Light3 = this.Enable_Light3,
  430. Enable_Light4 = this.Enable_Light4,
  431. CameraProcedureId1 = this.CameraProcedureId1,
  432. CameraProcedureId2 = this.CameraProcedureId2,
  433. CameraProcedureId3 = this.CameraProcedureId3,
  434. CameraProcedureId4 = this.CameraProcedureId4,
  435. CameraProcedureId5 = this.CameraProcedureId5,
  436. CameraProcedureId6 = this.CameraProcedureId6,
  437. CameraProcedureId7 = this.CameraProcedureId7,
  438. CameraProcedureId8 = this.CameraProcedureId8,
  439. Camera_Data1 = this.Camera_Data1,
  440. Camera_Data2 = this.Camera_Data2,
  441. Camera_Data3 = this.Camera_Data3,
  442. Camera_Data4 = this.Camera_Data4,
  443. //R_Position = this.R_Position,
  444. //R_Velocity = this.R_Velocity,
  445. //Torque = this.Torque,
  446. //Feeder = this.Feeder,
  447. //ScrewProNum = this.ScrewProNum,
  448. //Description = this.Description
  449. };
  450. }
  451. /// <summary>
  452. /// 将点位数据写入到PLC地址
  453. /// </summary>
  454. /// <param name="plcAddress"></param>
  455. /// <param name="pLC"></param>
  456. /// <returns></returns>
  457. public async Task<bool> WriteToPlcAddress(PlcPointAddress plcAddress, OpcUaClientPLC pLC)
  458. {
  459. Dictionary<string, object> nodeValues = new Dictionary<string, object>();
  460. nodeValues.Add(string.Format(plcAddress.X_Position_Start.Address, Number), X_Position_Start);
  461. nodeValues.Add(string.Format(plcAddress.X_Velocity_Start.Address, Number), X_Velocity_Start);
  462. nodeValues.Add(string.Format(plcAddress.X_Position_Stop.Address, Number), X_Position_Stop);
  463. nodeValues.Add(string.Format(plcAddress.X_Velocity_Stop.Address, Number), X_Velocity_Stop);
  464. nodeValues.Add(string.Format(plcAddress.Y_Position_Start.Address, Number), Y_Position_Start);
  465. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Start.Address, Number), Y_Velocity_Start);
  466. nodeValues.Add(string.Format(plcAddress.Y_Position_Stop.Address, Number), Y_Position_Stop);
  467. nodeValues.Add(string.Format(plcAddress.Y_Velocity_Stop.Address, Number), Y_Velocity_Stop);
  468. nodeValues.Add(string.Format(plcAddress.Z_Position_Start.Address, Number), Z_Position_Start);
  469. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Start.Address, Number), Z_Velocity_Start);
  470. nodeValues.Add(string.Format(plcAddress.Z_Position_Stop.Address, Number), Z_Position_Stop);
  471. nodeValues.Add(string.Format(plcAddress.Z_Velocity_Stop.Address, Number), Z_Velocity_Stop);
  472. nodeValues.Add(string.Format(plcAddress.U_Position_Start.Address, Number), U_Position_Start);
  473. nodeValues.Add(string.Format(plcAddress.U_Velocity_Start.Address, Number), U_Velocity_Start);
  474. nodeValues.Add(string.Format(plcAddress.U_Position_Stop.Address, Number), U_Position_Stop);
  475. nodeValues.Add(string.Format(plcAddress.U_Velocity_Stop.Address, Number), U_Velocity_Stop);
  476. nodeValues.Add(string.Format(plcAddress.V_Position_Start.Address, Number), V_Position_Start);
  477. nodeValues.Add(string.Format(plcAddress.V_Velocity_Start.Address, Number), V_Velocity_Start);
  478. nodeValues.Add(string.Format(plcAddress.V_Position_Stop.Address, Number), V_Position_Stop);
  479. nodeValues.Add(string.Format(plcAddress.V_Velocity_Stop.Address, Number), V_Velocity_Stop);
  480. nodeValues.Add(string.Format(plcAddress.W_Position_Start.Address, Number), W_Position_Start);
  481. nodeValues.Add(string.Format(plcAddress.W_Velocity_Start.Address, Number), W_Velocity_Start);
  482. nodeValues.Add(string.Format(plcAddress.W_Position_Stop.Address, Number), W_Position_Stop);
  483. nodeValues.Add(string.Format(plcAddress.W_Velocity_Stop.Address, Number), W_Velocity_Stop);
  484. nodeValues.Add(string.Format(plcAddress.Enable_Start_Node.Address, Number), Enable_Start_Node);
  485. nodeValues.Add(string.Format(plcAddress.Enable_Pulse.Address, Number), Enable_Pulse);
  486. nodeValues.Add(string.Format(plcAddress.Enable_3D.Address, Number), Enable_3D);
  487. nodeValues.Add(string.Format(plcAddress.Enable_Wait_Finish.Address, Number), Enable_Wait_Finish);
  488. nodeValues.Add(string.Format(plcAddress.Enable_Light1.Address, Number), Enable_Light1);
  489. nodeValues.Add(string.Format(plcAddress.Enable_Light2.Address, Number), Enable_Light2);
  490. nodeValues.Add(string.Format(plcAddress.Enable_Light3.Address, Number), Enable_Light3);
  491. nodeValues.Add(string.Format(plcAddress.Enable_Light4.Address, Number), Enable_Light4);
  492. //nodeValues.Add(string.Format(plcAddress.R_Position.Address, Number), R_Position);
  493. //nodeValues.Add(string.Format(plcAddress.R_Velocity.Address, Number), R_Velocity);
  494. //nodeValues.Add(string.Format(plcAddress.Torque.Address, Number), Torque);
  495. //nodeValues.Add(string.Format(plcAddress.Feeder.Address, Number), Feeder);
  496. //nodeValues.Add(string.Format(plcAddress.ScrewProNum.Address, Number), ScrewProNum);
  497. return await pLC.WriteNodesAsync(nodeValues);
  498. }
  499. }
  500. }