版博士V2.0程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

1669 linhas
70 KiB

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