add stop button, button lock

This commit is contained in:
2025-11-04 09:45:39 +08:00
parent 506f537347
commit 6c3d42328f
3 changed files with 4756 additions and 4737 deletions

View File

@@ -101,6 +101,7 @@
this.menuStrip_topmenu = new System.Windows.Forms.MenuStrip(); this.menuStrip_topmenu = new System.Windows.Forms.MenuStrip();
this.tableLayoutPanel_mainForm = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel_mainForm = new System.Windows.Forms.TableLayoutPanel();
this.panel_midup = new System.Windows.Forms.Panel(); this.panel_midup = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox(); this.listBox1 = new System.Windows.Forms.ListBox();
this.btn_StarDet_manual = new System.Windows.Forms.Button(); this.btn_StarDet_manual = new System.Windows.Forms.Button();
this.panel_log = new System.Windows.Forms.Panel(); this.panel_log = new System.Windows.Forms.Panel();
@@ -1005,6 +1006,7 @@
// //
// panel_midup // panel_midup
// //
this.panel_midup.Controls.Add(this.button1);
this.panel_midup.Controls.Add(this.listBox1); this.panel_midup.Controls.Add(this.listBox1);
this.panel_midup.Controls.Add(this.btn_StarDet_manual); this.panel_midup.Controls.Add(this.btn_StarDet_manual);
this.panel_midup.Controls.Add(this.lbl_RShow); this.panel_midup.Controls.Add(this.lbl_RShow);
@@ -1025,6 +1027,21 @@
this.panel_midup.Size = new System.Drawing.Size(801, 388); this.panel_midup.Size = new System.Drawing.Size(801, 388);
this.panel_midup.TabIndex = 33; this.panel_midup.TabIndex = 33;
// //
// button1
//
this.button1.BackColor = System.Drawing.Color.LimeGreen;
this.button1.Enabled = false;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button1.Location = new System.Drawing.Point(371, 207);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(149, 46);
this.button1.TabIndex = 27;
this.button1.Text = "手动停止";
this.toolTip.SetToolTip(this.button1, "此操作为当前暂定方式");
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1 // listBox1
// //
this.listBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.listBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -1040,7 +1057,7 @@
this.btn_StarDet_manual.BackColor = System.Drawing.Color.LimeGreen; this.btn_StarDet_manual.BackColor = System.Drawing.Color.LimeGreen;
this.btn_StarDet_manual.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_StarDet_manual.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_StarDet_manual.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_StarDet_manual.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btn_StarDet_manual.Location = new System.Drawing.Point(339, 210); this.btn_StarDet_manual.Location = new System.Drawing.Point(191, 207);
this.btn_StarDet_manual.Name = "btn_StarDet_manual"; this.btn_StarDet_manual.Name = "btn_StarDet_manual";
this.btn_StarDet_manual.Size = new System.Drawing.Size(149, 46); this.btn_StarDet_manual.Size = new System.Drawing.Size(149, 46);
this.btn_StarDet_manual.TabIndex = 25; this.btn_StarDet_manual.TabIndex = 25;
@@ -1206,6 +1223,7 @@
private System.Windows.Forms.ToolTip toolTip; private System.Windows.Forms.ToolTip toolTip;
private System.Windows.Forms.ListView list_Log; private System.Windows.Forms.ListView list_Log;
private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
} }
} }

View File

