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

1672 lines
70 KiB

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