FrmPLC_M01M02.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. using Sunny.UI;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace HRT_Measure
  12. {
  13. public partial class FrmPLC_M01M02 : Sunny.UI.UIForm
  14. {
  15. public FrmPLC_M01M02()
  16. {
  17. InitializeComponent();
  18. }
  19. private void FrmPLC_Load(object sender, EventArgs e)
  20. {
  21. uiSplitContainer1.SplitterDistance = this.Width / 2;
  22. LoadPLCValue();
  23. LoadAxisPos();
  24. LoadAxis();
  25. tabControlAxis.SelectedIndex = 0;
  26. }
  27. public List<UCCylinder> listCylinder = new List<UCCylinder>();
  28. public List<UCAxisPos> listAxisPos_取料X轴Pos = new List<UCAxisPos>();
  29. public List<UCAxisPos> listAxisPos_取料Y轴Pos = new List<UCAxisPos>();
  30. public List<UCAxisPos> listAxisPos_取料Z轴Pos = new List<UCAxisPos>();
  31. public List<UCAxisPos> listAxisPos_取料R轴Pos = new List<UCAxisPos>();
  32. public List<UCAxisPos> listAxisPos_上料站X轴Pos = new List<UCAxisPos>();
  33. public List<UCAxisPos> listAxisPos_上料站Y轴Pos = new List<UCAxisPos>();
  34. public List<UCAxisPos> listAxisPos_上料站Z轴Pos = new List<UCAxisPos>();
  35. public List<UCAxis> listAxis = new List<UCAxis>();
  36. private void LoadPLCValue()
  37. {
  38. listCylinder.Clear();
  39. for (int i = 0; i < PLCCylinder.listM01M02_上料工位.Count; i++)
  40. {
  41. UCCylinder uCCylinder = new UCCylinder("M01M02", PLCCylinder.listM01M02_上料工位[i],PLCCylinder.dictM01M02_上料工位);
  42. if(i < 11) uiTableLayoutPanel上料工位.Controls.Add(uCCylinder, 0, i);
  43. else uiTableLayoutPanel上料工位.Controls.Add(uCCylinder, 1, i - 11);
  44. listCylinder.Add(uCCylinder);
  45. //uCCylinder.timer1.Enabled = true;
  46. uCCylinder.thMonitor.Start();
  47. }
  48. for (int i = 0; i < PLCCylinder.listM01M02_取出工位.Count; i++)
  49. {
  50. UCCylinder uCCylinder = new UCCylinder("M01M02", PLCCylinder.listM01M02_取出工位[i], PLCCylinder.dictM01M02_取出工位);
  51. if (i < 11) uiTableLayoutPanel取出工位.Controls.Add(uCCylinder, 0, i);
  52. else uiTableLayoutPanel取出工位.Controls.Add(uCCylinder, 1, i - 11);
  53. listCylinder.Add(uCCylinder);
  54. //uCCylinder.timer1.Enabled = true;
  55. uCCylinder.thMonitor.Start();
  56. }
  57. for (int i = 0; i < PLCCylinder.listM01M02_提升机工位.Count; i++)
  58. {
  59. UCCylinder uCCylinder = new UCCylinder("M01M02", PLCCylinder.listM01M02_提升机工位[i], PLCCylinder.dictM01M02_提升机工位);
  60. if (i < 11) uiTableLayoutPanel提升机工位.Controls.Add(uCCylinder, 0, i);
  61. else uiTableLayoutPanel提升机工位.Controls.Add(uCCylinder, 1, i - 11);
  62. listCylinder.Add(uCCylinder);
  63. //uCCylinder.timer1.Enabled = true;
  64. uCCylinder.thMonitor.Start();
  65. }
  66. for (int i = 0; i < PLCCylinder.listM01M02_称重工位.Count; i++)
  67. {
  68. UCCylinder uCCylinder = new UCCylinder("M01M02", PLCCylinder.listM01M02_称重工位[i], PLCCylinder.dictM01M02_称重工位);
  69. if (i < 11) uiTableLayoutPanel称重工位.Controls.Add(uCCylinder, 0, i);
  70. else uiTableLayoutPanel称重工位.Controls.Add(uCCylinder, 1, i - 11);
  71. listCylinder.Add(uCCylinder);
  72. //uCCylinder.timer1.Enabled = true;
  73. uCCylinder.thMonitor.Start();
  74. }
  75. for (int i = 0; i < PLCCylinder.listM01M02_出口工位.Count; i++)
  76. {
  77. UCCylinder uCCylinder = new UCCylinder("M01M02", PLCCylinder.listM01M02_出口工位[i], PLCCylinder.dictM01M02_出口工位);
  78. if (i < 11) uiTableLayoutPanel出口工位.Controls.Add(uCCylinder, 0, i);
  79. else uiTableLayoutPanel出口工位.Controls.Add(uCCylinder, 1, i - 11);
  80. listCylinder.Add(uCCylinder);
  81. //uCCylinder.timer1.Enabled = true;
  82. uCCylinder.thMonitor.Start();
  83. }
  84. }
  85. private void LoadAxisPos()
  86. {
  87. listAxisPos_取料X轴Pos.Clear(); listAxisPos_取料Y轴Pos.Clear(); listAxisPos_取料Z轴Pos.Clear(); listAxisPos_取料R轴Pos.Clear();
  88. listAxisPos_上料站X轴Pos.Clear(); listAxisPos_上料站Y轴Pos.Clear(); listAxisPos_上料站Z轴Pos.Clear();
  89. uiTableLayoutPanel取料X轴Pos.Controls.Clear();
  90. uiTableLayoutPanel1取料Y轴Pos.Controls.Clear(); uiTableLayoutPanel取料Z轴Pos.Controls.Clear(); uiTableLayoutPanel取料R轴Pos.Controls.Clear();
  91. uiTableLayoutPanel上料站X轴Pos.Controls.Clear(); uiTableLayoutPanel上料站Y轴Pos.Controls.Clear(); uiTableLayoutPanel上料站Z轴Pos.Controls.Clear();
  92. for (int i = 0; i < PLCAxisPos.dictM01M02_取料X轴.Count; i++)
  93. {
  94. UCAxisPos uCAxisPos = new UCAxisPos( PLCAxisPos.listM01M02_取料X轴[i], PLCAxisPos.dictM01M02_取料X轴);
  95. if (i < 9) uiTableLayoutPanel取料X轴Pos.Controls.Add(uCAxisPos, 0, i);
  96. else uiTableLayoutPanel取料X轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  97. listAxisPos_取料X轴Pos.Add(uCAxisPos);
  98. //uCAxisPos.timer1.Enabled = true;
  99. uCAxisPos.thMonitor.Start();
  100. }
  101. for (int i = 0; i < PLCAxisPos.dictM01M02_取料Y轴.Count; i++)
  102. {
  103. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_取料Y轴[i], PLCAxisPos.dictM01M02_取料Y轴);
  104. if (i < 9) uiTableLayoutPanel1取料Y轴Pos.Controls.Add(uCAxisPos, 0, i);
  105. else uiTableLayoutPanel1取料Y轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  106. listAxisPos_取料Y轴Pos.Add(uCAxisPos);
  107. //uCAxisPos.timer1.Enabled = true;
  108. uCAxisPos.thMonitor.Start();
  109. }
  110. for (int i = 0; i < PLCAxisPos.dictM01M02_取料Z轴.Count; i++)
  111. {
  112. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_取料Z轴[i], PLCAxisPos.dictM01M02_取料Z轴);
  113. if (i < 9) uiTableLayoutPanel取料Z轴Pos.Controls.Add(uCAxisPos, 0, i);
  114. else uiTableLayoutPanel取料Z轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  115. listAxisPos_取料Z轴Pos.Add(uCAxisPos);
  116. //uCAxisPos.timer1.Enabled = true;
  117. uCAxisPos.thMonitor.Start();
  118. }
  119. for (int i = 0; i < PLCAxisPos.dictM01M02_取料R轴.Count; i++)
  120. {
  121. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_取料R轴[i], PLCAxisPos.dictM01M02_取料R轴);
  122. if (i < 9) uiTableLayoutPanel取料R轴Pos.Controls.Add(uCAxisPos, 0, i);
  123. else uiTableLayoutPanel取料R轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  124. listAxisPos_取料R轴Pos.Add(uCAxisPos);
  125. //uCAxisPos.timer1.Enabled = true;
  126. uCAxisPos.thMonitor.Start();
  127. }
  128. for (int i = 0; i < PLCAxisPos.dictM01M02_上料站X轴.Count; i++)
  129. {
  130. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_上料站X轴[i], PLCAxisPos.dictM01M02_上料站X轴);
  131. if (i < 9) uiTableLayoutPanel上料站X轴Pos.Controls.Add(uCAxisPos, 0, i);
  132. else uiTableLayoutPanel上料站X轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  133. listAxisPos_上料站X轴Pos.Add(uCAxisPos);
  134. //uCAxisPos.timer1.Enabled = true;
  135. uCAxisPos.thMonitor.Start();
  136. }
  137. for (int i = 0; i < PLCAxisPos.dictM01M02_上料站Y轴.Count; i++)
  138. {
  139. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_上料站Y轴[i], PLCAxisPos.dictM01M02_上料站Y轴);
  140. if (i < 9) uiTableLayoutPanel上料站Y轴Pos.Controls.Add(uCAxisPos, 0, i);
  141. else uiTableLayoutPanel上料站Y轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  142. listAxisPos_上料站Y轴Pos.Add(uCAxisPos);
  143. //uCAxisPos.timer1.Enabled = true;
  144. uCAxisPos.thMonitor.Start();
  145. }
  146. for (int i = 0; i < PLCAxisPos.dictM01M02_上料站Z轴.Count; i++)
  147. {
  148. UCAxisPos uCAxisPos = new UCAxisPos(PLCAxisPos.listM01M02_上料站Z轴[i], PLCAxisPos.dictM01M02_上料站Z轴);
  149. if (i < 9) uiTableLayoutPanel上料站Z轴Pos.Controls.Add(uCAxisPos, 0, i);
  150. else uiTableLayoutPanel上料站Z轴Pos.Controls.Add(uCAxisPos, 1, i - 9);
  151. listAxisPos_上料站Z轴Pos.Add(uCAxisPos);
  152. //uCAxisPos.timer1.Enabled = true;
  153. uCAxisPos.thMonitor.Start();
  154. }
  155. }
  156. private void LoadAxis()
  157. {
  158. listAxis.Clear();
  159. UCAxis uCAxis取料X轴 = new UCAxis("M01M02", "取料X轴", PLCAxis.listM01M02_轴[0], PLCAxis.dictM01M02_轴);
  160. panel取料X轴.Controls.Clear();
  161. panel取料X轴.Controls.Add(uCAxis取料X轴);
  162. //uCAxisPos.timer1.Enabled = true;
  163. uCAxis取料X轴.thMonitor.Start();
  164. listAxis.Add(uCAxis取料X轴);
  165. UCAxis uCAxis取料Y轴 = new UCAxis("M01M02", "取料Y轴", PLCAxis.listM01M02_轴[1], PLCAxis.dictM01M02_轴);
  166. panel取料Y轴.Controls.Clear();
  167. panel取料Y轴.Controls.Add(uCAxis取料Y轴);
  168. //uCAxis取料Y轴.timer1.Enabled = true;
  169. uCAxis取料Y轴.thMonitor.Start();
  170. listAxis.Add(uCAxis取料Y轴);
  171. UCAxis uCAxis取料Z轴 = new UCAxis("M01M02", "取料Z轴", PLCAxis.listM01M02_轴[2], PLCAxis.dictM01M02_轴);
  172. panel取料Z轴.Controls.Clear();
  173. panel取料Z轴.Controls.Add(uCAxis取料Z轴);
  174. //uCAxis取料Z轴.timer1.Enabled = true;
  175. uCAxis取料Z轴.thMonitor.Start();
  176. listAxis.Add(uCAxis取料Z轴);
  177. UCAxis uCAxis取料R轴 = new UCAxis("M01M02", "取料R轴", PLCAxis.listM01M02_轴[3], PLCAxis.dictM01M02_轴);
  178. panel取料R轴.Controls.Clear();
  179. panel取料R轴.Controls.Add(uCAxis取料R轴);
  180. //uCAxis取料R轴.timer1.Enabled = true;
  181. uCAxis取料R轴.thMonitor.Start();
  182. listAxis.Add(uCAxis取料R轴);
  183. UCAxis uCAxis上料站X轴 = new UCAxis("M01M02", "上料站X轴", PLCAxis.listM01M02_轴[4], PLCAxis.dictM01M02_轴);
  184. panel上料站X轴.Controls.Clear();
  185. panel上料站X轴.Controls.Add(uCAxis上料站X轴);
  186. //uCAxis上料站X轴.timer1.Enabled = true;
  187. uCAxis上料站X轴.thMonitor.Start();
  188. listAxis.Add(uCAxis上料站X轴);
  189. UCAxis uCAxis上料站Y轴 = new UCAxis("M01M02", "上料站Y轴", PLCAxis.listM01M02_轴[5], PLCAxis.dictM01M02_轴);
  190. panel上料站Y轴.Controls.Clear();
  191. panel上料站Y轴.Controls.Add(uCAxis上料站Y轴);
  192. uCAxis上料站Y轴.thMonitor.Start();
  193. listAxis.Add(uCAxis上料站Y轴);
  194. UCAxis uCAxis上料站Z轴 = new UCAxis("M01M02", "上料站Z轴", PLCAxis.listM01M02_轴[6], PLCAxis.dictM01M02_轴);
  195. panel上料站Z轴.Controls.Clear();
  196. panel上料站Z轴.Controls.Add(uCAxis上料站Z轴);
  197. uCAxis上料站Z轴.thMonitor.Start();
  198. listAxis.Add(uCAxis上料站Z轴);
  199. }
  200. int count = 0;
  201. private void Timer1_Tick(object sender, EventArgs e)
  202. {
  203. count = listAxis.Count;
  204. count = PLCAxis.dictM01M02_轴.Count;
  205. }
  206. private void FrmPLC_FormClosing(object sender, FormClosingEventArgs e)
  207. {
  208. timer1.Enabled = false;
  209. foreach (var item in listCylinder)
  210. {
  211. try
  212. {
  213. item.timer1.Enabled = false;
  214. item.thMonitor.Abort();
  215. }
  216. catch (Exception)
  217. {
  218. }
  219. }
  220. foreach (var item in listAxis)
  221. {
  222. try
  223. {
  224. item.timer1.Enabled = false;
  225. item.thMonitor.Abort();
  226. }
  227. catch (Exception)
  228. {
  229. }
  230. }
  231. foreach (var item in listAxisPos_取料X轴Pos)
  232. {
  233. try
  234. {
  235. item.timer1.Enabled = false;
  236. item.thMonitor.Abort();
  237. }
  238. catch (Exception)
  239. {
  240. }
  241. }
  242. foreach (var item in listAxisPos_取料Y轴Pos)
  243. {
  244. try
  245. {
  246. item.timer1.Enabled = false;
  247. item.thMonitor.Abort();
  248. }
  249. catch (Exception)
  250. {
  251. }
  252. }
  253. foreach (var item in listAxisPos_取料Z轴Pos)
  254. {
  255. try
  256. {
  257. item.timer1.Enabled = false;
  258. item.thMonitor.Abort();
  259. }
  260. catch (Exception)
  261. {
  262. }
  263. }
  264. foreach (var item in listAxisPos_取料R轴Pos)
  265. {
  266. try
  267. {
  268. item.timer1.Enabled = false;
  269. item.thMonitor.Abort();
  270. }
  271. catch (Exception)
  272. {
  273. }
  274. }
  275. foreach (var item in listAxisPos_上料站X轴Pos)
  276. {
  277. try
  278. {
  279. item.timer1.Enabled = false;
  280. item.thMonitor.Abort();
  281. }
  282. catch (Exception)
  283. {
  284. }
  285. }
  286. foreach (var item in listAxisPos_上料站Y轴Pos)
  287. {
  288. try
  289. {
  290. item.timer1.Enabled = false;
  291. item.thMonitor.Abort();
  292. }
  293. catch (Exception)
  294. {
  295. }
  296. }
  297. foreach (var item in listAxisPos_上料站Z轴Pos)
  298. {
  299. try
  300. {
  301. item.timer1.Enabled = false;
  302. item.thMonitor.Abort();
  303. }
  304. catch (Exception)
  305. {
  306. }
  307. }
  308. }
  309. private void tabControlM01M02_SelectedIndexChanged(object sender, EventArgs e)
  310. {
  311. ReadPLCHelp.iM01M02IOStation = tabControlM01M02.SelectedIndex;
  312. }
  313. private void tabControlAxis_SelectedIndexChanged(object sender, EventArgs e)
  314. {
  315. ReadPLCHelp.iM01M02AxisStation = tabControlAxis.SelectedIndex;
  316. //switch (tabControlAxis.SelectedIndex)
  317. //{
  318. // case 0:
  319. // foreach (var item in listAxisPos_取料X轴Pos)
  320. // {
  321. // //item.timer1.Enabled = true;
  322. // item.thMonitor.Start();
  323. // }
  324. // break;
  325. // case 1:
  326. // foreach (var item in listAxisPos_取料Y轴Pos)
  327. // {
  328. // item.thMonitor.Start();
  329. // }
  330. // break;
  331. // case 2:
  332. // foreach (var item in listAxisPos_取料Z轴Pos)
  333. // {
  334. // item.thMonitor.Start();
  335. // }
  336. // break;
  337. // case 3:
  338. // foreach (var item in listAxisPos_取料R轴Pos)
  339. // {
  340. // item.thMonitor.Start();
  341. // }
  342. // break;
  343. // case 4:
  344. // foreach (var item in listAxisPos_上料站X轴Pos)
  345. // {
  346. // item.thMonitor.Start();
  347. // }
  348. // break;
  349. // case 5:
  350. // foreach (var item in listAxisPos_上料站Y轴Pos)
  351. // {
  352. // item.thMonitor.Start();
  353. // }
  354. // break;
  355. // case 6:
  356. // foreach (var item in listAxisPos_上料站Z轴Pos)
  357. // {
  358. // item.thMonitor.Start();
  359. // }
  360. // break;
  361. //}
  362. }
  363. }
  364. }