UCHMI.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using Sunny.UI;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics.Eventing.Reader;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace HRT_Measure
  15. {
  16. public partial class UCHMI : UserControl
  17. {
  18. public UCHMI()
  19. {
  20. InitializeComponent();
  21. }
  22. public string DisplayLabel
  23. {
  24. set { uiTitlePanel1.Text = value; }
  25. get { return uiTitlePanel1.Text; }
  26. }
  27. public Thread thMonitor ;
  28. public string strPLC = "";
  29. private void UCHMI_Load(object sender, EventArgs e)
  30. {
  31. this.Dock = DockStyle.Fill;
  32. //timer1.Enabled = true;
  33. //splitContainer1.SplitterDistance = this.Height / 2;
  34. switch (DisplayLabel)
  35. {
  36. case "上料房 称重房":
  37. strPLC = "M01M02";
  38. break;
  39. case "压机房":
  40. strPLC = "M03";
  41. break;
  42. case "检测房 装箱房":
  43. strPLC = "M04M05";
  44. break;
  45. }
  46. thMonitor = new Thread(new ThreadStart(ThMonitor));
  47. thMonitor.IsBackground = true;
  48. txtAlm.Start();
  49. }
  50. #region Button
  51. private void btnInitilize_Click(object sender, EventArgs e)
  52. {
  53. //switch (strPLC)
  54. //{
  55. // case "M01M02":
  56. // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", true, out string str);
  57. // break;
  58. // case "M03":
  59. // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", true, out str);
  60. // break;
  61. // case "M04M05":
  62. // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", true, out str);
  63. // break;
  64. //}
  65. }
  66. private void btnInitilize_MouseDown(object sender, MouseEventArgs e)
  67. {
  68. switch (strPLC)
  69. {
  70. case "M01M02":
  71. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", true, out string str);
  72. break;
  73. case "M03":
  74. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", true, out str);
  75. break;
  76. case "M04M05":
  77. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", true, out str);
  78. break;
  79. }
  80. }
  81. private void btnInitilize_MouseUp(object sender, MouseEventArgs e)
  82. {
  83. switch (strPLC)
  84. {
  85. case "M01M02":
  86. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", false, out string str);
  87. break;
  88. case "M03":
  89. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", false, out str);
  90. break;
  91. case "M04M05":
  92. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", false, out str);
  93. break;
  94. }
  95. }
  96. private void btnClearException_Click(object sender, EventArgs e)
  97. {
  98. switch (strPLC)
  99. {
  100. case "M01M02":
  101. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", true, out string str);
  102. break;
  103. case "M03":
  104. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", true, out str);
  105. break;
  106. case "M04M05":
  107. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", true, out str);
  108. break;
  109. }
  110. txtAlm.Text = "";
  111. }
  112. private void btnClearException_MouseDown(object sender, MouseEventArgs e)
  113. {
  114. //switch (strPLC)
  115. //{
  116. // case "M01M02":
  117. // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", true, out string str);
  118. // break;
  119. // case "M03":
  120. // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", true, out str);
  121. // break;
  122. // case "M04M05":
  123. // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", true, out str);
  124. // break;
  125. //}
  126. //txtAlm.Text = "";
  127. }
  128. private void btnClearException_MouseUp(object sender, MouseEventArgs e)
  129. {
  130. switch (strPLC)
  131. {
  132. case "M01M02":
  133. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", false, out string str);
  134. break;
  135. case "M03":
  136. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", false, out str);
  137. break;
  138. case "M04M05":
  139. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", false, out str);
  140. break;
  141. }
  142. txtAlm.Text = "";
  143. }
  144. private void btnStop_Click(object sender, EventArgs e)
  145. {
  146. //switch (strPLC)
  147. //{
  148. // case "M01M02":
  149. // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", true, out string str);
  150. // break;
  151. // case "M03":
  152. // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", true, out str);
  153. // break;
  154. // case "M04M05":
  155. // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", true, out str);
  156. // break;
  157. //}
  158. }
  159. private void btnStop_MouseDown(object sender, MouseEventArgs e)
  160. {
  161. switch (strPLC)
  162. {
  163. case "M01M02":
  164. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", true, out string str);
  165. break;
  166. case "M03":
  167. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", true, out str);
  168. break;
  169. case "M04M05":
  170. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", true, out str);
  171. break;
  172. }
  173. }
  174. private void btnStop_MouseUp(object sender, MouseEventArgs e)
  175. {
  176. switch (strPLC)
  177. {
  178. case "M01M02":
  179. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", false, out string str);
  180. break;
  181. case "M03":
  182. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", false, out str);
  183. break;
  184. case "M04M05":
  185. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", false, out str);
  186. break;
  187. }
  188. }
  189. private void btnStart_Click(object sender, EventArgs e)
  190. {
  191. //switch (strPLC)
  192. //{
  193. // case "M01M02":
  194. // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", true, out string str);
  195. // break;
  196. // case "M03":
  197. // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", true, out str);
  198. // break;
  199. // case "M04M05":
  200. // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", true, out str);
  201. // break;
  202. //}
  203. }
  204. private void btnStart_MouseDown(object sender, MouseEventArgs e)
  205. {
  206. switch (strPLC)
  207. {
  208. case "M01M02":
  209. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", true, out string str);
  210. break;
  211. case "M03":
  212. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", true, out str);
  213. break;
  214. case "M04M05":
  215. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", true, out str);
  216. break;
  217. }
  218. }
  219. private void btnStart_MouseUp(object sender, MouseEventArgs e)
  220. {
  221. switch (strPLC)
  222. {
  223. case "M01M02":
  224. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", false, out string str);
  225. break;
  226. case "M03":
  227. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", false, out str);
  228. break;
  229. case "M04M05":
  230. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", false, out str);
  231. break;
  232. }
  233. }
  234. private void btnHandAndAuto_Click(object sender, EventArgs e)
  235. {
  236. switch (strPLC)
  237. {
  238. case "M01M02":
  239. //ProgramHelp.Instance.commPLC_M01M02.ReadCoin("DB20.494.5", out bool isTrue, out string str);
  240. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.5", !PLCCylinder.dictPLC_InitIO["M01M02"].isHandOrAuto , out string str);//isTrue
  241. break;
  242. case "M03":
  243. //ProgramHelp.Instance.commPLC_M03.ReadCoin("DB20.4.5", out isTrue, out str);
  244. ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.5", !PLCCylinder.dictPLC_InitIO["M03"].isHandOrAuto, out str);
  245. break;
  246. case "M04M05":
  247. //ProgramHelp.Instance.commPLC_M04M05.ReadCoin("DB20.0.5", out isTrue, out str);
  248. ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.5", !PLCCylinder.dictPLC_InitIO["M04M05"].isHandOrAuto, out str);
  249. break;
  250. }
  251. }
  252. #endregion
  253. private void timer1_Tick(object sender, EventArgs e)
  254. {
  255. try
  256. {
  257. //string strPLC = strPLC;
  258. //if (PLCCylinder.dictPLC_InitIO[strPLC].isHandOrAuto) btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.Text = "手动"; btnHandAndAuto.Symbol = 362038; }));
  259. //else btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.Text = "自动"; btnHandAndAuto.Symbol = 57531; }));
  260. if (PLCCylinder.dictPLC_InitIO[strPLC].isInitDone) lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.On; }));
  261. else lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.Off; }));
  262. if (PLCCylinder.dictPLC_InitIO[strPLC].isWait) lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.On; }));
  263. else lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.Off; }));
  264. if (PLCCylinder.dictPLC_InitIO[strPLC].isAlm) lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.On; }));
  265. else lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.Off; }));
  266. if (PLCCylinder.dictPLC_InitIO[strPLC].isAutoRunning) lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.On; }));
  267. else lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.Off; }));
  268. btnInitilize.BeginInvoke(new Action(() => { btnInitilize.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnInit ? Color.Red : Color.LightSkyBlue; }));
  269. btnClearException.BeginInvoke(new Action(() => { btnClearException.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnExceptionQuit ? Color.Red : Color.LightSkyBlue; }));
  270. btnStop.BeginInvoke(new Action(() => { btnStop.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStop ? Color.Red : Color.LightSkyBlue; }));
  271. btnStart.BeginInvoke(new Action(() => { btnStart.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStart ? Color.Red : Color.LightSkyBlue; }));
  272. btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? Color.Red : Color.LightSkyBlue; }));
  273. }
  274. catch (Exception ex)
  275. {
  276. MessageBox.Show(ex.ToString());
  277. }
  278. }
  279. private void ThMonitor()
  280. {
  281. while (true)
  282. {
  283. try
  284. {
  285. if (PLCCylinder.dictPLC_InitIO[strPLC].isInitDone) lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.On; }));
  286. else lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.Off; }));
  287. if (PLCCylinder.dictPLC_InitIO[strPLC].isWait) lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.On; }));
  288. else lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.Off; }));
  289. if (PLCCylinder.dictPLC_InitIO[strPLC].isAlm) lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.On; }));
  290. else
  291. {
  292. lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.Off; }));
  293. txtAlm.BeginInvoke(new Action(() => { txtAlm.Text = ""; }));
  294. }
  295. if (PLCCylinder.dictPLC_InitIO[strPLC].isAutoRunning) lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.On; }));
  296. else lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.Off; }));
  297. btnInitilize.BeginInvoke(new Action(() => { btnInitilize.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnInit ? Color.Red : Color.LightSkyBlue; }));
  298. btnClearException.BeginInvoke(new Action(() => { btnClearException.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnExceptionQuit ? Color.Red : Color.LightSkyBlue; }));
  299. btnStop.BeginInvoke(new Action(() => { btnStop.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStop ? Color.Red : Color.LightSkyBlue; }));
  300. btnStart.BeginInvoke(new Action(() => { btnStart.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStart ? Color.Red : Color.LightSkyBlue; }));
  301. btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? Color.Red : Color.LightSkyBlue;
  302. btnHandAndAuto.Text = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? "自动模式" : "手动模式";
  303. }));
  304. switch(strPLC)
  305. {
  306. case "M01M02":
  307. foreach (var item in PLCCylinder.dictM01M02_Alm)
  308. {
  309. if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if(!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
  310. }
  311. break;
  312. case "M03":
  313. foreach (var item in PLCCylinder.dictM03_Alm)
  314. {
  315. if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if (!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
  316. }
  317. break;
  318. case "M04M05":
  319. foreach (var item in PLCCylinder.dictM04M05_Alm)
  320. {
  321. if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if (!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
  322. }
  323. break;
  324. }
  325. }
  326. catch (Exception ex)
  327. {
  328. MessageBox.Show(ex.ToString());
  329. }
  330. Thread.Sleep(1);
  331. }
  332. }
  333. }
  334. }