FrmFirstWindow.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 FrmFirstWindow : Form
  14. {
  15. public FrmFirstWindow()
  16. {
  17. InitializeComponent();
  18. }
  19. PLCResultHelp resultHelp = new PLCResultHelp();
  20. private void FrmFirstWindow_Load(object sender, EventArgs e)
  21. {
  22. splitContainerMain.SplitterDistance = 367;
  23. uchmiM01M02.thMonitor.Start(); uchmiM03.thMonitor.Start(); uchmiM04M05.thMonitor.Start();
  24. timer1.Enabled = true;
  25. }
  26. private void btn清料_Click(object sender, EventArgs e)
  27. {
  28. try
  29. {
  30. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.496.0", !PLCResultHelp.isM01_清料, out string str);
  31. }
  32. catch (Exception ex)
  33. {
  34. MessageBox.Show(ex.ToString());
  35. }
  36. }
  37. private void btn称重开始_Click(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB136.502.4", !PLCResultHelp.isM01_称重开始, out string str);
  42. }
  43. catch (Exception ex)
  44. {
  45. MessageBox.Show(ex.ToString());
  46. }
  47. }
  48. private void btnClearPressure_Click(object sender, EventArgs e)
  49. {
  50. try
  51. {
  52. ProgramHelp.Instance.comm压机.WriteShort(ReadPLCHelp.dictPressure["工件计数"].Address, 0, out string str);
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageBox.Show(ex.ToString());
  57. }
  58. }
  59. private void btnAllowLayOff_Click(object sender, EventArgs e)
  60. {
  61. try
  62. {
  63. ProgramHelp.Instance.commPLC_M04M05.WriteCoin(ReadPLCHelp.dictM04["允许下料"], !PLCResultHelp.isM04_允许下料, out string str);
  64. }
  65. catch (Exception ex)
  66. {
  67. MessageBox.Show(ex.ToString());
  68. }
  69. }
  70. private void timer1_Tick(object sender, EventArgs e)
  71. {
  72. try
  73. {
  74. //M01
  75. txt药A暂存当前盒数.Text = resultHelp.M01_药A暂存当前盒数.ToString();
  76. txt药B暂存当前盒数.Text = resultHelp.M01_药B暂存当前盒数.ToString();
  77. txt抛盖暂存槽当前数量.Text = resultHelp.M01_抛盖暂存槽当前数量.ToString();
  78. txt空桶暂存槽当前数量.Text = resultHelp.M01_空桶暂存槽当前数量.ToString();
  79. btn清料.FillColor = PLCResultHelp.isM01_清料 ? Color.Green : Color.Gray;
  80. btn称重开始.FillColor = PLCResultHelp.isM01_称重开始 ? Color.Green : Color.Gray;
  81. //M02
  82. txt药A称重配比重量.Text = resultHelp.M02_药A称重配比重量.ToString();
  83. txtA料仓1当前重量.Text = (Convert.ToSingle( resultHelp.M02_A料仓1当前重量) / 100).ToString("f3");
  84. txtA料仓2当前重量.Text = (Convert.ToSingle(resultHelp.M02_A料仓2当前重量) / 100).ToString("f3");
  85. txtA料仓3当前重量.Text = (Convert.ToSingle(resultHelp.M02_A料仓3当前重量) / 100).ToString("f3");
  86. txtA料仓4当前重量.Text = (Convert.ToSingle(resultHelp.M02_A料仓4当前重量) / 100).ToString("f3");
  87. txtA料仓5当前重量.Text = (Convert.ToSingle(resultHelp.M02_A料仓5当前重量) / 100).ToString("f3");
  88. txt药B称重配比重量.Text = resultHelp.M02_药B称重配比重量.ToString();
  89. txtB料仓1当前重量.Text = (Convert.ToSingle(resultHelp.M02_B料仓1当前重量) / 100).ToString("f3");
  90. txtB料仓2当前重量.Text = (Convert.ToSingle(resultHelp.M02_B料仓2当前重量) / 100).ToString("f3");
  91. txtB料仓3当前重量.Text = (Convert.ToSingle(resultHelp.M02_B料仓3当前重量) / 100).ToString("f3");
  92. txtB料仓4当前重量.Text = (Convert.ToSingle(resultHelp.M02_B料仓4当前重量) / 100).ToString("f3");
  93. txtB料仓5当前重量.Text = (Convert.ToSingle(resultHelp.M02_B料仓5当前重量) / 100).ToString("f3");
  94. //M04
  95. btnAllowLayOff.FillColor = PLCResultHelp.isM04_允许下料 ? Color.Green : Color.Gray;
  96. txtCurrentHeight.Text = PLCResultHelp.fM04_当前检测高度.ToString("f2");
  97. txtCurrentWeight.Text = PLCResultHelp.fM04_当前重量.ToString("f2");
  98. //M05
  99. txt箱数.Text = resultHelp.M05_箱数.ToString();
  100. //压机
  101. foreach (var item in grbPressure.Controls)
  102. {
  103. if (item is UITextBox)
  104. {
  105. try
  106. {
  107. string name = (((UITextBox)item).Name).Remove(0,3);
  108. if (name == "当前动作")
  109. {
  110. switch (Convert.ToInt32(ReadPLCHelp.dictPressure[name].value))
  111. {
  112. case 0:
  113. ((UITextBox)item).Text = "静止";
  114. break;
  115. case 1:
  116. ((UITextBox)item).Text = "主缸保压";
  117. break;
  118. case 2:
  119. ((UITextBox)item).Text = "主缸快速顶出";
  120. break;
  121. case 4:
  122. ((UITextBox)item).Text = "主缸慢速顶出";
  123. break;
  124. case 5:
  125. ((UITextBox)item).Text = "主缸泄压";
  126. break;
  127. case 6:
  128. ((UITextBox)item).Text = "主缸慢速退回";
  129. break;
  130. case 7:
  131. ((UITextBox)item).Text = "主缸快速退回";
  132. break;
  133. case 8:
  134. ((UITextBox)item).Text = "主缸减速退回";
  135. break;
  136. case 3:
  137. case 9:
  138. case 10:
  139. case 11:
  140. ((UITextBox)item).Text = "";
  141. break;
  142. }
  143. }
  144. else if (name == "动作提示")
  145. {
  146. switch (Convert.ToInt32(ReadPLCHelp.dictPressure[name].value))
  147. {
  148. case 0:
  149. ((UITextBox)item).Text = "允许动作";
  150. break;
  151. case 1:
  152. ((UITextBox)item).Text = "主缸上限位";
  153. break;
  154. case 2:
  155. ((UITextBox)item).Text = "主缸压力达成";
  156. break;
  157. case 3:
  158. ((UITextBox)item).Text = "前光栅保护";
  159. break;
  160. case 4:
  161. ((UITextBox)item).Text = "后光栅保护";
  162. break;
  163. case 5:
  164. ((UITextBox)item).Text = "主缸下限位";
  165. break;
  166. case 6:
  167. ((UITextBox)item).Text = "顶缸上限位";
  168. break;
  169. case 7:
  170. ((UITextBox)item).Text = "顶缸下限位";
  171. break;
  172. case 8:
  173. ((UITextBox)item).Text = "主缸未置下限位";
  174. break;
  175. case 9:
  176. ((UITextBox)item).Text = "伺服未启动";
  177. break;
  178. case 10:
  179. ((UITextBox)item).Text = "顶缸未置上限位";
  180. break;
  181. case 11:
  182. ((UITextBox)item).Text = "顶缸未置下限位";
  183. break;
  184. case 12:
  185. ((UITextBox)item).Text = "工件计数达成";
  186. break;
  187. case 13:
  188. ((UITextBox)item).Text = "静止";
  189. break;
  190. case 14:
  191. ((UITextBox)item).Text = "伺服停止";
  192. break;
  193. case 15:
  194. ((UITextBox)item).Text = "主伺服报警";
  195. break;
  196. case 16:
  197. ((UITextBox)item).Text = "副伺服报警";
  198. break;
  199. case 17:
  200. ((UITextBox)item).Text = "液位低报警";
  201. break;
  202. case 18:
  203. ((UITextBox)item).Text = "油温需冷却";
  204. break;
  205. case 19:
  206. ((UITextBox)item).Text = "油温超高停机";
  207. break;
  208. case 20:
  209. ((UITextBox)item).Text = "润滑油位不足";
  210. break;
  211. case 21:
  212. ((UITextBox)item).Text = "地坑漏油报警";
  213. break;
  214. case 22:
  215. ((UITextBox)item).Text = "锁紧完成";
  216. break;
  217. case 23:
  218. ((UITextBox)item).Text = "松锁完成";
  219. break;
  220. case 24:
  221. ((UITextBox)item).Text = "锁紧缸未松锁";
  222. break;
  223. case 25:
  224. ((UITextBox)item).Text = "松锁未置上极限";
  225. break;
  226. case 26:
  227. ((UITextBox)item).Text = "未置上极限";
  228. break;
  229. case 27:
  230. ((UITextBox)item).Text = "锁紧缸未锁紧";
  231. break;
  232. case 28:
  233. ((UITextBox)item).Text = "顶缸未置下极限";
  234. break;
  235. case 29:
  236. ((UITextBox)item).Text = "移动台未贴合";
  237. break;
  238. case 30:
  239. ((UITextBox)item).Text = "移动台未夹紧";
  240. break;
  241. case 31:
  242. ((UITextBox)item).Text = "移动台未进到位";
  243. break;
  244. case 32:
  245. ((UITextBox)item).Text = "安全撑未移出";
  246. break;
  247. }
  248. }
  249. else
  250. {
  251. //name = name.Remove(0, 3);
  252. ((UITextBox)item).Text = ReadPLCHelp.dictPressure[name].value;
  253. }
  254. }
  255. catch (Exception)
  256. {
  257. }
  258. }
  259. }
  260. }
  261. catch (Exception)
  262. {
  263. }
  264. }
  265. private void FrmFirstWindow_FormClosing(object sender, FormClosingEventArgs e)
  266. {
  267. try
  268. {
  269. uchmiM01M02.timer1.Enabled = false;
  270. uchmiM03.timer1.Enabled = false;
  271. uchmiM04M05.timer1.Enabled = false;
  272. try
  273. {
  274. uchmiM01M02.thMonitor.Abort();
  275. }
  276. catch { }
  277. try
  278. {
  279. uchmiM03.thMonitor.Abort();
  280. }
  281. catch { }
  282. try
  283. {
  284. uchmiM04M05.thMonitor.Abort();
  285. }
  286. catch { }
  287. }
  288. catch (Exception)
  289. {
  290. }
  291. }
  292. }
  293. }