版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1441 lines
61 KiB

  1. using CCWin;
  2. using HalconDotNet;
  3. using HZH_Controls.Forms;
  4. using MaiMuAOI.SysCtrl;
  5. using MaiMuAOI.SysUI.DefectPicShow;
  6. using MaiMuAOI.SysUI.Load;
  7. using MaiMuAOI.SysUI.ProcessStep;
  8. using MaiMuAOI.SysUI.ProcessStep.Ctrl;
  9. using MaiMuAOI.SysUI.ProductAndStep;
  10. using MaiMuAOI.SysUI.SysSet;
  11. using MaiMuAOI.SysUI.Web;
  12. using MaiMuAOI.UI.SysSet;
  13. using MaiMuControl.Device;
  14. using MaiMuControl.Device.CamDev;
  15. using MaiMuControl.Device.IOCardDev;
  16. using MaiMuControl.SysStatusMgr.StatusMgr;
  17. using Models;
  18. using Newtonsoft.Json.Linq;
  19. using OpenCvSharp;
  20. using ProductionControl;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.ComponentModel;
  24. using System.Data;
  25. using System.Diagnostics;
  26. using System.Drawing;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading;
  30. using System.Threading.Tasks;
  31. using System.Windows.Forms;
  32. using static MaiMuAOI.SysCtrl.SysMgr;
  33. namespace MaiMuAOI
  34. {
  35. public partial class MainFrm : Form
  36. {
  37. private Service.ProductService svcProduct = new Service.ProductService();
  38. object AddTextLock = new object();
  39. object AddPicLock = new object();
  40. bool backgroundWorkerDo;
  41. bool DisEnableBuzz;
  42. bool DisEnableDoor;
  43. private Stopwatch RunStartTime = new Stopwatch();
  44. public MainFrm()
  45. {
  46. InitializeComponent();
  47. this.uiTitel1.FatherForm = this;
  48. this.uiTitel1.UserMenuStrip = this.menuStrip1;
  49. this.uiTitel1.ShowContrlBox(true, true, true);
  50. this.uiTitel1.ShowMenu();
  51. this.DoubleBuffered = true;//设置本窗体
  52. SetStyle(ControlStyles.UserPaint, true);
  53. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  54. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
  55. SysMgr.Instance.MainRuning += main_running;
  56. SysMgr.Instance.AutoRuning += auto_runing;
  57. SysMgr.Instance.AutoShowImg += auto_ShowMoreImg;
  58. //显示行号与列宽度自动调整
  59. dgvProcess.RowHeadersVisible = true;
  60. dgvProcess.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
  61. dgvProcess.RowPostPaint += (sender, e) =>
  62. {
  63. SysMgr.showRowNum_onDataGrid_RowPostPaint(this.dgvProcess, sender, e);
  64. };
  65. dgvProcess.DefaultCellStyle.ForeColor = System.Drawing.Color.Black;
  66. this.lblTimeLen.Top = toolStrip1.Top + 20;
  67. this.lblTimeLen.Left = toolStrip1.Width - 300;
  68. this.chkBuzzer.Top = toolStrip1.Top + 20;
  69. this.chkDoorSensor.Top = toolStrip1.Top + 20;
  70. }
  71. #region 私有方法
  72. /// <summary>
  73. /// 初始化
  74. /// </summary>
  75. /// <returns></returns>
  76. private bool InitSystem()
  77. {
  78. //进入初始化,初始化失败则中断
  79. InitFrm initFrm = new InitFrm();
  80. initFrm.ShowDialog();
  81. if (initFrm.DialogResult == DialogResult.OK)
  82. {
  83. //初始化成功
  84. }
  85. else
  86. {
  87. initFrm.Dispose();
  88. return false;
  89. }
  90. initFrm.Dispose();
  91. return true;
  92. }
  93. /// <summary>
  94. /// 系统是否在运行
  95. /// </summary>
  96. /// <returns></returns>
  97. private bool SystemIsRun()
  98. {
  99. if (SysMgr.Instance.IsRuning)
  100. {
  101. FrmDialog.ShowDialog(this, "设备正在运行中!", "警告", false);
  102. //MessageBox.Show("设备正在运行中!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  103. return false;
  104. }
  105. return true;
  106. }
  107. private void ClearDefectBmps()
  108. {
  109. this.pnlBmpList.Controls.Clear();
  110. this.gboxDefectList.Text = $"缺陷图像";
  111. this.gboxDefectList.Tag = 0;
  112. this.lblDefectAddTag.Text = "";
  113. this.lblDefectAddTag.Tag = 0;
  114. }
  115. private void ResetUI(bool clearSN)
  116. {
  117. //保持产品名称和料号
  118. //txtProductName.Text = txtProductCode.Text = txtProductSN.Text = "";
  119. if(clearSN)
  120. cbProductSN.Text = "";
  121. lblTension.ForeColor = Color.White;
  122. lblTension.Text = "0.00";
  123. lblTensionMax.Text = "0.00";
  124. lblTensionMin.Text = "0.00";
  125. lblHeight.ForeColor = Color.White;
  126. lblHeight.Text = "0.00";
  127. lblHeightMax.Text = "0.00";
  128. lblHeightMin.Text = "0.00";
  129. lblLineWidth.ForeColor = Color.White;
  130. lblLineWidth.Text = "0.00";
  131. lblLineWidthMax.Text = "0.00";
  132. lblLineWidthMin.Text = "0.00";
  133. lblPT.ForeColor = Color.White;
  134. lblPT.Text = "0.00";
  135. lblPTMax.Text = "0.00";
  136. lblPTMin.Text = "0.00";
  137. lblCompareResult.ForeColor = Color.White;
  138. lblCompareResult.Text = "无";
  139. //lblCompareCount.Text = "未通过:";
  140. lblDefectResult.ForeColor = Color.White;
  141. lblDefectResult.Text = "无";
  142. lblDefectResultCount.Text = "无";
  143. this.dgvProcess.DataSource = null;
  144. this.dgvProcess.DataSource = null;
  145. this.lstLog.Items.Clear();
  146. this.ClearDefectBmps();
  147. this.flpProcessStep.Controls.Clear();
  148. this.picScanner0.Image = null;
  149. picScanner0.Refresh();
  150. this.picScanner1.Image = null;
  151. picScanner1.Refresh();
  152. this.tsbtnStop.Enabled = false;
  153. this.cbOrderCode.Enabled = true;
  154. this.cbProductCode.Enabled = true;
  155. this.cbProductSN.Enabled = true;
  156. lblTimeLen.Text = "检测时长: 0 秒";
  157. tslabelTime.Text = "实时测试:0.00s";
  158. MainFrm_Paint(null, null);
  159. this.Refresh();
  160. }
  161. private void UserRightCheck()
  162. {
  163. this.tsmStepMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Step);
  164. this.tsmPdtMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Product);
  165. this.tsmSysDataFind.Visible = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Statistics);
  166. this.tsmUserList.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.User);
  167. this.tsmUserRight.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Role);
  168. if(this.tsmUserList.Enabled == false && this.tsmUserRight.Enabled == false)
  169. this.tsmSysUserMgr.Visible = false;
  170. else
  171. this.tsmSysUserMgr.Visible = true;
  172. this.tsmDebug.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Debug);
  173. this.tsmSysSet.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.ParamsSetting);
  174. this.tsmSysPoints.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.ParamsSetting);
  175. if (this.tsmDebug.Enabled == false && this.tsmSysSet.Enabled == false)
  176. this.stmSysSet.Visible = false;
  177. else
  178. this.stmSysSet.Visible = true;
  179. }
  180. #endregion
  181. private void MainFrm_Load(object sender, EventArgs e)
  182. {
  183. //登入
  184. if (SysMgr.Instance.LoginSystem())
  185. {
  186. //登入成功
  187. if (InitSystem())
  188. {
  189. this.Cursor = Cursors.WaitCursor;
  190. //this.WindowState = FormWindowState.Normal;
  191. this.Top = 0;
  192. this.Left = 0;
  193. this.Width = SystemInformation.WorkingArea.Width;
  194. this.Height = SystemInformation.WorkingArea.Height;
  195. //this.WindowState = FormWindowState.Maximized;
  196. this.splitContainer1.SplitterDistance = this.Width / 3;
  197. ResetUI(true);
  198. this.Show();
  199. this.dgvProcess.AutoGenerateColumns = false;
  200. this.tsslLoginInfo.Text = $"操作员:{SysMgr.Instance.UserMgr.LoginUser.Code}({SysMgr.Instance.UserMgr.LoginUser.Name})";
  201. //this.tsslLoginTime.Text = $" 登录时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}";
  202. this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
  203. this.tsslLoginTime.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
  204. this.tsslLoginInfo.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
  205. this.tsAxisState.Text = "";
  206. //设置流程卡显示
  207. this.tabControl1.SelectTab(0);
  208. //更新数据库格式
  209. Service.InitDB.initDB();
  210. //权限判断
  211. UserRightCheck();
  212. //开启后台
  213. //timer1.Enabled = true;
  214. backgroundWorkerDo = true;
  215. backgroundWorker1.RunWorkerAsync();
  216. //s_BackWorker = true;
  217. //backgroundWorker.RunWorkerAsync();
  218. //开启web服务器
  219. SysMgr.Instance.InitWebServer();
  220. //开启处理事件反馈
  221. SysMgr.Instance.InitDefectEvent();
  222. //加载产品料号
  223. SysMgr.Instance.LoadProductCodeList();
  224. //加载产品选择
  225. LoadPdtList(SysMgr.Instance.ProductCodeList);
  226. LoadSNList(SysMgr.Instance.ProductSNList);
  227. this.Cursor = Cursors.Default;
  228. //运行前检测磁盘空间
  229. SysMgr.CheckDisk(this);
  230. }
  231. else
  232. {
  233. Application.Exit();
  234. }
  235. }
  236. else
  237. {
  238. Application.Exit();
  239. }
  240. }
  241. private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
  242. {
  243. backgroundWorkerDo = false;
  244. Thread.Sleep(300);
  245. if (SystemIsRun())
  246. {
  247. DialogResult dr = DialogResult.Cancel;
  248. if (SysMgr.Instance.IsInit)
  249. {
  250. dr = FrmDialog.ShowDialog(this, "确定要退出当前系统?", "警告", true);
  251. }
  252. else
  253. dr = DialogResult.OK;
  254. if (dr == DialogResult.Cancel)
  255. {
  256. e.Cancel = true;
  257. }
  258. else
  259. {
  260. Thread.Sleep(300);
  261. if (SysMgr.Instance.IsInit)
  262. SysMgr.Instance.Close();
  263. //SysMgr.Instance.MainRuning -= main_running;
  264. }
  265. }
  266. else
  267. e.Cancel = true;
  268. }
  269. #region 主界面
  270. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  271. {
  272. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  273. {
  274. Rectangle rect = new Rectangle(0, 0, this.toolStrip1.Width, this.toolStrip1.Height - 2);
  275. e.Graphics.SetClip(rect);
  276. }
  277. }
  278. private void chkBuzzer_CheckedChanged(object sender, EventArgs e)
  279. {
  280. DisEnableBuzz = chkBuzzer.Checked;
  281. }
  282. private void chkDoorSensor_CheckedChanged(object sender, EventArgs e)
  283. {
  284. DisEnableDoor = chkDoorSensor.Checked;
  285. }
  286. private void MainFrm_Shown(object sender, EventArgs e)
  287. {
  288. }
  289. #endregion
  290. #region 菜单按钮
  291. private void tsmSysSet_Click(object sender, EventArgs e)
  292. {
  293. if (SystemIsRun())
  294. {
  295. SysMgr.Instance.StatusMgr.GotoSetParams();
  296. SysSetFrm frm = new SysSetFrm();
  297. frm.ShowDialog();
  298. MainFrm_Paint(null, null);
  299. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  300. }
  301. }
  302. private void tsmUserRight_Click(object sender, EventArgs e)
  303. {
  304. SysMgr.Instance.UserPermissiomMgr();
  305. }
  306. private void tsmUserList_Click(object sender, EventArgs e)
  307. {
  308. SysMgr.Instance.UserListMgr();
  309. }
  310. private void tsmDebug_Click(object sender, EventArgs e)
  311. {
  312. if (SystemIsRun())
  313. {
  314. SysMgr.Instance.StatusMgr.GotoDebug();
  315. SysDebugFrm frm = new SysDebugFrm();
  316. frm.ShowDialog();
  317. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  318. }
  319. }
  320. private void tsmSysPoints_Click(object sender, EventArgs e)
  321. {
  322. if (SystemIsRun())
  323. {
  324. SysMgr.Instance.StatusMgr.GotoSetParams();
  325. SysPointsFrm frm = new SysPointsFrm();
  326. frm.ShowDialog();
  327. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  328. }
  329. }
  330. private void tsmSysDataFind_Click(object sender, EventArgs e)
  331. {
  332. //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B",
  333. // "http://127.0.0.1:" + ConfMgr.Instance.SysConfigParams.HttpServerPort.ToString() + "/static/index.html#/");
  334. //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
  335. //frm.WindowState = FormWindowState.Maximized;
  336. //frm.Show();
  337. }
  338. private void web数据查询ToolStripMenuItem_Click(object sender, EventArgs e)
  339. {
  340. WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
  341. frm.WindowState = FormWindowState.Maximized;
  342. frm.Show();
  343. }
  344. private void 本地数据库查询ToolStripMenuItem_Click(object sender, EventArgs e)
  345. {
  346. DataQueryFrm frm = new DataQueryFrm();
  347. frm.WindowState = FormWindowState.Maximized;
  348. frm.Show();
  349. }
  350. private void 系统管理ToolStripMenuItem_Click(object sender, EventArgs e)
  351. {
  352. if (SystemIsRun())
  353. {
  354. ProductListFrm frm = new ProductListFrm();
  355. frm.ShowDialog();
  356. //加载产品料号
  357. SysMgr.Instance.LoadProductCodeList();
  358. //加载产品选择
  359. LoadPdtList(SysMgr.Instance.ProductCodeList);
  360. }
  361. }
  362. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  363. {
  364. if (SystemIsRun())
  365. {
  366. StepListFrm frm = new StepListFrm();
  367. frm.ShowDialog();
  368. }
  369. }
  370. private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
  371. {
  372. this.Close();
  373. }
  374. private void tsmInfoUS_Click(object sender, EventArgs e)
  375. {
  376. SysInfoFrm frm = new SysInfoFrm();
  377. frm.ShowDialog();
  378. }
  379. private void tsmReadLog_Click(object sender, EventArgs e)
  380. {
  381. SysLogFrm frm = new SysLogFrm();
  382. frm.ShowDialog();
  383. }
  384. private void tsmHelpInfo_Click(object sender, EventArgs e)
  385. {
  386. MessageBox.Show(SysUpdata.Updata, "更新信息");
  387. }
  388. #endregion
  389. #region 显示图像和消息
  390. private void lstLog_DrawItem(object sender, DrawItemEventArgs e)
  391. {
  392. e.DrawBackground();
  393. if (e.Index < 0) return;
  394. try
  395. {
  396. string str = lstLog.Items[e.Index].ToString();
  397. e.Graphics.DrawString(str.Substring(1), e.Font,
  398. new SolidBrush(str[0] == 'R' ? Color.Red : (str[0] == 'Y' ? Color.Orange : Color.Black)),
  399. e.Bounds);
  400. }
  401. catch(Exception ex)
  402. {
  403. e.Graphics.DrawString(ex.Message, e.Font,
  404. new SolidBrush( Color.Red ),
  405. e.Bounds);
  406. }
  407. }
  408. /// <summary>
  409. /// 异步输出日志
  410. /// </summary>
  411. /// <param name="tag">模板标识</param>
  412. /// <param name="msg">内容</param>
  413. /// <param name="type"></param>
  414. private void AddTextEvent(string tag, string msg, WarningEnum level = WarningEnum.Normal)
  415. {
  416. lock (AddTextLock)
  417. {
  418. if (tag != null && tag != "")
  419. tag = $" - [{tag}]";
  420. var now = DateTime.Now;
  421. msg = now.ToString("HH:mm:ss fff") + tag + " - " + msg;
  422. msg = (level == WarningEnum.Normal ? "B" : level == WarningEnum.Low ? "Y" : "R") + msg;
  423. if (this.lstLog.Items.Count > 1000)
  424. this.lstLog.Items.Clear();
  425. lstLog.Items.Insert(0, msg);
  426. }
  427. }
  428. private void main_running(object sender, MainEventArgs e)
  429. {
  430. ShowMessage(e);
  431. }
  432. private delegate void ShowMessageDelegate(MainEventArgs e);
  433. private void ShowMessage(MainEventArgs e)
  434. {
  435. if (InvokeRequired)
  436. {
  437. ShowMessageDelegate smd = new ShowMessageDelegate(ShowMessage);
  438. this.BeginInvoke(smd, e);
  439. }
  440. else
  441. {
  442. AddTextEvent(e.Tag, e.Message, e.Warning);
  443. }
  444. }
  445. /// <summary>
  446. /// 自动运行流程显示
  447. /// </summary>
  448. /// <param name="sender"></param>
  449. /// <param name="e"></param>
  450. private void auto_runing(object sender, RunEventArgs e)
  451. {
  452. ShowUIEvent(e);
  453. }
  454. private delegate void ShowUIEventDelegate(RunEventArgs e);
  455. Bitmap bmp0;
  456. Bitmap bmp1;
  457. private void ShowUIEvent(RunEventArgs e)
  458. {
  459. if (InvokeRequired)
  460. {
  461. ShowUIEventDelegate smd = new ShowUIEventDelegate(ShowUIEvent);
  462. this.BeginInvoke(smd, e);
  463. }
  464. else
  465. {
  466. try
  467. {
  468. if (e.Cmd == 0) //显示SN和流程
  469. {
  470. this.cbProductSN.Text = e.SN;
  471. if (e.NewStep)
  472. {
  473. this.tabControl1.SelectTab(1);
  474. ShowNewStepProcess(e.StepProcessesList);
  475. }
  476. else
  477. {
  478. this.tabControl1.SelectTab(0);
  479. this.dgvProcess.DataSource = new BindingSource(e.StepProcessesList, null);
  480. }
  481. }
  482. else if (e.Cmd == 1) //显示当前运行步骤
  483. {
  484. this.dgvProcess.Rows[e.StepIndex].Selected = true;
  485. dgvProcess.CurrentCell = dgvProcess.Rows[e.StepIndex].Cells[1];
  486. }
  487. else if (e.Cmd == 2) //显示当前运行步骤 和步骤详情
  488. {
  489. this.dgvProcess.Rows[e.StepIndex].Cells["colValue"].Value = e.Mesg;
  490. }
  491. else if (e.Cmd == 3) //图纸比对结果
  492. {
  493. this.lblCompareResult.Text = (e.CompareResult ? "通过" : $"未通过");
  494. this.lblCompareResultCount.Text = e.Cnt.ToString();
  495. if (!e.CompareResult)
  496. {
  497. this.lblCompareResult.ForeColor = Color.Red;
  498. }
  499. else
  500. this.lblCompareResult.ForeColor = Color.Lime;
  501. }
  502. else if (e.Cmd == 4) //缺陷结果
  503. {
  504. lblDefectResult.Text = "未通过";
  505. lblDefectResultCount.Text = $"总数:{e.Cnt},详细:{e.CompareResultString}";
  506. this.toolTip1.SetToolTip(lblDefectResultCount, lblDefectResultCount.Text);
  507. this.lblDefectResult.Text = (e.CompareResult ? "通过" : "未通过");
  508. if (!e.CompareResult)
  509. {
  510. this.lblDefectResult.ForeColor = Color.Red;
  511. }
  512. else
  513. this.lblDefectResult.ForeColor = Color.Lime;
  514. }
  515. else if (e.Cmd == 5) //加载缺陷小图
  516. {
  517. ;
  518. }
  519. else if (e.Cmd == 6) //显示主图
  520. {
  521. if (e.PicIndex == 0)
  522. {
  523. bmp0 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  524. picScanner0.Image = bmp0;
  525. picScanner0.Refresh();
  526. }
  527. else
  528. {
  529. bmp1 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  530. picScanner1.Image = bmp1;
  531. picScanner1.Refresh();
  532. }
  533. }
  534. else if (e.Cmd == 7) //显示测试时间
  535. {
  536. lblTimeLen.Text = "检测时长: " + e.Time.ToString("0.000") + " 秒";
  537. //tslabelTestTime.Text = "测试时间:" + e.Time.ToString("0.000") + "s";
  538. }
  539. else if (e.Cmd == 10) //测试结束
  540. {
  541. this.tsbtnStart.Enabled = true;
  542. this.tsbtnStop.Enabled = false;
  543. this.cbOrderCode.Enabled = true;
  544. this.cbProductCode.Enabled = true;
  545. this.cbProductSN.Enabled = true;
  546. }
  547. else if (e.Cmd == 21) //厚度显示
  548. {
  549. double value = Math.Round(e.Value.Average(), 2);
  550. double valueMax = e.Value.Max();
  551. double valueMin = e.Value.Min();
  552. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  553. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  554. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  555. this.lblHeight.Text = Math.Round(value, 2).ToString();
  556. this.lblHeight.ForeColor = color;
  557. this.lblHeightMax.Text = Math.Round(valueMax, 2).ToString();
  558. this.lblHeightMax.ForeColor = colorMax;
  559. this.lblHeightMin.Text = Math.Round(valueMin, 2).ToString();
  560. this.lblHeightMin.ForeColor = colorMin;
  561. }
  562. else if (e.Cmd == 22) //PT显示
  563. {
  564. double value = Math.Round(e.Value.Average(), 4);
  565. double valueMax = e.Value.Max();
  566. double valueMin = e.Value.Min();
  567. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  568. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  569. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  570. this.lblPT.Text = Math.Round(value, 4).ToString();
  571. this.lblPT.ForeColor = color;
  572. this.lblPTMax.Text = Math.Round(valueMax, 4).ToString();
  573. this.lblPTMax.ForeColor = colorMax;
  574. this.lblPTMin.Text = Math.Round(valueMin, 4).ToString();
  575. this.lblPTMin.ForeColor = colorMin;
  576. }
  577. else if (e.Cmd == 23) //线宽显示
  578. {
  579. double value = Math.Round(e.Value.Average(), 2);
  580. double valueMax = e.Value.Max();
  581. double valueMin = e.Value.Min();
  582. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  583. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  584. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  585. this.lblLineWidth.Text = Math.Round(value, 2).ToString();
  586. this.lblLineWidth.ForeColor = color;
  587. this.lblLineWidthMax.Text = Math.Round(valueMax, 2).ToString();
  588. this.lblLineWidthMax.ForeColor = colorMax;
  589. this.lblLineWidthMin.Text = Math.Round(valueMin, 2).ToString();
  590. this.lblLineWidthMin.ForeColor = colorMin;
  591. }
  592. else if (e.Cmd == 30) //新流程 厚度, 张力, pt, 线宽显示
  593. {
  594. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex +1), true);
  595. //滚动条滚动
  596. //int scrollStep = (this.flpProcessStep.VerticalScroll.Maximum / (flpProcessStep.Controls.Count - 1));
  597. this.flpProcessStep.VerticalScroll.Value = e.StepIndex * controls[0].Height > this.flpProcessStep.VerticalScroll.Maximum? this.flpProcessStep.VerticalScroll.Maximum: e.StepIndex * controls[0].Height;
  598. if (!e.ProcessType)
  599. {
  600. NewStepShow newStepShow = controls[0] as NewStepShow;
  601. if (e.Mesg == "镜头变焦")
  602. {
  603. string str1 = e.Value_ave == 0 ? "开启自动聚焦" : "关闭自动聚焦";
  604. string str2 = e.Value_up == 0 ? "自动变倍" : "手动变倍";
  605. string str3 = e.Value_low == 0 ? "自动Z轴聚焦" : "手动Z轴聚焦";
  606. string ShowData = e.Mesg + $"-{str1}-{str2}-{str3}";
  607. newStepShow.StepString = ShowData;
  608. }
  609. if (e.Mesg == "光源设置")
  610. {
  611. string ShowData = e.Mesg + $":通道号:{e.Value_up},亮度:{e.Value_low}";
  612. newStepShow.StepString = ShowData;
  613. }
  614. else
  615. {
  616. newStepShow.StepMax = e.Value_up;
  617. newStepShow.StepMin = e.Value_low;
  618. newStepShow.StepData = e.Value_ave;
  619. if (e.Value !=null && e.Value.Count > 0)
  620. {
  621. string ShowData = e.Mesg + $"1:{e.Value[0]}";
  622. for (int i = 1; i < e.Value.Count; i++)
  623. {
  624. ShowData += $",{e.Mesg}{i + 1}:{e.Value[i]}";
  625. }
  626. newStepShow.StepString = ShowData;
  627. }
  628. else
  629. newStepShow.StepString = e.Mesg;
  630. }
  631. if (e.ProcessSts == 1)
  632. newStepShow.StepStatus = NewStepShow.StepStsEnum.Testing;
  633. else if (e.ProcessSts == 2)
  634. newStepShow.StepStatus = NewStepShow.StepStsEnum.OK;
  635. else if (e.ProcessSts == 3)
  636. newStepShow.StepStatus = NewStepShow.StepStsEnum.NG;
  637. else if (e.ProcessSts == 0)
  638. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  639. else if (e.ProcessSts == 4)
  640. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  641. }
  642. else
  643. {
  644. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  645. newStepShowDef.StepString = e.Mesg;
  646. if (e.ProcessSts == 1)
  647. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Testing;
  648. else if (e.ProcessSts == 2)
  649. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.OK;
  650. else if (e.ProcessSts == 3)
  651. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.NG;
  652. else if (e.ProcessSts == 0)
  653. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  654. else if (e.ProcessSts == 4)
  655. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Error;
  656. if (e.Value_ave == 0)
  657. {
  658. newStepShowDef.StepSizeData = (int)e.Value_up;
  659. if (e.Value_up > 0)
  660. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.NG;
  661. else if (e.Value_up < 0)
  662. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  663. else if (e.Value_up == 0)
  664. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.OK;
  665. else
  666. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.Error;
  667. }
  668. else
  669. {
  670. if (e.Value_low == 0)
  671. newStepShowDef.StepDefectData = (int)e.Value_low;
  672. else if (e.Value_low > 0)
  673. newStepShowDef.StepDefectData = newStepShowDef.StepDefectData + (int)e.Value_low;
  674. //if (e.Value_low > 0)
  675. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.NG;
  676. //else if (e.Value_low < 0)
  677. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  678. //else if ((e.Value_low == 0)&&(e.Value_up == 0))
  679. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.OK;
  680. if ((e.Value_up == -1) && (e.Value_low == -1))
  681. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Error;
  682. else if (e.Value_up == 1)
  683. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Testing;
  684. else if (e.Value_up == 0)
  685. {
  686. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Done;
  687. newStepShowDef.StepDefectData = (int)e.Value_low;
  688. }
  689. }
  690. }
  691. }
  692. else if (e.Cmd == 31) //忽略流程 厚度, 张力, pt, 线宽显示
  693. {
  694. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex + 1), true);
  695. if (!e.ProcessType )
  696. {
  697. NewStepShow newStepShow = controls[0] as NewStepShow;
  698. newStepShow.StepMax = 0;
  699. newStepShow.StepMin = 0;
  700. newStepShow.StepData = 0;
  701. string ShowData = e.Mesg;
  702. newStepShow.StepString = ShowData;
  703. if (e.ProcessSts == 4)
  704. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  705. else
  706. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  707. }
  708. else
  709. {
  710. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  711. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  712. newStepShowDef.StepDefectData = -1;
  713. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  714. newStepShowDef.StepSizeData = -1;
  715. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  716. newStepShowDef.StepString = "未启用或被禁用";
  717. newStepShowDef.StepString = e.Mesg;
  718. }
  719. }
  720. Application.DoEvents();
  721. }
  722. catch { }
  723. }
  724. }
  725. void ShowNewStepProcess(List<StepProcess> list)
  726. {
  727. flpProcessStep.Controls.Clear();
  728. int index = 0;
  729. int splitWidth = 5;
  730. foreach (StepProcess stepProcess in list)
  731. {
  732. index++;
  733. if (stepProcess.ProcessCode != "SizeAndDefect")
  734. {
  735. NewStepShow newStepShow = new NewStepShow();
  736. newStepShow.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  737. newStepShow.StepName = stepProcess.ProcessName;
  738. newStepShow.StepIndex = index;
  739. newStepShow.StepMax = 0;
  740. newStepShow.StepMin = 0;
  741. newStepShow.StepData = 0;
  742. newStepShow.StepString = "";
  743. newStepShow.StepStatus = NewStepShow.StepStsEnum.Wait;
  744. newStepShow.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  745. newStepShow.Name = "Step_" + index;
  746. flpProcessStep.Controls.Add(newStepShow);
  747. }
  748. else
  749. {
  750. NewStepShowDefect newStepShowDefect = new NewStepShowDefect();
  751. newStepShowDefect.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  752. newStepShowDefect.StepName = stepProcess.ProcessName;
  753. newStepShowDefect.StepIndex = index;
  754. bool opensize = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenSize");
  755. newStepShowDefect.StepSizeSts = opensize ? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  756. newStepShowDefect.StepSizeData = -1;
  757. bool opendefect = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenDefect");
  758. newStepShowDefect.StepDefectSts = opendefect? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  759. newStepShowDefect.StepDefectData = -1;
  760. newStepShowDefect.StepString = "";
  761. newStepShowDefect.StepStatus = NewStepShowDefect.StepStsEnum.Wait;
  762. newStepShowDefect.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  763. newStepShowDefect.Name = "Step_" + index;
  764. flpProcessStep.Controls.Add(newStepShowDefect);
  765. }
  766. }
  767. }
  768. /// <summary>
  769. /// 缺陷小图多图显示
  770. /// </summary>
  771. /// <param name="sender"></param>
  772. /// <param name="e"></param>
  773. private void auto_ShowMoreImg(object sender, ImgEventArgs e)
  774. {
  775. ShowImgEvent(e);
  776. }
  777. private delegate void ShowImgEventDelegate(ImgEventArgs e);
  778. private void ShowImgEvent(ImgEventArgs e)
  779. {
  780. if (InvokeRequired)
  781. {
  782. ShowImgEventDelegate smd = new ShowImgEventDelegate(ShowImgEvent);
  783. this.BeginInvoke(smd, e);
  784. }
  785. else
  786. {
  787. //Task<int> tt = new Task<int>(() =>
  788. //{
  789. //lock (AddPicLock)
  790. {
  791. //加载缺陷小图
  792. //纵向显示
  793. int imgWidth = this.pnlBmpList.ClientSize.Width - 50;
  794. int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
  795. int splitWidth = 20;
  796. int pnlWidth = this.pnlBmpList.ClientSize.Width;
  797. int index = (int)this.gboxDefectList.Tag;
  798. //横向显示
  799. //int imgHeight = this.pnlBmpList.Height - 50;
  800. //int imgWidth = (int)((e.Bitmaps[0].Width * 1.0f / e.Bitmaps[0].Height) * imgHeight + 0.5);
  801. //int splitWidth = 20;
  802. //int pnlWidth = this.pnlBmpList.Height;
  803. //int index = (int)this.gboxDefectList.Tag;
  804. int len = e.Info.Count();
  805. int range = 100;
  806. int uselen = len > 100 ? 100 : len;
  807. for (int x = 0; x < uselen / range + 1; x++)
  808. {
  809. for (int i = 0; i < (x < (uselen / range) ? range : uselen % range); i++)
  810. {
  811. foreach (var item in e.Info[(x * range + i)]) //单个info[x] = {"1":[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]}
  812. {
  813. //统计缺陷类型
  814. SysMgr.Instance.countDefectClass(item.Value);//[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]
  815. //
  816. PictureBox picbox = new PictureBox();
  817. picbox.Width = imgWidth;
  818. picbox.Height = imgHeight;
  819. picbox.Image = (Bitmap)e.Bitmaps[(x * range + i)].Clone();
  820. picbox.Name = "imgDefect_" + index;
  821. picbox.Tag = item.Key + "," + e.X + "," + e.Y;
  822. picbox.Click += new EventHandler(defectBmpBox_Click);
  823. picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  824. picbox.BorderStyle = BorderStyle.FixedSingle;
  825. //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
  826. picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
  827. picbox.MouseHover += simpleTip_MouseHover;
  828. picbox.Visible = true;
  829. //this.Invoke(new MethodInvoker(() =>
  830. // {
  831. this.pnlBmpList.Controls.Add(picbox);
  832. //this.Refresh();
  833. //this.dgvProcess.Refresh();
  834. //this.lstLog.Refresh();
  835. //this.statusStrip1.Refresh();
  836. // }));
  837. break;
  838. }
  839. //
  840. index++;
  841. //Thread.Sleep(10);
  842. //Application.DoEvents();
  843. }
  844. //Application.DoEvents();
  845. //this.Invoke(new MethodInvoker(() =>
  846. //{
  847. //this.Refresh();
  848. pnlBmpList.VerticalScroll.Value = pnlBmpList.VerticalScroll.Maximum;
  849. //}));
  850. //Thread.Sleep(10);
  851. }
  852. //this.Invoke(new MethodInvoker(() =>
  853. //{
  854. //this.gboxDefectList.Tag = len + (int)this.gboxDefectList.Tag;
  855. this.gboxDefectList.Tag = index;
  856. this.gboxDefectList.Text = $"缺陷图像:{index} 张";
  857. }
  858. //}));
  859. //return 0;
  860. // });
  861. // tt.Start();
  862. // await tt;
  863. }
  864. }
  865. #endregion
  866. #region 工具栏
  867. private void tsbtnImpStop_Click(object sender, EventArgs e)
  868. {
  869. SysMgr.Instance.LedPause();
  870. AddTextEvent("急停", "手动急停", WarningEnum.High);
  871. SysMgr.Instance.StatusMgr.GotoWarning( WarningEnum.High, "急停", "手动急停");
  872. SysMgr.Instance.EmergencyStop();
  873. }
  874. private void tsbOpenLight_Click(object sender, EventArgs e)
  875. {
  876. if (this.tsbOpenLight.Text == "开灯")
  877. {
  878. SysMgr.Instance.OpenFloodlight(true);
  879. this.tsbOpenLight.Text = "关灯";
  880. }
  881. else
  882. {
  883. SysMgr.Instance.OpenFloodlight(false);
  884. this.tsbOpenLight.Text = "开灯";
  885. }
  886. }
  887. private void tsbtnStart_Click(object sender, EventArgs e)
  888. {
  889. if (!SysMgr.Instance.IsRuning)
  890. {
  891. //低报警自动复位
  892. if(SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  893. {
  894. if (SysMgr.Instance.StatusMgr.Warning == WarningEnum.Low)
  895. {
  896. SysMgr.Instance.StatusMgr.ClearWarning();
  897. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  898. }
  899. }
  900. //提示正在报警中
  901. if (SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  902. {
  903. FrmDialog.ShowDialog(this, "系统报警中!无法启动运行!", "警告", false);
  904. return;
  905. }
  906. if (SysMgr.Instance.StatusMgr.Status != SystemStsEnum.Pause)
  907. {
  908. ResetUI(false);
  909. AddTextEvent("运行", $"启动自动检测流程");
  910. this.lstLog.Refresh();
  911. if (SysMgr.Instance.StartRun(this, this.cbOrderCode.Text, this.cbProductCode.Text, this.cbProductSN.Text))
  912. {
  913. this.tsbtnStop.Enabled = true;
  914. this.tsbtnStart.Enabled = false;
  915. //锁定信息
  916. this.cbOrderCode.Enabled = false;
  917. this.cbProductCode.Enabled = false;
  918. this.cbProductSN.Enabled = false;
  919. //记录开始运行时间
  920. RunStartTime.Restart();
  921. }
  922. }
  923. else //暂停状态开始
  924. {
  925. if (SysMgr.Instance.ReStartRun())
  926. {
  927. this.tsbtnStop.Enabled = true;
  928. this.tsbtnStart.Enabled = false;
  929. }
  930. }
  931. }
  932. }
  933. private void tsbtnStop_Click(object sender, EventArgs e)
  934. {
  935. AddTextEvent("暂停", "手动暂停");
  936. this.tsbtnStart.Enabled = true;
  937. SysMgr.Instance.StatusMgr.GotoPause();
  938. SysMgr.Instance.LedPause();
  939. //this.tsbtnStart.Enabled = true;
  940. }
  941. private void tsbtnReset_Click(object sender, EventArgs e)
  942. {
  943. if (SystemIsRun())
  944. {
  945. DialogResult dr = DialogResult.Cancel;
  946. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统?", "警告", true);
  947. if (dr == DialogResult.OK)
  948. {
  949. this.tsbtnStart.Enabled = true;
  950. this.tsbtnStop.Enabled = false;
  951. Task.Factory.StartNew(() =>
  952. {
  953. SysMgr.Instance.LedRset(true);
  954. SysMgr.Instance.GotoReadyPosAndIO();
  955. SysMgr.Instance.LedRset(false);
  956. });
  957. ResetUI(true);
  958. AddTextEvent("复位", "复位完成");
  959. }
  960. }
  961. }
  962. private void tsbtnWarning_Click(object sender, EventArgs e)
  963. {
  964. if(SysMgr.Instance.StatusMgr.Warning != WarningEnum.Normal)
  965. {
  966. AddTextEvent("清除", "手动清除报警");
  967. SysMgr.Instance.StatusMgr.ClearWarning();
  968. SysMgr.Instance.LedReady();
  969. if (SysMgr.Instance.IsAuto)
  970. SysMgr.Instance.StatusMgr.GotoPause();
  971. else
  972. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  973. }
  974. }
  975. private void tsbGoHome_Click(object sender, EventArgs e)
  976. {
  977. if (SystemIsRun())
  978. {
  979. DialogResult dr = DialogResult.Cancel;
  980. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统所有硬件位置?", "警告", true);
  981. if (dr == DialogResult.OK)
  982. {
  983. this.tsbtnStart.Enabled = true;
  984. this.tsbtnStop.Enabled = false;
  985. this.Cursor = Cursors.WaitCursor;
  986. Task.Factory.StartNew(() =>
  987. {
  988. SysMgr.Instance.LedRset(true);
  989. SysMgr.Instance.AllResetAndGoHome();
  990. SysMgr.Instance.LedRset(false);
  991. });
  992. this.Cursor = Cursors.Default;
  993. }
  994. }
  995. }
  996. #endregion
  997. #region 小图操作
  998. private void defectBmpBox_Click(object sender, EventArgs e)
  999. {
  1000. PictureBox picbox = sender as PictureBox;
  1001. if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
  1002. {
  1003. //只查看
  1004. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1005. frm.ShowDialog(this);
  1006. }
  1007. else//完成
  1008. {
  1009. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1010. frm.ShowDialog(this);
  1011. }
  1012. }
  1013. private void simpleTip_MouseHover(object sender, EventArgs e)
  1014. {
  1015. PictureBox pb = sender as PictureBox;
  1016. // 创建the ToolTip
  1017. ToolTip toolTip1 = new ToolTip();
  1018. // 设置显示样式
  1019. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  1020. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  1021. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1022. toolTip1.ShowAlways = true;//是否显示提示框
  1023. // 设置伴随的对象.
  1024. toolTip1.SetToolTip(pb, pb.Name + "[" +pb.Tag.ToString() + "]");//设置提示按钮和提示内容
  1025. }
  1026. #endregion
  1027. #region 时钟捕获
  1028. GetPN pn = new GetPN();
  1029. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  1030. {
  1031. while (backgroundWorkerDo)
  1032. {
  1033. try
  1034. {
  1035. this.Invoke(new MethodInvoker(() =>
  1036. {
  1037. this.tsslLoginTime.Text = $" 当前时间:{DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss")}";
  1038. }));
  1039. //检测按钮和实时状态
  1040. if (SysMgr.Instance.IsInit)
  1041. {
  1042. bool sts = SysMgr.Instance.WarningShowLed(DisEnableBuzz);
  1043. if (sts)
  1044. {
  1045. this.Invoke(new MethodInvoker(() =>
  1046. {
  1047. this.tsbtnStart.Enabled = true;
  1048. this.tsbtnStop.Enabled = false;
  1049. }));
  1050. }
  1051. int stsno = 0;
  1052. stsno = SysMgr.Instance.ButtonIOTrg(DisEnableDoor);
  1053. if (stsno == 1)
  1054. {
  1055. this.Invoke(new MethodInvoker(() =>
  1056. {
  1057. tsbtnStart_Click(null, null);
  1058. }));
  1059. }
  1060. else if (stsno == 2)
  1061. {
  1062. this.Invoke(new MethodInvoker(() =>
  1063. {
  1064. this.tsbtnStart.Enabled = true;
  1065. }));
  1066. SysMgr.Instance.LedPause();
  1067. }
  1068. else if (stsno == 3)
  1069. {
  1070. this.Invoke(new MethodInvoker(() =>
  1071. {
  1072. tsbtnReset_Click(null, null);
  1073. }));
  1074. }
  1075. else if (stsno == 4) //老流程张力读取
  1076. {
  1077. TensionResult tensionResult;
  1078. if (SysMgr.Instance.TensionGetValue(out tensionResult) >= 0)
  1079. {
  1080. this.Invoke(new MethodInvoker(() =>
  1081. {
  1082. this.lblTension.Text = Math.Round(tensionResult.value, 2).ToString();
  1083. this.lblTension.ForeColor = tensionResult.color;
  1084. this.lblTensionMax.Text = Math.Round(tensionResult.valueMax, 2).ToString();
  1085. this.lblTensionMax.ForeColor = tensionResult.colorMax;
  1086. this.lblTensionMin.Text = Math.Round(tensionResult.valueMin, 2).ToString();
  1087. this.lblTensionMin.ForeColor = tensionResult.colorMin;
  1088. }));
  1089. }
  1090. }
  1091. else if (stsno == 5) //新流程张力读取
  1092. {
  1093. //this.Invoke(new MethodInvoker(() =>
  1094. //{
  1095. // tsbtnReset_Click(null, null);
  1096. //}));
  1097. }
  1098. //显示实际位置
  1099. this.Invoke(new MethodInvoker(() =>
  1100. {
  1101. tsAxisState.Text = SysMgr.Instance.GetAxisPos();
  1102. }));
  1103. }
  1104. if (pn.P(SysMgr.Instance.IsRuning))
  1105. {
  1106. //继续计时
  1107. RunStartTime.Start();
  1108. }
  1109. if (pn.N(SysMgr.Instance.IsRuning))
  1110. {
  1111. //停止计时
  1112. RunStartTime.Stop();
  1113. }
  1114. if (SysMgr.Instance.IsRuning)
  1115. {
  1116. //实时显示
  1117. RunStartTime.Stop();
  1118. this.Invoke(new MethodInvoker(() =>
  1119. {
  1120. tslabelTime.Text = "实时测试:" + ((double)RunStartTime.ElapsedMilliseconds / 1000.0).ToString("0.000") + "s";
  1121. //this.Refresh();
  1122. }));
  1123. RunStartTime.Start();
  1124. }
  1125. Thread.Sleep(100);
  1126. }
  1127. catch { }
  1128. }
  1129. }
  1130. /// <summary>
  1131. /// 信号上升沿下降沿捕获
  1132. /// </summary>
  1133. class GetPN
  1134. {
  1135. bool _P = false;
  1136. bool _N = false;
  1137. /// <summary>
  1138. /// 判断上升沿
  1139. /// </summary>
  1140. /// <param name="Value"></param>
  1141. /// <returns></returns>
  1142. public bool P(bool Value)
  1143. {
  1144. if (Value && !_P)
  1145. {
  1146. _P = true;
  1147. return true;
  1148. }
  1149. if (!Value)
  1150. _P = false;
  1151. return false;
  1152. }
  1153. /// <summary>
  1154. /// 判断下降沿
  1155. /// </summary>
  1156. /// <param name="Value"></param>
  1157. /// <returns></returns>
  1158. public bool N(bool Value)
  1159. {
  1160. if (!Value && _N)
  1161. {
  1162. _N = false;
  1163. return true;
  1164. }
  1165. if (Value)
  1166. _N = true;
  1167. return false;
  1168. }
  1169. }
  1170. #endregion
  1171. #region 料号和产品编码选择
  1172. private void txtProductCode_DoubleClick(object sender, EventArgs e)
  1173. {
  1174. string pdtName = SysMgr.Instance.SelectProduct();
  1175. if (!string.IsNullOrWhiteSpace(pdtName))
  1176. this.cbProductCode.Text = pdtName;
  1177. }
  1178. private void txtProductCode_TextChanged(object sender, EventArgs e)
  1179. {
  1180. }
  1181. private void txtProductSN_DoubleClick(object sender, EventArgs e)
  1182. {
  1183. InputFrm frm = new InputFrm(null, "请输入网版编码:");
  1184. if (frm.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(frm.inputData))
  1185. {
  1186. this.cbProductSN.Text = frm.inputData;
  1187. }
  1188. else
  1189. {
  1190. this.cbProductSN.Text = "";
  1191. }
  1192. }
  1193. private string[] pdtlistData;
  1194. private string[] snlistData;
  1195. private void LoadPdtList(List<string> list)
  1196. {
  1197. this.cbProductCode.Items.Clear();
  1198. this.pdtlistData = list.ToArray();
  1199. cbProductCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
  1200. cbProductCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1201. cbProductCode.KeyDown += CobList_KeyDown;
  1202. this.cbProductCode.Text = "";
  1203. cbProductCode.Focus();
  1204. cbProductCode.SelectAll();
  1205. }
  1206. private void LoadSNList(List<string> list)
  1207. {
  1208. this.cbProductSN.Items.Clear();
  1209. this.snlistData = list.ToArray();
  1210. cbProductSN.Items.AddRange(snlistData);//比使用DataSource速度要快一些
  1211. //cbProductSN.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1212. cbProductSN.KeyDown += CobList_KeyDown;
  1213. this.cbProductSN.Text = "";
  1214. cbProductSN.Focus();
  1215. cbProductSN.SelectAll();
  1216. }
  1217. private void CobList_KeyDown(object sender, KeyEventArgs e)
  1218. {
  1219. ComboBox ctrl = sender as ComboBox;
  1220. if (e.KeyCode == Keys.Enter)
  1221. {
  1222. if (ctrl.Items.Count == 1)
  1223. ctrl.Text = ctrl.Items[0].ToString();
  1224. }
  1225. }
  1226. private void cobList_TextUpdate(object sender, EventArgs e)
  1227. {
  1228. ComboBox ctrl = sender as ComboBox;
  1229. if (ctrl.Text != null)
  1230. {
  1231. string str = ctrl.Text; //获取cb_material控件输入内
  1232. //清空combobox
  1233. ctrl.DataSource = null;
  1234. ctrl.Items.Clear();
  1235. string[] workOrderFiltered;
  1236. if (ctrl.Name == "cbProductCode")
  1237. workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1238. else
  1239. workOrderFiltered = snlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1240. ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
  1241. // 不存在符合条件时
  1242. //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1243. ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
  1244. if (workOrderFiltered.Length > 0)
  1245. {
  1246. if (!ctrl.DroppedDown)
  1247. ctrl.DroppedDown = true; // 自动弹出下拉框
  1248. }
  1249. ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1250. }
  1251. }
  1252. #endregion
  1253. private void MainFrm_SizeChanged(object sender, EventArgs e)
  1254. {
  1255. if (this.WindowState == FormWindowState.Maximized)
  1256. {
  1257. this.WindowState = FormWindowState.Normal;
  1258. this.Top = 0;
  1259. this.Left = 0;
  1260. this.Width = SystemInformation.WorkingArea.Width;
  1261. this.Height = SystemInformation.WorkingArea.Height;
  1262. }
  1263. }
  1264. private void tsmSysUserMgr_Click(object sender, EventArgs e)
  1265. {
  1266. }
  1267. private void tabPage1_Resize(object sender, EventArgs e)
  1268. {
  1269. int allWidth = this.tabPage1.Width;
  1270. this.flpnlResultData.Width = allWidth;
  1271. kanban1.Width = kanban2.Width = kanban3.Width = kanban4.Width = kanban5.Width = kanban6.Width = (flpnlResultData.Width - 30) / 6;
  1272. tabControl1.Region = new Region(new RectangleF(this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height));
  1273. }
  1274. private void tabPage2_Resize(object sender, EventArgs e)
  1275. {
  1276. int allWidth = this.tabPage2.Width;
  1277. tabControl1.Region = new Region(new RectangleF(this.tabPage2.Left, this.tabPage2.Top, this.tabPage2.Width, this.tabPage2.Height));
  1278. }
  1279. private void MainFrm_Paint(object sender, PaintEventArgs e)
  1280. {
  1281. this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn;
  1282. this.chkBuzzer.Visible = ConfMgr.Instance.SysConfigParams.ShowBuzz;
  1283. this.chkDoorSensor.Visible = ConfMgr.Instance.SysConfigParams.ShowDoorAlm;
  1284. }
  1285. private void flpProcessStep_SizeChanged(object sender, EventArgs e)
  1286. {
  1287. int splitWidth = 5;
  1288. foreach (Control item in this.flpProcessStep.Controls)
  1289. {
  1290. item.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  1291. }
  1292. this.flpProcessStep.Refresh();
  1293. this.gpbProcessList.Refresh();
  1294. }
  1295. }
  1296. }