@@ -121,11 +121,6 @@ namespace TetraPackOCR
#region #region
//private void MainPage_SizeChanged(object sender, EventArgs e)
//{
// asf.controlAutoSize(this);
//}
/// <summary> /// <summary>
/// 窗体加载 /// 窗体加载
/// </summary> /// </summary>
@@ -139,7 +134,10 @@ namespace TetraPackOCR
btn_manualOcr.Enabled = false; btn_manualOcr.Enabled = false;
check_Autorun.Enabled = false; check_Autorun.Enabled = false;
btn_StarDet_manual.Enabled = false; btn_StarDet_manual.Enabled = false;
//asf.controllInitializeSize(this); btn_StarDet_manual.BackColor = Color.LightGray;
button1.BackColor = Color.LightGray;
btn_OrderNum.Enabled = false;
btn_OrderNum.BackColor = Color.LightGray;
log.Info("软件正在加载..."); log.Info("软件正在加载...");
this.Enabled = false; this.Enabled = false;
Action action = (() => Action action = (() =>
@@ -160,7 +158,7 @@ namespace TetraPackOCR
InitializeCC24(); InitializeCC24();
log.Info("模型文件加载完成"); log.Info("模型文件加载完成");
this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\ON.png"); this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\ON.png");
this.ttls_SystemStatusShow.Visible = true; this.ttls_SystemStatusShow.Visible = true;
@@ -172,6 +170,8 @@ namespace TetraPackOCR
check_Autorun.Enabled = true; check_Autorun.Enabled = true;
//btn_StarDet_manual.Enabled = true; //btn_StarDet_manual.Enabled = true;
this.Enabled = true; this.Enabled = true;
btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
})); }));
}); });
@@ -220,27 +220,13 @@ namespace TetraPackOCR
try try
{ {
//if (myJob1.AcqFifo.FrameGrabber != null)
//{
// myJob1.AcqFifo.FrameGrabber.Disconnect(true);
//}
//if (myJob2.AcqFifo.FrameGrabber != null)
//{
// myJob2.AcqFifo.FrameGrabber.Disconnect(true);
//}
ClossCam(); ClossCam();
//// 注销结果队列事件 //// 注销结果队列事件
myJobManager1.UserResultAvailable -= new CogJobManager.CogUserResultAvailableEventHandler(DetResult); myJobManager1.UserResultAvailable -= new CogJobManager.CogUserResultAvailableEventHandler(DetResult);
myJobManager1.Shutdown(); myJobManager1.Shutdown();
CloseCC24(); CloseCC24();
//Application.DoEvents();
//System.Environment.Exit(0);
} }
catch catch
{ {
@@ -389,7 +375,6 @@ namespace TetraPackOCR
bmp = e.GrabResult.ToBitmap(true); bmp = e.GrabResult.ToBitmap(true);
OCRResult(bmp); OCRResult(bmp);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -512,8 +497,6 @@ namespace TetraPackOCR
bmp = e.GrabResult.ToBitmap(true); bmp = e.GrabResult.ToBitmap(true);
//Bitmap bmp = new Bitmap(cogimg.ToBitmap()); //Bitmap bmp = new Bitmap(cogimg.ToBitmap());
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
@@ -548,12 +531,26 @@ namespace TetraPackOCR
} }
catch (Exception ex) catch (Exception ex)
{ {
EnableStartDetect();
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString());
} }
} }
#endregion #endregion
private void EnableStartDetect()
{
if (InvokeRequired)
{
BeginInvoke(new Action(EnableStartDetect));
return;
}
btn_StarDet_manual.Enabled = true;
btn_StarDet_manual.BackColor = Color.LimeGreen;
button1.Enabled = false;
button1.BackColor = Color.LightGray;
}
#region #region
void ClossCam() void ClossCam()
{ {
@@ -635,6 +632,7 @@ namespace TetraPackOCR
this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\OFF.png"); this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\OFF.png");
this.panel_Manual.Visible = true; this.panel_Manual.Visible = true;
this.btn_StarDet_manual.Enabled = false; this.btn_StarDet_manual.Enabled = false;
btn_StarDet_manual.BackColor = Color.LightGray;
this.ttls_PCLStatusShow.Visible = false; this.ttls_PCLStatusShow.Visible = false;
} }
else if (!check_Autorun.Checked) else if (!check_Autorun.Checked)
@@ -644,7 +642,10 @@ namespace TetraPackOCR
this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\ON.png"); this.check_Autorun.BackgroundImage = Image.FromFile(Application.StartupPath + "\\logo_image\\ON.png");
this.panel_Manual.Visible = false; this.panel_Manual.Visible = false;
if (orderLoaded) if (orderLoaded)
{
this.btn_StarDet_manual.Enabled = true; this.btn_StarDet_manual.Enabled = true;
btn_StarDet_manual.BackColor = Color.LimeGreen;
}
this.ttls_PCLStatusShow.Visible = true; this.ttls_PCLStatusShow.Visible = true;
} }
} }
@@ -660,8 +661,10 @@ namespace TetraPackOCR
{ {
try try
{ {
button1.Enabled = false;
orderLoaded = false; orderLoaded = false;
btn_StarDet_manual.Enabled = false; btn_StarDet_manual.Enabled = false;
btn_StarDet_manual.BackColor = Color.LightGray;
listBox1.Items.Clear(); listBox1.Items.Clear();
ocrTextRequest.Clear(); ocrTextRequest.Clear();
ClearData(); ClearData();
@@ -688,12 +691,14 @@ namespace TetraPackOCR
this.lbl_L9_verOcrRs.BackColor = Color.Gray; this.lbl_L9_verOcrRs.BackColor = Color.Gray;
})); }));
this.btn_OrderNum.Enabled = false; this.btn_OrderNum.Enabled = false;
btn_OrderNum.BackColor = Color.LightGray;
//通过订单号获取表格中需要的值 //通过订单号获取表格中需要的值
string order = txt_OrderNum.Text; string order = txt_OrderNum.Text;
if (string.IsNullOrEmpty(order)) if (string.IsNullOrEmpty(order))
{ {
log.Warn("订单号为空,请输入订单号。"); log.Warn("订单号为空,请输入订单号。");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
string laststr; string laststr;
@@ -779,8 +784,9 @@ namespace TetraPackOCR
} }
if (string.IsNullOrEmpty(ProductStandard)) if (string.IsNullOrEmpty(ProductStandard))
{ {
log.Debug("请检查订单号是否正确"); log.Debug("ProductStandard未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
//根据产品规格获取距离坐标 //根据产品规格获取距离坐标
@@ -806,16 +812,18 @@ namespace TetraPackOCR
} }
if (DistX == 0 || DistY == 0) if (DistX == 0 || DistY == 0)
{ {
log.Debug("请检查订单号是否正确"); log.Debug("DistXDistY未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
log.Info("相关数据已获取完成,且已显示在界面中,请查看。"); log.Info("相关数据已获取完成,且已显示在界面中,请查看。");
} }
else else
{ {
log.Debug("请检查订单号是否正确"); log.Debug("QSV未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
} }
@@ -883,8 +891,9 @@ namespace TetraPackOCR
} }
if (string.IsNullOrEmpty(ProductStandard)) if (string.IsNullOrEmpty(ProductStandard))
{ {
log.Debug("请检查订单号是否正确"); log.Debug("ProductStandard未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
//根据产品规格获取距离坐标 //根据产品规格获取距离坐标
@@ -910,16 +919,18 @@ namespace TetraPackOCR
} }
if (DistX == 0 || DistY == 0) if (DistX == 0 || DistY == 0)
{ {
log.Debug("请检查订单号是否正确"); log.Debug("DistXDistY未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
log.Info("相关数据已获取完成,且已显示在界面中,请查看。"); log.Info("相关数据已获取完成,且已显示在界面中,请查看。");
} }
else else
{ {
log.Debug("请检查订单号是否正确"); log.Debug("QSV未找到请检查订单号是否正确");
btn_OrderNum.Enabled = true; btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
return; return;
} }
} }
@@ -1066,13 +1077,16 @@ namespace TetraPackOCR
} }
this.btn_OrderNum.Enabled = true; this.btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
orderLoaded = true; orderLoaded = true;
btn_StarDet_manual.Enabled = true; btn_StarDet_manual.Enabled = true;
btn_StarDet_manual.BackColor = Color.LimeGreen;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error(ex.Message + "请检查订单号是否正确,数据表中并无此订单号"); log.Error("数据解析错误,请检查订单号是否正确");
this.btn_OrderNum.Enabled = true; this.btn_OrderNum.Enabled = true;
btn_OrderNum.BackColor = Color.DeepSkyBlue;
} }
} }
/// <summary> /// <summary>
@@ -1097,7 +1111,12 @@ namespace TetraPackOCR
} }
private void btn_StarDet_manual_Click(object sender, EventArgs e) private void btn_StarDet_manual_Click(object sender, EventArgs e)
{ {
m_dev_cam1.ExecuteSoftwareTrigger(); btn_StarDet_manual.Enabled = false;
button1.Enabled = true;
btn_StarDet_manual.BackColor = Color.LightGray;
button1.BackColor = Color.LimeGreen;
m_dev_cam1?.ExecuteSoftwareTrigger();
list_Log.Clear();
log.Info("手动触发开始"); log.Info("手动触发开始");
} }
@@ -1243,28 +1262,6 @@ namespace TetraPackOCR
CogPMAlignTool myPMA = myTB.Tools["CogPMAlignTool2"] as CogPMAlignTool; CogPMAlignTool myPMA = myTB.Tools["CogPMAlignTool2"] as CogPMAlignTool;
CogImageConvertTool myImage = myTB.Tools["CogImageConvertTool1"] as CogImageConvertTool; CogImageConvertTool myImage = myTB.Tools["CogImageConvertTool1"] as CogImageConvertTool;
////把vpro图像转为bitmap
//ICogImage cogimg = myImage.OutputImage;
//Bitmap bmp = new Bitmap(cogimg.ToBitmap());
//MemoryStream ms = new MemoryStream();
//bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
//byte[] bytes = ms.GetBuffer();
//ms.Close();
////保存DET图像
//if (!Directory.Exists(SaveImageFileDET))
//{
// Directory.CreateDirectory(SaveImageFileDET);
//}
//string strTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
//FileStream fs = new FileStream(SaveImageFileDET + '\\' + strTime + ".bmp", FileMode.Create);
//BinaryWriter bw = new BinaryWriter(fs);
//bw.Write(bytes, 0, bytes.Length);
//bw.Close();
//fs.Close();
//log.Info("定位存图已完成");
Location_Display.Image = myPMA.InputImage; Location_Display.Image = myPMA.InputImage;
Location_Display.StaticGraphics.Clear(); Location_Display.StaticGraphics.Clear();
Location_Display.InteractiveGraphics.Clear(); Location_Display.InteractiveGraphics.Clear();
@@ -1292,11 +1289,13 @@ namespace TetraPackOCR
} }
else else
{ {
EnableStartDetect();
log.Info("没有定位到K标志,请查看图像或相机是否正常"); log.Info("没有定位到K标志,请查看图像或相机是否正常");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
EnableStartDetect();
log.Error(ex.Message + "未检测到K标志"); log.Error(ex.Message + "未检测到K标志");
if (this.check_Autorun.Checked == false) if (this.check_Autorun.Checked == false)
{ {
@@ -1456,12 +1455,6 @@ namespace TetraPackOCR
return; return;
} }
//CogToolGroup myTG = myJob2.VisionTool as CogToolGroup;
//CogAcqFifoTool myImage = myTG.Tools["CogAcqFifoTool1"] as CogAcqFifoTool;
//把vpro图像先转为bitmap
//ICogImage cogimg = myImage.OutputImage;
//Bitmap bmp = new Bitmap(cogimg.ToBitmap()); //有时会丢图cogimg为空改为SDK取图
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer(); byte[] bytes = ms.GetBuffer();
@@ -1690,6 +1683,15 @@ namespace TetraPackOCR
return matrix[rowSize, columnSize]; return matrix[rowSize, columnSize];
} }
private void button1_Click(object sender, EventArgs e)
{
btn_StarDet_manual.Enabled = true;
button1.Enabled = false;
btn_StarDet_manual.BackColor = Color.LimeGreen;
button1.BackColor = Color.LightGray;
}
/// <summary> /// <summary>
/// 将结果显示在对应状态栏 /// 将结果显示在对应状态栏
/// </summary> /// </summary>
@@ -1937,6 +1939,7 @@ namespace TetraPackOCR
log.Info("PC接收PLC数据数据内容" + mMatchingStr); log.Info("PC接收PLC数据数据内容" + mMatchingStr);
if (NumberOfLanes + 1 == mMatchingStr) if (NumberOfLanes + 1 == mMatchingStr)
{ {
EnableStartDetect();
if (ocrAcc.Count == 0) if (ocrAcc.Count == 0)
return; return;
if (ocrAcc.Min() < 0.95) if (ocrAcc.Min() < 0.95)
@@ -2178,6 +2181,7 @@ namespace TetraPackOCR
log.Info("第" + (item + 1) + "组坐标为X" + ocrxx[item] + ",Y:" + ocryy[item] + "。"); log.Info("第" + (item + 1) + "组坐标为X" + ocrxx[item] + ",Y:" + ocryy[item] + "。");
if (ocrxx[item] < 0 || ocrxx[item] > 1200) if (ocrxx[item] < 0 || ocrxx[item] > 1200)
{ {
EnableStartDetect();
log.Error("x范围 0,1200"); log.Error("x范围 0,1200");
byte[] datax = DataConverter.FloatToByte(0.0f, true); byte[] datax = DataConverter.FloatToByte(0.0f, true);
cc24?.NotifyCamInspectionComplete(0, datax); cc24?.NotifyCamInspectionComplete(0, datax);
@@ -2186,6 +2190,7 @@ namespace TetraPackOCR
} }
if (ocryy[item] < -50 || ocryy[item] > 400) if (ocryy[item] < -50 || ocryy[item] > 400)
{ {
EnableStartDetect();
log.Error("y范围 -50,400"); log.Error("y范围 -50,400");
byte[] datax = DataConverter.FloatToByte(0.0f, true); byte[] datax = DataConverter.FloatToByte(0.0f, true);
cc24?.NotifyCamInspectionComplete(0, datax); cc24?.NotifyCamInspectionComplete(0, datax);
@@ -2213,13 +2218,12 @@ namespace TetraPackOCR
cc24?.NotifyCamInspectionComplete(0, datax); cc24?.NotifyCamInspectionComplete(0, datax);
cc24?.NotifyCamAcqComplete(0); cc24?.NotifyCamAcqComplete(0);
log.Info("坐标已发送完成。"); log.Info("坐标已发送完成。");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
EnableStartDetect();
log.Error(ex.Message + "未检测到K标志"); log.Error(ex.Message + "未检测到K标志");
if (check_Autorun.Checked == false) if (check_Autorun.Checked == false)
{ {

File diff suppressed because it is too large Load Diff