版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1642 строки
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. #endregion
  451. #region 显示图像和消息
  452. private void lstLog_DrawItem(object sender, DrawItemEventArgs e)
  453. {
  454. e.DrawBackground();
  455. if (e.Index < 0) return;
  456. try
  457. {
  458. string str = lstLog.Items[e.Index].ToString();
  459. e.Graphics.DrawString(str.Substring(1), e.Font,
  460. new SolidBrush(str[0] == 'R' ? Color.Red : (str[0] == 'Y' ? Color.Orange : Color.Black)),
  461. e.Bounds);
  462. }
  463. catch(Exception ex)
  464. {
  465. e.Graphics.DrawString(ex.Message, e.Font,
  466. new SolidBrush( Color.Red ),
  467. e.Bounds);
  468. }
  469. }
  470. /// <summary>
  471. /// 异步输出日志
  472. /// </summary>
  473. /// <param name="tag">模板标识</param>
  474. /// <param name="msg">内容</param>
  475. /// <param name="type"></param>
  476. private void AddTextEvent(string tag, string msg, WarningEnum level = WarningEnum.Normal)
  477. {
  478. lock (AddTextLock)
  479. {
  480. if (tag != null && tag != "")
  481. tag = $" - [{tag}]";
  482. var now = DateTime.Now;
  483. msg = now.ToString("HH:mm:ss fff") + tag + " - " + msg;
  484. msg = (level == WarningEnum.Normal ? "B" : level == WarningEnum.Low ? "Y" : "R") + msg;
  485. if (this.lstLog.Items.Count > 1000)
  486. this.lstLog.Items.Clear();
  487. lstLog.Items.Insert(0, msg);
  488. }
  489. }
  490. private void main_running(object sender, MainEventArgs e)
  491. {
  492. ShowMessage(e);
  493. }
  494. private delegate void ShowMessageDelegate(MainEventArgs e);
  495. private void ShowMessage(MainEventArgs e)
  496. {
  497. if (InvokeRequired)
  498. {
  499. ShowMessageDelegate smd = new ShowMessageDelegate(ShowMessage);
  500. this.BeginInvoke(smd, e);
  501. }
  502. else
  503. {
  504. AddTextEvent(e.Tag, e.Message, e.Warning);
  505. }
  506. }
  507. /// <summary>
  508. /// 自动运行流程显示
  509. /// </summary>
  510. /// <param name="sender"></param>
  511. /// <param name="e"></param>
  512. private void auto_runing(object sender, RunEventArgs e)
  513. {
  514. ShowUIEvent(e);
  515. }
  516. private delegate void ShowUIEventDelegate(RunEventArgs e);
  517. Bitmap bmp0;
  518. Bitmap bmp1;
  519. private void ShowUIEvent(RunEventArgs e)
  520. {
  521. if (InvokeRequired)
  522. {
  523. ShowUIEventDelegate smd = new ShowUIEventDelegate(ShowUIEvent);
  524. this.BeginInvoke(smd, e);
  525. }
  526. else
  527. {
  528. try
  529. {
  530. if (e.Cmd == 0) //显示SN和流程
  531. {
  532. this.cbProductSN.Text = e.SN;
  533. if (e.NewStep)
  534. {
  535. this.tabControl1.SelectTab(1);
  536. ShowNewStepProcess(e.StepProcessesList);
  537. }
  538. else
  539. {
  540. this.tabControl1.SelectTab(0);
  541. this.dgvProcess.DataSource = new BindingSource(e.StepProcessesList, null);
  542. }
  543. }
  544. else if (e.Cmd == 1) //显示当前运行步骤
  545. {
  546. this.dgvProcess.Rows[e.StepIndex].Selected = true;
  547. dgvProcess.CurrentCell = dgvProcess.Rows[e.StepIndex].Cells[1];
  548. }
  549. else if (e.Cmd == 2) //显示当前运行步骤 和步骤详情
  550. {
  551. this.dgvProcess.Rows[e.StepIndex].Cells["colValue"].Value = e.Mesg;
  552. }
  553. else if (e.Cmd == 3) //图纸比对结果
  554. {
  555. this.lblCompareResult.Text = (e.CompareResult ? "通过" : $"未通过");
  556. this.lblCompareResultCount.Text = e.Cnt.ToString();
  557. if (!e.CompareResult)
  558. {
  559. this.lblCompareResult.ForeColor = Color.Red;
  560. }
  561. else
  562. this.lblCompareResult.ForeColor = Color.Lime;
  563. }
  564. else if (e.Cmd == 4) //缺陷结果
  565. {
  566. lblDefectResult.Text = "未通过";
  567. lblDefectResultCount.Text = $"总数:{e.Cnt},详细:{e.CompareResultString}";
  568. this.toolTip1.SetToolTip(lblDefectResultCount, lblDefectResultCount.Text);
  569. this.lblDefectResult.Text = (e.CompareResult ? "通过" : "未通过");
  570. if (!e.CompareResult)
  571. {
  572. this.lblDefectResult.ForeColor = Color.Red;
  573. }
  574. else
  575. this.lblDefectResult.ForeColor = Color.Lime;
  576. }
  577. else if (e.Cmd == 5) //加载缺陷小图
  578. {
  579. ;
  580. }
  581. else if (e.Cmd == 6) //显示主图
  582. {
  583. if (e.PicIndex == 0)
  584. {
  585. bmp0 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  586. picScanner0.Image = bmp0;
  587. picScanner0.Refresh();
  588. }
  589. else
  590. {
  591. bmp1 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  592. picScanner1.Image = bmp1;
  593. picScanner1.Refresh();
  594. }
  595. }
  596. else if (e.Cmd == 7) //显示测试时间
  597. {
  598. lblTimeLen.Text = "检测时长: " + e.Time.ToString("0.000") + " 秒";
  599. }
  600. else if (e.Cmd == 8) //显示测试时间
  601. {
  602. lblOutput.Text = "当日产量: " + e.Num.ToString("0") + " 个";
  603. }
  604. else if (e.Cmd == 10) //测试结束
  605. {
  606. this.tsbtnStart.Enabled = true;
  607. this.tsbtnStop.Enabled = false;
  608. this.cbOrderCode.Enabled = true;
  609. this.cbProductCode.Enabled = true;
  610. this.cbProductSN.Enabled = true;
  611. }
  612. else if (e.Cmd == 21) //厚度显示
  613. {
  614. double value = Math.Round(e.Value.Average(), 2);
  615. double valueMax = e.Value.Max();
  616. double valueMin = e.Value.Min();
  617. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  618. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  619. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  620. this.lblHeight.Text = Math.Round(value, 2).ToString();
  621. this.lblHeight.ForeColor = color;
  622. this.lblHeightMax.Text = Math.Round(valueMax, 2).ToString();
  623. this.lblHeightMax.ForeColor = colorMax;
  624. this.lblHeightMin.Text = Math.Round(valueMin, 2).ToString();
  625. this.lblHeightMin.ForeColor = colorMin;
  626. }
  627. else if (e.Cmd == 22) //PT显示
  628. {
  629. double value = Math.Round(e.Value.Average(), 4);
  630. double valueMax = e.Value.Max();
  631. double valueMin = e.Value.Min();
  632. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  633. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  634. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  635. this.lblPT.Text = Math.Round(value, 4).ToString();
  636. this.lblPT.ForeColor = color;
  637. this.lblPTMax.Text = Math.Round(valueMax, 4).ToString();
  638. this.lblPTMax.ForeColor = colorMax;
  639. this.lblPTMin.Text = Math.Round(valueMin, 4).ToString();
  640. this.lblPTMin.ForeColor = colorMin;
  641. }
  642. else if (e.Cmd == 23) //线宽显示
  643. {
  644. double value = Math.Round(e.Value.Average(), 2);
  645. double valueMax = e.Value.Max();
  646. double valueMin = e.Value.Min();
  647. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  648. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  649. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  650. this.lblLineWidth.Text = Math.Round(value, 2).ToString();
  651. this.lblLineWidth.ForeColor = color;
  652. this.lblLineWidthMax.Text = Math.Round(valueMax, 2).ToString();
  653. this.lblLineWidthMax.ForeColor = colorMax;
  654. this.lblLineWidthMin.Text = Math.Round(valueMin, 2).ToString();
  655. this.lblLineWidthMin.ForeColor = colorMin;
  656. }
  657. else if (e.Cmd == 30) //新流程 厚度, 张力, pt, 线宽显示
  658. {
  659. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex +1), true);
  660. //滚动条滚动
  661. //int scrollStep = (this.flpProcessStep.VerticalScroll.Maximum / (flpProcessStep.Controls.Count - 1));
  662. this.flpProcessStep.VerticalScroll.Value = e.StepIndex * controls[0].Height > this.flpProcessStep.VerticalScroll.Maximum? this.flpProcessStep.VerticalScroll.Maximum: e.StepIndex * controls[0].Height;
  663. if (!e.ProcessType)
  664. {
  665. NewStepShow newStepShow = controls[0] as NewStepShow;
  666. if (e.Mesg == "镜头变焦")
  667. {
  668. string str1 = e.Value_ave == 0 ? "开启自动聚焦" : "关闭自动聚焦";
  669. string str2 = e.Value_up == 0 ? "自动变倍" : "手动变倍";
  670. string str3 = e.Value_low == 0 ? "自动Z轴聚焦" : "手动Z轴聚焦";
  671. string ShowData = e.Mesg + $"-{str1}-{str2}-{str3}";
  672. newStepShow.StepString = ShowData;
  673. }
  674. if (e.Mesg == "光源设置")
  675. {
  676. string ShowData = e.Mesg + $":通道号:{e.Value_up},亮度:{e.Value_low}";
  677. newStepShow.StepString = ShowData;
  678. }
  679. else
  680. {
  681. newStepShow.StepMax = e.Value_up;
  682. newStepShow.StepMin = e.Value_low;
  683. newStepShow.StepData = e.Value_ave;
  684. if (e.Value !=null && e.Value.Count > 0)
  685. {
  686. string ShowData = e.Mesg + $"1:{e.Value[0]}";
  687. for (int i = 1; i < e.Value.Count; i++)
  688. {
  689. ShowData += $",{e.Mesg}{i + 1}:{e.Value[i]}";
  690. }
  691. newStepShow.StepString = ShowData;
  692. }
  693. else
  694. newStepShow.StepString = e.Mesg;
  695. }
  696. if (e.ProcessSts == 1)
  697. newStepShow.StepStatus = NewStepShow.StepStsEnum.Testing;
  698. else if (e.ProcessSts == 2)
  699. newStepShow.StepStatus = NewStepShow.StepStsEnum.OK;
  700. else if (e.ProcessSts == 3)
  701. newStepShow.StepStatus = NewStepShow.StepStsEnum.NG;
  702. else if (e.ProcessSts == 0)
  703. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  704. else if (e.ProcessSts == 4)
  705. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  706. }
  707. else
  708. {
  709. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  710. newStepShowDef.StepString = e.Mesg;
  711. if (e.ProcessSts == 1)
  712. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Testing;
  713. else if (e.ProcessSts == 2)
  714. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.OK;
  715. else if (e.ProcessSts == 3)
  716. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.NG;
  717. else if (e.ProcessSts == 0)
  718. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  719. else if (e.ProcessSts == 4)
  720. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Error;
  721. if (e.Value_ave == 0)
  722. {
  723. newStepShowDef.StepSizeData = (int)e.Value_up;
  724. if (e.Value_up > 0)
  725. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.NG;
  726. else if (e.Value_up < 0)
  727. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  728. else if (e.Value_up == 0)
  729. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.OK;
  730. else
  731. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.Error;
  732. }
  733. else
  734. {
  735. if (e.Value_low == 0)
  736. newStepShowDef.StepDefectData = (int)e.Value_low;
  737. else if (e.Value_low > 0)
  738. newStepShowDef.StepDefectData = newStepShowDef.StepDefectData + (int)e.Value_low;
  739. //if (e.Value_low > 0)
  740. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.NG;
  741. //else if (e.Value_low < 0)
  742. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  743. //else if ((e.Value_low == 0)&&(e.Value_up == 0))
  744. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.OK;
  745. if ((e.Value_up == -1) && (e.Value_low == -1))
  746. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Error;
  747. else if (e.Value_up == 1)
  748. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Testing;
  749. else if (e.Value_up == 0)
  750. {
  751. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Done;
  752. newStepShowDef.StepDefectData = (int)e.Value_low;
  753. }
  754. }
  755. }
  756. }
  757. else if (e.Cmd == 31) //忽略流程 厚度, 张力, pt, 线宽显示
  758. {
  759. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex + 1), true);
  760. if (controls != null)
  761. {
  762. if (!e.ProcessType)
  763. {
  764. NewStepShow newStepShow = controls[0] as NewStepShow;
  765. newStepShow.StepMax = 0;
  766. newStepShow.StepMin = 0;
  767. newStepShow.StepData = 0;
  768. string ShowData = e.Mesg;
  769. newStepShow.StepString = ShowData;
  770. if (e.ProcessSts == 4)
  771. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  772. else
  773. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  774. }
  775. else
  776. {
  777. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  778. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  779. newStepShowDef.StepDefectData = -1;
  780. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  781. newStepShowDef.StepSizeData = -1;
  782. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  783. newStepShowDef.StepString = "未启用或被禁用";
  784. newStepShowDef.StepString = e.Mesg;
  785. }
  786. }
  787. }
  788. Application.DoEvents();
  789. }
  790. catch { }
  791. }
  792. }
  793. void ShowNewStepProcess(List<StepProcess> list)
  794. {
  795. flpProcessStep.Controls.Clear();
  796. int index = 0;
  797. int splitWidth = 5;
  798. foreach (StepProcess stepProcess in list)
  799. {
  800. index++;
  801. if (stepProcess.ProcessCode != "SizeAndDefect")
  802. {
  803. NewStepShow newStepShow = new NewStepShow();
  804. newStepShow.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  805. newStepShow.StepName = stepProcess.ProcessName;
  806. newStepShow.StepIndex = index;
  807. newStepShow.StepMax = 0;
  808. newStepShow.StepMin = 0;
  809. newStepShow.StepData = 0;
  810. newStepShow.StepString = "";
  811. newStepShow.StepStatus = NewStepShow.StepStsEnum.Wait;
  812. newStepShow.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  813. newStepShow.Name = "Step_" + index;
  814. flpProcessStep.Controls.Add(newStepShow);
  815. }
  816. else
  817. {
  818. NewStepShowDefect newStepShowDefect = new NewStepShowDefect();
  819. newStepShowDefect.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  820. newStepShowDefect.StepName = stepProcess.ProcessName;
  821. newStepShowDefect.StepIndex = index;
  822. bool opensize = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenSize");
  823. newStepShowDefect.StepSizeSts = opensize ? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  824. newStepShowDefect.StepSizeData = -1;
  825. bool opendefect = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenDefect");
  826. newStepShowDefect.StepDefectSts = opendefect? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  827. newStepShowDefect.StepDefectData = -1;
  828. newStepShowDefect.StepString = "";
  829. newStepShowDefect.StepStatus = NewStepShowDefect.StepStsEnum.Wait;
  830. newStepShowDefect.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  831. newStepShowDefect.Name = "Step_" + index;
  832. flpProcessStep.Controls.Add(newStepShowDefect);
  833. }
  834. }
  835. }
  836. /// <summary>
  837. /// 缺陷小图多图显示
  838. /// </summary>
  839. /// <param name="sender"></param>
  840. /// <param name="e"></param>
  841. private void auto_ShowMoreImg(object sender, ImgEventArgs e)
  842. {
  843. ShowImgEvent(e);
  844. }
  845. private delegate void ShowImgEventDelegate(ImgEventArgs e);
  846. private void ShowImgEvent(ImgEventArgs e)
  847. {
  848. if (InvokeRequired)
  849. {
  850. ShowImgEventDelegate smd = new ShowImgEventDelegate(ShowImgEvent);
  851. this.BeginInvoke(smd, e);
  852. }
  853. else
  854. {
  855. //Task<int> tt = new Task<int>(() =>
  856. //{
  857. //lock (AddPicLock)
  858. {
  859. //加载缺陷小图
  860. //纵向显示
  861. int imgWidth = this.pnlBmpList.ClientSize.Width - 50;
  862. int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
  863. int splitWidth = 20;
  864. int pnlWidth = this.pnlBmpList.ClientSize.Width;
  865. int index = (int)this.gboxDefectList.Tag;
  866. //横向显示
  867. //int imgHeight = this.pnlBmpList.Height - 50;
  868. //int imgWidth = (int)((e.Bitmaps[0].Width * 1.0f / e.Bitmaps[0].Height) * imgHeight + 0.5);
  869. //int splitWidth = 20;
  870. //int pnlWidth = this.pnlBmpList.Height;
  871. //int index = (int)this.gboxDefectList.Tag;
  872. int len = e.Info.Count();
  873. int range = 100;
  874. int uselen = len > 100 ? 100 : len;
  875. for (int x = 0; x < uselen / range + 1; x++)
  876. {
  877. for (int i = 0; i < (x < (uselen / range) ? range : uselen % range); i++)
  878. {
  879. foreach (var item in e.Info[(x * range + i)]) //单个info[x] = {"1":[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]}
  880. {
  881. //统计缺陷类型
  882. SysMgr.Instance.countDefectClass(item.Value);//[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]
  883. //
  884. PictureBox picbox = new PictureBox();
  885. picbox.Width = imgWidth;
  886. picbox.Height = imgHeight;
  887. picbox.Image = (Bitmap)e.Bitmaps[(x * range + i)].Clone();
  888. picbox.Name = "imgDefect_" + index;
  889. picbox.Tag = item.Key + "," + e.X + "," + e.Y;
  890. picbox.Click += new EventHandler(defectBmpBox_Click);
  891. picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  892. picbox.BorderStyle = BorderStyle.FixedSingle;
  893. //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
  894. picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
  895. picbox.MouseHover += simpleTip_MouseHover;
  896. picbox.Visible = true;
  897. //this.Invoke(new MethodInvoker(() =>
  898. // {
  899. this.pnlBmpList.Controls.Add(picbox);
  900. //this.Refresh();
  901. //this.dgvProcess.Refresh();
  902. //this.lstLog.Refresh();
  903. //this.statusStrip1.Refresh();
  904. // }));
  905. break;
  906. }
  907. //
  908. index++;
  909. //Thread.Sleep(10);
  910. //Application.DoEvents();
  911. }
  912. //Application.DoEvents();
  913. //this.Invoke(new MethodInvoker(() =>
  914. //{
  915. //this.Refresh();
  916. pnlBmpList.VerticalScroll.Value = pnlBmpList.VerticalScroll.Maximum;
  917. //}));
  918. //Thread.Sleep(10);
  919. }
  920. //this.Invoke(new MethodInvoker(() =>
  921. //{
  922. //this.gboxDefectList.Tag = len + (int)this.gboxDefectList.Tag;
  923. this.gboxDefectList.Tag = index;
  924. this.gboxDefectList.Text = $"缺陷图像:{index} 张";
  925. }
  926. //}));
  927. //return 0;
  928. // });
  929. // tt.Start();
  930. // await tt;
  931. }
  932. }
  933. /// <summary>
  934. /// 尺寸小图多图显示
  935. /// </summary>
  936. /// <param name="sender"></param>
  937. /// <param name="e"></param>
  938. private void auto_SizeShowMoreImg(object sender, ImgEventArgs e)
  939. {
  940. SizeShowImgEvent(e);
  941. }
  942. private delegate void SizeShowImgEventDelegate(ImgEventArgs e);
  943. private void SizeShowImgEvent(ImgEventArgs e)
  944. {
  945. if (InvokeRequired)
  946. {
  947. SizeShowImgEventDelegate smd = new SizeShowImgEventDelegate(SizeShowImgEvent);
  948. this.BeginInvoke(smd, e);
  949. }
  950. else
  951. {
  952. //Task<int> tt = new Task<int>(() =>
  953. //{
  954. //lock (AddPicLock)
  955. //加载缺陷小图
  956. //纵向显示
  957. int imgWidth = this.pnlSizeBmpList.ClientSize.Width - 50;
  958. int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
  959. int splitWidth = 20;
  960. int pnlWidth = this.pnlSizeBmpList.ClientSize.Width;
  961. int index = (int)this.gboxSizeDefectList.Tag;
  962. //
  963. PictureBox picbox = new PictureBox();
  964. picbox.Width = imgWidth;
  965. picbox.Height = imgHeight;
  966. picbox.Image = (Bitmap)e.Bitmaps[0].Clone();
  967. picbox.Name = "imgSize_" + index;
  968. picbox.Tag = e.Name;
  969. picbox.Click += new EventHandler(defectBmpBox2_Click);
  970. picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  971. picbox.BorderStyle = BorderStyle.FixedSingle;
  972. //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
  973. picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
  974. picbox.MouseHover += simpleTip_MouseHover;
  975. picbox.Visible = true;
  976. this.pnlSizeBmpList.Controls.Add(picbox);
  977. index++;
  978. pnlSizeBmpList.VerticalScroll.Value = pnlSizeBmpList.VerticalScroll.Maximum;
  979. this.gboxSizeDefectList.Tag = index;
  980. this.gboxSizeDefectList.Text = $"尺寸图像:{index} 张";
  981. }
  982. }
  983. #endregion
  984. #region 工具栏
  985. private void tsbtnImpStop_Click(object sender, EventArgs e)
  986. {
  987. SysMgr.Instance.LedPause();
  988. AddTextEvent("急停", "手动急停", WarningEnum.High);
  989. SysMgr.Instance.StatusMgr.GotoWarning( WarningEnum.High, "急停", "手动急停");
  990. SysMgr.Instance.SendStatus();
  991. SysMgr.Instance.EmergencyStop();
  992. }
  993. private void tsbOpenLight_Click(object sender, EventArgs e)
  994. {
  995. if (this.tsbOpenLight.Text == "开灯")
  996. {
  997. SysMgr.Instance.OpenFloodlight(true);
  998. this.tsbOpenLight.Text = "关灯";
  999. }
  1000. else
  1001. {
  1002. SysMgr.Instance.OpenFloodlight(false);
  1003. this.tsbOpenLight.Text = "开灯";
  1004. }
  1005. }
  1006. private void tsbtnStart_Click(object sender, EventArgs e)
  1007. {
  1008. if (!SysMgr.Instance.IsRuning)
  1009. {
  1010. //低报警自动复位
  1011. if(SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  1012. {
  1013. if (SysMgr.Instance.StatusMgr.Warning == WarningEnum.Low)
  1014. {
  1015. SysMgr.Instance.StatusMgr.ClearWarning();
  1016. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  1017. }
  1018. }
  1019. //提示正在报警中
  1020. if (SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  1021. {
  1022. FrmDialog.ShowDialog(this, "系统报警中!无法启动运行!", "警告", false);
  1023. return;
  1024. }
  1025. this.Cursor = Cursors.WaitCursor;
  1026. System.Windows.Forms.Application.DoEvents();
  1027. if (SysMgr.Instance.StatusMgr.Status != SystemStsEnum.Pause)
  1028. {
  1029. ResetUI(false);
  1030. AddTextEvent("运行", $"启动自动检测流程");
  1031. this.lstLog.Refresh();
  1032. if (SysMgr.Instance.StartRun(this, this.cbOrderCode.Text, (int)this.numDefectCnt.Value, this.cbProductCode.Text, this.cbProductSN.Text))
  1033. {
  1034. this.tsbtnStop.Enabled = true;
  1035. this.tsbtnStart.Enabled = false;
  1036. //锁定信息
  1037. this.cbOrderCode.Enabled = false;
  1038. this.cbProductCode.Enabled = false;
  1039. this.cbProductSN.Enabled = false;
  1040. //记录开始运行时间
  1041. RunStartTime.Restart();
  1042. }
  1043. }
  1044. else //暂停状态开始
  1045. {
  1046. if (SysMgr.Instance.ReStartRun())
  1047. {
  1048. this.tsbtnStop.Enabled = true;
  1049. this.tsbtnStart.Enabled = false;
  1050. }
  1051. }
  1052. this.Cursor = Cursors.Default;
  1053. }
  1054. }
  1055. private void tsbtnStop_Click(object sender, EventArgs e)
  1056. {
  1057. AddTextEvent("暂停", "手动暂停");
  1058. this.tsbtnStart.Enabled = true;
  1059. SysMgr.Instance.StatusMgr.GotoPause();
  1060. SysMgr.Instance.SendStatus();
  1061. SysMgr.Instance.LedPause();
  1062. //this.tsbtnStart.Enabled = true;
  1063. }
  1064. private void tsbtnReset_Click(object sender, EventArgs e)
  1065. {
  1066. if (SystemIsRun())
  1067. {
  1068. DialogResult dr = DialogResult.Cancel;
  1069. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统?", "警告", true);
  1070. if (dr == DialogResult.OK)
  1071. {
  1072. this.tsbtnStart.Enabled = true;
  1073. this.tsbtnStop.Enabled = false;
  1074. Task.Factory.StartNew(() =>
  1075. {
  1076. SysMgr.Instance.LedRset(true);
  1077. SysMgr.Instance.GotoReadyPosAndIO();
  1078. SysMgr.Instance.LedRset(false);
  1079. });
  1080. ResetUI(true);
  1081. //AddTextEvent("复位", "复位完成");
  1082. }
  1083. }
  1084. }
  1085. private void tsbtnWarning_Click(object sender, EventArgs e)
  1086. {
  1087. if(SysMgr.Instance.StatusMgr.Warning != WarningEnum.Normal)
  1088. {
  1089. AddTextEvent("清除", "手动清除报警");
  1090. SysMgr.Instance.StatusMgr.ClearWarning();
  1091. SysMgr.Instance.LedReady();
  1092. if (SysMgr.Instance.IsAuto)
  1093. SysMgr.Instance.StatusMgr.GotoPause();
  1094. else
  1095. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  1096. SysMgr.Instance.SendStatus();
  1097. }
  1098. }
  1099. private void tsbGoHome_Click(object sender, EventArgs e)
  1100. {
  1101. if (SystemIsRun())
  1102. {
  1103. DialogResult dr = DialogResult.Cancel;
  1104. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统所有硬件位置?", "警告", true);
  1105. if (dr == DialogResult.OK)
  1106. {
  1107. this.tsbtnStart.Enabled = true;
  1108. this.tsbtnStop.Enabled = false;
  1109. this.Cursor = Cursors.WaitCursor;
  1110. System.Windows.Forms.Application.DoEvents();
  1111. Task.Factory.StartNew(() =>
  1112. {
  1113. SysMgr.Instance.LedRset(true);
  1114. SysMgr.Instance.AllResetAndGoHome();
  1115. SysMgr.Instance.LedRset(false);
  1116. });
  1117. this.Cursor = Cursors.Default;
  1118. }
  1119. }
  1120. }
  1121. //缺陷+比对与图纸查看
  1122. private void tsbtnDefectImage_Click(object sender, EventArgs e)
  1123. {
  1124. try
  1125. {
  1126. string gbxBmpPath = "";
  1127. Order temp_order = null;
  1128. if (SysMgr.Instance.GetDefectDistribution(out gbxBmpPath, out temp_order))
  1129. {
  1130. //
  1131. ToolStripButton btn = sender as ToolStripButton;
  1132. DefectImageShowFrm frm = new DefectImageShowFrm(gbxBmpPath , temp_order, string.IsNullOrEmpty(btn.Tag.ToString()) ? 0 : Convert.ToInt32(btn.Tag.ToString()));
  1133. frm.Show();
  1134. }
  1135. }
  1136. catch (Exception ex)
  1137. {
  1138. MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
  1139. }
  1140. }
  1141. #endregion
  1142. #region 小图操作
  1143. private void defectBmpBox_Click(object sender, EventArgs e)
  1144. {
  1145. PictureBox picbox = sender as PictureBox;
  1146. if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
  1147. {
  1148. //只查看
  1149. AddTextEvent("查看", $"运行中查看缺陷{SysMgr.Instance.IsAuto} - {SysMgr.Instance.StatusMgr.Status}");
  1150. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1151. frm.ShowDialog(this);
  1152. }
  1153. else//完成
  1154. {
  1155. AddTextEvent("查看", $"查看缺陷{ConfMgr.Instance.SysConfigParams.OpenDefectSanp}");
  1156. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls,
  1157. Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]), ConfMgr.Instance.SysConfigParams.OpenDefectSanp);
  1158. frm.ShowDialog(this);
  1159. }
  1160. }
  1161. private void defectBmpBox2_Click(object sender, EventArgs e)
  1162. {
  1163. PictureBox picbox = sender as PictureBox;
  1164. if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
  1165. {
  1166. //只查看
  1167. AddTextEvent("查看", $"运行中查看缺陷{SysMgr.Instance.IsAuto} - {SysMgr.Instance.StatusMgr.Status}");
  1168. ImageShowFrm frm = new ImageShowFrm(this.pnlSizeBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1169. frm.ShowDialog(this);
  1170. }
  1171. else//完成
  1172. {
  1173. AddTextEvent("查看", $"查看缺陷{ConfMgr.Instance.SysConfigParams.OpenDefectSanp}");
  1174. ImageShowFrm frm = new ImageShowFrm(this.pnlSizeBmpList.Controls,
  1175. Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1176. frm.ShowDialog(this);
  1177. }
  1178. }
  1179. private void simpleTip_MouseHover(object sender, EventArgs e)
  1180. {
  1181. PictureBox pb = sender as PictureBox;
  1182. // 创建the ToolTip
  1183. ToolTip toolTip1 = new ToolTip();
  1184. // 设置显示样式
  1185. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  1186. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  1187. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1188. toolTip1.ShowAlways = true;//是否显示提示框
  1189. // 设置伴随的对象.
  1190. toolTip1.SetToolTip(pb, pb.Name + "[" +pb.Tag.ToString() + "]");//设置提示按钮和提示内容
  1191. }
  1192. #endregion
  1193. #region 时钟捕获
  1194. GetPN pn = new GetPN();
  1195. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  1196. {
  1197. while (backgroundWorkerDo)
  1198. {
  1199. try
  1200. {
  1201. this.Invoke(new MethodInvoker(() =>
  1202. {
  1203. this.tsslLoginTime.Text = $" 当前时间:{DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss")}";
  1204. }));
  1205. //检测按钮和实时状态
  1206. if (SysMgr.Instance.IsInit)
  1207. {
  1208. bool sts = SysMgr.Instance.WarningShowLed(DisEnableBuzz);
  1209. if (sts)
  1210. {
  1211. this.Invoke(new MethodInvoker(() =>
  1212. {
  1213. this.tsbtnStart.Enabled = true;
  1214. this.tsbtnStop.Enabled = false;
  1215. }));
  1216. }
  1217. int stsno = 0;
  1218. stsno = SysMgr.Instance.ButtonIOTrg(DisEnableDoor);
  1219. if (stsno == 1)
  1220. {
  1221. this.Invoke(new MethodInvoker(() =>
  1222. {
  1223. tsbtnStart_Click(null, null);
  1224. }));
  1225. }
  1226. else if (stsno == 2)
  1227. {
  1228. this.Invoke(new MethodInvoker(() =>
  1229. {
  1230. this.tsbtnStart.Enabled = true;
  1231. }));
  1232. SysMgr.Instance.LedPause();
  1233. }
  1234. else if (stsno == 3)
  1235. {
  1236. this.Invoke(new MethodInvoker(() =>
  1237. {
  1238. tsbtnReset_Click(null, null);
  1239. }));
  1240. }
  1241. else if (stsno == 4) //老流程张力读取
  1242. {
  1243. TensionResult tensionResult;
  1244. if (SysMgr.Instance.TensionGetValue(out tensionResult) >= 0)
  1245. {
  1246. this.Invoke(new MethodInvoker(() =>
  1247. {
  1248. this.lblTension.Text = Math.Round(tensionResult.value, 2).ToString();
  1249. this.lblTension.ForeColor = tensionResult.color;
  1250. this.lblTensionMax.Text = Math.Round(tensionResult.valueMax, 2).ToString();
  1251. this.lblTensionMax.ForeColor = tensionResult.colorMax;
  1252. this.lblTensionMin.Text = Math.Round(tensionResult.valueMin, 2).ToString();
  1253. this.lblTensionMin.ForeColor = tensionResult.colorMin;
  1254. }));
  1255. }
  1256. }
  1257. else if (stsno == 5) //新流程张力读取
  1258. {
  1259. //this.Invoke(new MethodInvoker(() =>
  1260. //{
  1261. // tsbtnReset_Click(null, null);
  1262. //}));
  1263. }
  1264. //显示实际位置
  1265. this.Invoke(new MethodInvoker(() =>
  1266. {
  1267. tsAxisState.Text = SysMgr.Instance.GetAxisPos();
  1268. }));
  1269. }
  1270. if (pn.P(SysMgr.Instance.IsRuning))
  1271. {
  1272. //继续计时
  1273. RunStartTime.Start();
  1274. }
  1275. if (pn.N(SysMgr.Instance.IsRuning))
  1276. {
  1277. //停止计时
  1278. RunStartTime.Stop();
  1279. }
  1280. if (SysMgr.Instance.IsRuning)
  1281. {
  1282. //实时显示
  1283. RunStartTime.Stop();
  1284. this.Invoke(new MethodInvoker(() =>
  1285. {
  1286. tslabelTime.Text = "实时测试:" + ((double)RunStartTime.ElapsedMilliseconds / 1000.0).ToString("0.000") + "s";
  1287. //this.Refresh();
  1288. }));
  1289. RunStartTime.Start();
  1290. }
  1291. Thread.Sleep(100);
  1292. }
  1293. catch { }
  1294. }
  1295. }
  1296. /// <summary>
  1297. /// 信号上升沿下降沿捕获
  1298. /// </summary>
  1299. class GetPN
  1300. {
  1301. bool _P = false;
  1302. bool _N = false;
  1303. /// <summary>
  1304. /// 判断上升沿
  1305. /// </summary>
  1306. /// <param name="Value"></param>
  1307. /// <returns></returns>
  1308. public bool P(bool Value)
  1309. {
  1310. if (Value && !_P)
  1311. {
  1312. _P = true;
  1313. return true;
  1314. }
  1315. if (!Value)
  1316. _P = false;
  1317. return false;
  1318. }
  1319. /// <summary>
  1320. /// 判断下降沿
  1321. /// </summary>
  1322. /// <param name="Value"></param>
  1323. /// <returns></returns>
  1324. public bool N(bool Value)
  1325. {
  1326. if (!Value && _N)
  1327. {
  1328. _N = false;
  1329. return true;
  1330. }
  1331. if (Value)
  1332. _N = true;
  1333. return false;
  1334. }
  1335. }
  1336. #endregion
  1337. #region 料号和产品编码选择
  1338. private void txtProductCode_DoubleClick(object sender, EventArgs e)
  1339. {
  1340. string pdtName = SysMgr.Instance.SelectProduct();
  1341. if (!string.IsNullOrWhiteSpace(pdtName))
  1342. this.cbProductCode.Text = pdtName;
  1343. }
  1344. private void txtProductCode_TextChanged(object sender, EventArgs e)
  1345. {
  1346. }
  1347. private void txtProductSN_DoubleClick(object sender, EventArgs e)
  1348. {
  1349. InputFrm frm = new InputFrm(null, "请输入网版编码:");
  1350. if (frm.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(frm.inputData))
  1351. {
  1352. this.cbProductSN.Text = frm.inputData;
  1353. }
  1354. else
  1355. {
  1356. this.cbProductSN.Text = "";
  1357. }
  1358. }
  1359. private string[] pdtlistData;
  1360. private string[] snlistData;
  1361. private void LoadPdtList(List<string> list)
  1362. {
  1363. this.cbProductCode.Items.Clear();
  1364. this.pdtlistData = list.ToArray();
  1365. cbProductCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
  1366. cbProductCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1367. cbProductCode.KeyDown += CobList_KeyDown;
  1368. this.cbProductCode.Text = "";
  1369. cbProductCode.Focus();
  1370. cbProductCode.SelectAll();
  1371. }
  1372. private void LoadSNList(List<string> list)
  1373. {
  1374. this.cbProductSN.Items.Clear();
  1375. this.snlistData = list.ToArray();
  1376. cbProductSN.Items.AddRange(snlistData);//比使用DataSource速度要快一些
  1377. //cbProductSN.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1378. cbProductSN.KeyDown += CobList_KeyDown;
  1379. this.cbProductSN.Text = "";
  1380. cbProductSN.Focus();
  1381. cbProductSN.SelectAll();
  1382. }
  1383. private void CobList_KeyDown(object sender, KeyEventArgs e)
  1384. {
  1385. ComboBox ctrl = sender as ComboBox;
  1386. if (e.KeyCode == Keys.Enter)
  1387. {
  1388. if (ctrl.Items.Count == 1)
  1389. ctrl.Text = ctrl.Items[0].ToString();
  1390. }
  1391. }
  1392. private void cobList_TextUpdate(object sender, EventArgs e)
  1393. {
  1394. ComboBox ctrl = sender as ComboBox;
  1395. if (ctrl.Text != null)
  1396. {
  1397. string str = ctrl.Text; //获取cb_material控件输入内
  1398. //清空combobox
  1399. ctrl.DataSource = null;
  1400. ctrl.Items.Clear();
  1401. string[] workOrderFiltered;
  1402. if (ctrl.Name == "cbProductCode")
  1403. workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1404. else
  1405. workOrderFiltered = snlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1406. ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
  1407. // 不存在符合条件时
  1408. //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1409. ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
  1410. if (workOrderFiltered.Length > 0)
  1411. {
  1412. if (!ctrl.DroppedDown)
  1413. ctrl.DroppedDown = true; // 自动弹出下拉框
  1414. }
  1415. ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1416. }
  1417. }
  1418. #endregion
  1419. #region 界面变化
  1420. private void MainFrm_SizeChanged(object sender, EventArgs e)
  1421. {
  1422. if (this.WindowState == FormWindowState.Maximized)
  1423. {
  1424. this.WindowState = FormWindowState.Normal;
  1425. this.Top = 0;
  1426. this.Left = 0;
  1427. this.Width = SystemInformation.WorkingArea.Width;
  1428. this.Height = SystemInformation.WorkingArea.Height;
  1429. }
  1430. }
  1431. private void tsmSysUserMgr_Click(object sender, EventArgs e)
  1432. {
  1433. }
  1434. private void tabPage1_Resize(object sender, EventArgs e)
  1435. {
  1436. int allWidth = this.tabPage1.Width;
  1437. this.flpnlResultData.Width = allWidth;
  1438. kanban1.Width = kanban2.Width = kanban3.Width = kanban4.Width = kanban5.Width = kanban6.Width = (flpnlResultData.Width - 30) / 6;
  1439. tabControl1.Region = new Region(new RectangleF(this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height));
  1440. }
  1441. private void tabPage2_Resize(object sender, EventArgs e)
  1442. {
  1443. int allWidth = this.tabPage2.Width;
  1444. tabControl1.Region = new Region(new RectangleF(this.tabPage2.Left, this.tabPage2.Top, this.tabPage2.Width, this.tabPage2.Height));
  1445. }
  1446. private void MainFrm_Paint(object sender, PaintEventArgs e)
  1447. {
  1448. this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn;
  1449. this.chkBuzzer.Visible = ConfMgr.Instance.SysConfigParams.ShowBuzz;
  1450. this.chkDoorSensor.Visible = ConfMgr.Instance.SysConfigParams.ShowDoorAlm;
  1451. this.tsbtnDefectImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1452. this.tsbtnSizeImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1453. toolStripSeparator7.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1454. this.tsbCC.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn;
  1455. this.tsbQX.Visible = ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1456. toolStripSeparator8.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn || ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1457. }
  1458. private void flpProcessStep_SizeChanged(object sender, EventArgs e)
  1459. {
  1460. int splitWidth = 5;
  1461. foreach (Control item in this.flpProcessStep.Controls)
  1462. {
  1463. item.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  1464. }
  1465. this.flpProcessStep.Refresh();
  1466. this.gpbProcessList.Refresh();
  1467. }
  1468. private void cbProductSN_MouseDoubleClick(object sender, MouseEventArgs e)
  1469. {
  1470. this.cbProductSN.Text = "";
  1471. this.cbProductSN.Select();
  1472. }
  1473. #endregion
  1474. }
  1475. }