- Added QRValidation vision control system - Includes CapCleaningControl UI components - WebSocket-based barcode validation system - Support for Crevis PLC integration - Test projects for PLC emulator, motion, IO panel, and Modbus 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
898 lines
32 KiB
C#
898 lines
32 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using static Project.Util_Vision;
|
|
using AR;
|
|
using Euresys.Open_eVision_22_12;
|
|
|
|
namespace Project
|
|
{
|
|
public partial class fMain : Form
|
|
{
|
|
Boolean exit = false;
|
|
Boolean bRunConnection = true;
|
|
private arCtl.LogTextBox rtLogR;
|
|
private arCtl.LogTextBox rtLogL;
|
|
|
|
public fMain()
|
|
{
|
|
InitializeComponent();
|
|
InitRTLog();
|
|
|
|
PUB.mre[0] = new ManualResetEvent(true);
|
|
PUB.mre[1] = new ManualResetEvent(true);
|
|
|
|
PUB.mre_send[0] = new ManualResetEvent(true);
|
|
PUB.mre_send[1] = new ManualResetEvent(true);
|
|
|
|
|
|
this.KeyDown += (s1, e1) =>
|
|
{
|
|
if (e1.KeyCode == Keys.Escape) this.Close();
|
|
if (DateTime.Now > PUB.LastInputTime) PUB.LastInputTime = DateTime.Now;
|
|
};
|
|
|
|
//dotList = new List<arCtl.arLabel>();
|
|
//dotList.AddRange(new arCtl.arLabel[] { lbDot1, lbDot2, lbDot3, lbDot4, lbDot5, lbDot6, lbDot7, lbDot8, lbDot9, lbDot10 });
|
|
|
|
this.MouseMove += (s1, e1) => { if (DateTime.Now > PUB.LastInputTime) PUB.LastInputTime = DateTime.Now; };
|
|
this.FormClosing += __Closing;
|
|
|
|
PUB._hDevice[0] = -1;
|
|
PUB._hDevice[1] = -1;
|
|
|
|
if (System.Diagnostics.Debugger.IsAttached) this.TopMost = false;
|
|
//else this.TopMost = true;
|
|
PUB.imgque.Push(this.Name);
|
|
PUB.RemoteCommand += PUB_RemoteCommand;
|
|
}
|
|
|
|
void InitRTLog()
|
|
{
|
|
this.rtLogR = new arCtl.LogTextBox();
|
|
this.rtLogL = new arCtl.LogTextBox();
|
|
|
|
arCtl.sLogMessageColor sLogMessageColor1 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor2 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor3 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor4 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor5 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor6 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor7 = new arCtl.sLogMessageColor();
|
|
arCtl.sLogMessageColor sLogMessageColor8 = new arCtl.sLogMessageColor();
|
|
|
|
//
|
|
// rtLogR
|
|
//
|
|
this.rtLogR.BackColor = System.Drawing.SystemColors.Control;
|
|
this.rtLogR.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
sLogMessageColor1.color = System.Drawing.Color.Black;
|
|
sLogMessageColor1.gubun = "NOR";
|
|
sLogMessageColor2.color = System.Drawing.Color.Red;
|
|
sLogMessageColor2.gubun = "ERR";
|
|
sLogMessageColor3.color = System.Drawing.Color.Tomato;
|
|
sLogMessageColor3.gubun = "WARN";
|
|
sLogMessageColor4.color = System.Drawing.Color.DeepSkyBlue;
|
|
sLogMessageColor4.gubun = "MSG";
|
|
this.rtLogR.ColorList = new arCtl.sLogMessageColor[] {
|
|
sLogMessageColor1,
|
|
sLogMessageColor2,
|
|
sLogMessageColor3,
|
|
sLogMessageColor4};
|
|
this.rtLogR.DateFormat = "mm:ss.fff";
|
|
this.rtLogR.DefaultColor = System.Drawing.Color.LightGray;
|
|
this.rtLogR.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
this.rtLogR.EnableDisplayTimer = false;
|
|
this.rtLogR.EnableGubunColor = true;
|
|
this.rtLogR.Font = new System.Drawing.Font("Consolas", 9F);
|
|
this.rtLogR.ListFormat = "[{0}] {1}";
|
|
this.rtLogR.Location = new System.Drawing.Point(587, 3);
|
|
this.rtLogR.MaxListCount = ((ushort)(200));
|
|
this.rtLogR.MaxTextLength = ((uint)(4000u));
|
|
this.rtLogR.MessageInterval = 50;
|
|
this.rtLogR.Name = "rtLogR";
|
|
this.rtLogR.Size = new System.Drawing.Size(578, 626);
|
|
this.rtLogR.TabIndex = 136;
|
|
this.rtLogR.Text = "";
|
|
//
|
|
// rtLogL
|
|
//
|
|
this.rtLogL.BackColor = System.Drawing.SystemColors.Control;
|
|
this.rtLogL.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
sLogMessageColor5.color = System.Drawing.Color.Black;
|
|
sLogMessageColor5.gubun = "NOR";
|
|
sLogMessageColor6.color = System.Drawing.Color.Red;
|
|
sLogMessageColor6.gubun = "ERR";
|
|
sLogMessageColor7.color = System.Drawing.Color.Tomato;
|
|
sLogMessageColor7.gubun = "WARN";
|
|
sLogMessageColor8.color = System.Drawing.Color.DeepSkyBlue;
|
|
sLogMessageColor8.gubun = "MSG";
|
|
this.rtLogL.ColorList = new arCtl.sLogMessageColor[] {
|
|
sLogMessageColor5,
|
|
sLogMessageColor6,
|
|
sLogMessageColor7,
|
|
sLogMessageColor8};
|
|
this.rtLogL.DateFormat = "mm:ss.fff";
|
|
this.rtLogL.DefaultColor = System.Drawing.Color.LightGray;
|
|
this.rtLogL.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
this.rtLogL.EnableDisplayTimer = false;
|
|
this.rtLogL.EnableGubunColor = true;
|
|
this.rtLogL.Font = new System.Drawing.Font("Consolas", 9F);
|
|
this.rtLogL.ListFormat = "[{0}] {1}";
|
|
this.rtLogL.Location = new System.Drawing.Point(3, 3);
|
|
this.rtLogL.MaxListCount = ((ushort)(200));
|
|
this.rtLogL.MaxTextLength = ((uint)(4000u));
|
|
this.rtLogL.MessageInterval = 50;
|
|
this.rtLogL.Name = "rtLogL";
|
|
this.rtLogL.Size = new System.Drawing.Size(578, 626);
|
|
this.rtLogL.TabIndex = 136;
|
|
this.rtLogL.Text = "";
|
|
|
|
this.tableLayoutPanel2.Controls.Add(this.rtLogR, 1, 0);
|
|
this.tableLayoutPanel2.Controls.Add(this.rtLogL, 0, 0);
|
|
}
|
|
private void PUB_RemoteCommand(object sender, remoteargs e)
|
|
{
|
|
switch (e.Command)
|
|
{
|
|
case remotelist.barcodeupdate:
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
if (e.CamIdx == PUB.setting.CameraIndexL)
|
|
{
|
|
rtLeft.Text = e.strdata;
|
|
}
|
|
else
|
|
{
|
|
rtRight.Text = e.strdata;
|
|
}
|
|
}));
|
|
break;
|
|
}
|
|
}
|
|
|
|
void addsendlogmsg(RichTextBox rt, string msg)
|
|
{
|
|
if (rt.InvokeRequired)
|
|
{
|
|
rt.BeginInvoke(new Action<RichTextBox, string>(addsendlogmsg), new object[] { rt, msg });
|
|
}
|
|
else
|
|
{
|
|
string pretext = "";
|
|
if (rt.TextLength > 500)
|
|
{
|
|
pretext = rt.Text.Substring(400);
|
|
rt.Clear();
|
|
}
|
|
rt.AppendText(pretext + "\n" + msg);
|
|
}
|
|
|
|
}
|
|
|
|
private void __Closing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (exit == false)
|
|
{
|
|
// viewmode(true);
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (UTIL.MsgQ("Do you really want to exit?") != DialogResult.Yes)
|
|
{
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
_Close_Start();
|
|
}
|
|
}
|
|
}
|
|
|
|
void UpdateControl()
|
|
{
|
|
this.Text = Application.ProductName + " ver " + Application.ProductVersion + $"({PUB.setting.cameraname})";
|
|
|
|
if (PUB.wsock_[0] != null)
|
|
{
|
|
PUB.wsock_[0].TargetIdx = PUB.setting.CameraIndexL;
|
|
PUB.wsock_[0].Target = eTarget.Left;
|
|
}
|
|
|
|
if (PUB.wsock_[1] != null)
|
|
{
|
|
PUB.wsock_[1].TargetIdx = PUB.setting.CameraIndexR;
|
|
PUB.wsock_[1].Target = eTarget.Right;
|
|
}
|
|
|
|
}
|
|
private void __Load(object sender, EventArgs e)
|
|
{
|
|
|
|
PUB.log_[0].RaiseMsg += Log_RaiseMsgL;
|
|
PUB.log_[1].RaiseMsg += Log_RaiseMsgR;
|
|
|
|
// if (System.Diagnostics.Debugger.IsAttached) viewmode(false);
|
|
// else viewmode(true);
|
|
this.Show();
|
|
Application.DoEvents();
|
|
|
|
|
|
//Shared memory setup 230811
|
|
//if (PUB.setting.CameraIndexL >= 0)
|
|
//{
|
|
// swplc[0] = new AR.MemoryMap.Server("crevisv22L", 1024);
|
|
// swplc[0].Idx = (int)PUB.setting.CameraIndexL;
|
|
// swplc[0].ValueChanged += Plc_ValueChanged;
|
|
// swplc[0].Start();
|
|
//}
|
|
|
|
//if (PUB.setting.CameraIndexR >= 0)
|
|
//{
|
|
// swplc[1] = new AR.MemoryMap.Server("crevisv22R", 1024);
|
|
// swplc[1].Idx = (int)PUB.setting.CameraIndexR;
|
|
// swplc[1].ValueChanged += Plc_ValueChanged;
|
|
// swplc[1].Start();
|
|
//}
|
|
|
|
//Socket initialization
|
|
//Pub.log.Add("Socket event assignment");
|
|
//Pub.wsListen.ConnectionRequest += WsListen_ConnectionRequest;
|
|
//Application.DoEvents();
|
|
|
|
PUB.log_[0].Add($"Server listening port:{PUB.setting.listenPortL}");
|
|
try
|
|
{
|
|
PUB.wsock_[0] = new Class.WebSocket("127.0.0.1", PUB.setting.listenPortL);
|
|
PUB.wsock_[0].TargetIdx = PUB.setting.CameraIndexL;
|
|
PUB.wsock_[0].Target = eTarget.Left;
|
|
PUB.wsock_[0].Start();
|
|
PUB.wsock_[0].MessageReceived += Ws_DataArrival;
|
|
PUB.wsock_[0].ClientConnected += Ws_Connected;
|
|
PUB.wsock_[0].ClientDisconnected += Ws_Disconnected;
|
|
PUB.log_[0].Add("Camera initialization");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.wsock_[0].MessageReceived -= Ws_DataArrival;
|
|
PUB.wsock_[0].ClientConnected -= Ws_Connected;
|
|
PUB.wsock_[0].ClientDisconnected -= Ws_Disconnected;
|
|
PUB.log_[0].AddE("Server listen failed:" + ex.Message);
|
|
}
|
|
|
|
PUB.log_[1].Add($"Server listening port:{PUB.setting.listenPortR}");
|
|
try
|
|
{
|
|
PUB.wsock_[1] = new Class.WebSocket("127.0.0.1", PUB.setting.listenPortR);
|
|
PUB.wsock_[1].TargetIdx = PUB.setting.CameraIndexR;
|
|
PUB.wsock_[1].Target = eTarget.Right;
|
|
PUB.wsock_[1].Start();
|
|
PUB.wsock_[1].MessageReceived += Ws_DataArrival;
|
|
PUB.wsock_[1].ClientConnected += Ws_Connected;
|
|
PUB.wsock_[1].ClientDisconnected += Ws_Disconnected;
|
|
PUB.log_[1].Add("Camera initialization");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.wsock_[1].MessageReceived -= Ws_DataArrival;
|
|
PUB.wsock_[1].ClientConnected -= Ws_Connected;
|
|
PUB.wsock_[1].ClientDisconnected -= Ws_Disconnected;
|
|
PUB.log_[1].AddE("Server listen failed:" + ex.Message);
|
|
}
|
|
|
|
Application.DoEvents();
|
|
|
|
_SM_RUN_INIT_CAMERA();
|
|
|
|
tmDisplay.Start(); //start Display
|
|
|
|
PUB.flag.set(eFlag.CHECKLICENSE, true, "LOAD");
|
|
PUB.flag.set(eFlag.CHECKCAMERAL, true, "LOAD");
|
|
PUB.flag.set(eFlag.CHECKCAMERAR, true, "LOAD");
|
|
Task.Run(new Action(() =>
|
|
{
|
|
//license chedk
|
|
try
|
|
{
|
|
|
|
using (var img = new EImageBW8())
|
|
{
|
|
PUB.log_[0].Add("evision check OK");
|
|
PUB.log_[1].Add("evision check OK");
|
|
}
|
|
PUB.VisionLicense = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.VisionLicense = false;
|
|
PUB.log_[0].AddE($"evision check Error:{ex.Message}");
|
|
PUB.log_[1].AddE($"evision check Error:{ex.Message}");
|
|
|
|
}
|
|
PUB.flag.set(eFlag.CHECKLICENSE, false, "LOAD");
|
|
// panMiniDisplay.Invalidate();
|
|
}));
|
|
UpdateControl();
|
|
PUB.log_[0].Add($"Program start(left:{PUB.setting.CameraIndexL})");
|
|
PUB.log_[1].Add($"Program start(right:{PUB.setting.CameraIndexR})");
|
|
//PUB.CheckNRegister3(Application.ProductName, "chi", Application.ProductVersion);
|
|
|
|
//Image collection thread start - 231003
|
|
bwLeft.RunWorkerAsync();
|
|
bwRight.RunWorkerAsync();
|
|
bwConn.RunWorkerAsync();
|
|
|
|
//set live mode
|
|
if (PUB.setting.CameraIndexL >= 0) PUB.IsLive[PUB.setting.CameraIndexL] = true;
|
|
if (PUB.setting.CameraIndexR >= 0) PUB.IsLive[PUB.setting.CameraIndexR] = true;
|
|
if (PUB.setting.CameraIndexL >= 0) PUB.IsProcess[PUB.setting.CameraIndexL] = true;
|
|
if (PUB.setting.CameraIndexR >= 0) PUB.IsProcess[PUB.setting.CameraIndexR] = true;
|
|
}
|
|
//private void Plc_ValueChanged(object sender, AR.MemoryMap.Core.monitorvalueargs e)
|
|
//{
|
|
// var ws = sender as AR.MemoryMap.Server;
|
|
//}
|
|
|
|
#region "Mouse Drag"
|
|
|
|
Boolean mousecap = false;
|
|
Point mousepos;
|
|
private void Panel1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
mousepos = e.Location;
|
|
mousecap = true;
|
|
// panMiniDisplay.Invalidate();
|
|
}
|
|
private void Panel1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
// viewmode(false);
|
|
this.Invalidate();
|
|
}
|
|
|
|
private void Panel1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (mousecap)
|
|
{
|
|
var offx = e.Location.X - mousepos.X;
|
|
var offy = e.Location.Y - mousepos.Y;
|
|
this.Location = new Point(this.Location.X + offx, this.Location.Y + offy);
|
|
//mousepos = e.Location;
|
|
}
|
|
}
|
|
|
|
private void Panel1_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
mousecap = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void Log_RaiseMsgL(DateTime LogTime, string TypeStr, string Message)
|
|
{
|
|
if (this.rtLogL != null)
|
|
this.rtLogL.AddMsg(LogTime, TypeStr, Message);
|
|
}
|
|
|
|
private void Log_RaiseMsgR(DateTime LogTime, string TypeStr, string Message)
|
|
{
|
|
if (this.rtLogR != null)
|
|
this.rtLogR.AddMsg(LogTime, TypeStr, Message);
|
|
}
|
|
|
|
|
|
#region "Mouse Form Move"
|
|
|
|
private Boolean fMove = false;
|
|
private Point MDownPos;
|
|
|
|
private void LbTitle_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal;
|
|
else this.WindowState = FormWindowState.Maximized;
|
|
//this.loader1.RemakeRect();
|
|
}
|
|
private void LbTitle_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (fMove)
|
|
{
|
|
Point offset = new Point(e.X - MDownPos.X, e.Y - MDownPos.Y);
|
|
this.Left += offset.X;
|
|
this.Top += offset.Y;
|
|
offset = new Point(0, 0);
|
|
}
|
|
}
|
|
private void LbTitle_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
fMove = false;
|
|
}
|
|
private void LbTitle_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
MDownPos = new Point(e.X, e.Y);
|
|
fMove = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
private void 맵데이터보기ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
Util.RunExplorer(Util.CurrentPath);
|
|
}
|
|
|
|
private void 저장폴더열기ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
PUB.LogFlush();
|
|
|
|
|
|
var fi = new System.IO.FileInfo(PUB.log_[0].FileName);
|
|
Util.RunExplorer(fi.Directory.FullName);
|
|
}
|
|
|
|
private void 캡처ToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
string savefile = System.IO.Path.Combine(Util.CurrentPath, "ScreenShot", DateTime.Now.ToString("yyyyMMddHHmmss") + ".png");
|
|
var grpath = new System.IO.FileInfo(savefile);
|
|
Util.RunExplorer(grpath.Directory.FullName);
|
|
}
|
|
|
|
private void 저장ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var path = System.IO.Path.Combine(
|
|
PUB.setting.Path_Data, "History",
|
|
DateTime.Now.Year.ToString("0000"),
|
|
DateTime.Now.Month.ToString("00"),
|
|
DateTime.Now.Day.ToString("00"));
|
|
if (System.IO.Directory.Exists(path))
|
|
Util.RunExplorer(path);
|
|
else
|
|
Util.RunExplorer(System.IO.Path.Combine(PUB.setting.Path_Data, "History"));
|
|
}
|
|
|
|
private void 이미지ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var path = System.IO.Path.Combine(
|
|
PUB.setting.Path_Data, "Images",
|
|
DateTime.Now.Year.ToString("0000"),
|
|
DateTime.Now.Month.ToString("00"),
|
|
DateTime.Now.Day.ToString("00"));
|
|
if (System.IO.Directory.Exists(path))
|
|
Util.RunExplorer(path);
|
|
else
|
|
Util.RunExplorer(System.IO.Path.Combine(PUB.setting.Path_Data, "History"));
|
|
}
|
|
|
|
private void 수량ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var path = System.IO.Path.Combine(
|
|
PUB.setting.Path_Data, "Count",
|
|
DateTime.Now.Year.ToString("0000"),
|
|
DateTime.Now.Month.ToString("00"),
|
|
DateTime.Now.Day.ToString("00"));
|
|
if (System.IO.Directory.Exists(path))
|
|
Util.RunExplorer(path);
|
|
else
|
|
Util.RunExplorer(System.IO.Path.Combine(PUB.setting.Path_Data, "History"));
|
|
}
|
|
|
|
private void exceptionTestToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
int a = 0;
|
|
int b = 1;
|
|
var c = b / a;
|
|
}
|
|
|
|
private void processListToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
PUB.log_[0].Add("process list");
|
|
PUB.log_[1].Add("process list");
|
|
foreach (var prc in System.Diagnostics.Process.GetProcesses())
|
|
{
|
|
if (prc.ProcessName.StartsWith("svchost")) continue;
|
|
if (prc.ProcessName.Contains(".host")) continue;
|
|
PUB.log_[0].Add(prc.ProcessName);
|
|
PUB.log_[1].Add(prc.ProcessName);
|
|
}
|
|
}
|
|
|
|
|
|
private void errorHandleToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
int a = 3;
|
|
int b = 0;
|
|
var c = a / b;
|
|
}
|
|
|
|
private void toolStripButton4_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
//라이브, 프로세스, 트리거상태 보존
|
|
var l0 = PUB.IsLive[0];
|
|
var t0 = PUB.IsTrigger[0];
|
|
var p0 = PUB.IsProcess[0];
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
PUB.IsLive[i] = false;
|
|
PUB.IsTrigger[i] = false;
|
|
PUB.IsProcess[i] = false;
|
|
}
|
|
|
|
using (var f = new fSetting())
|
|
{
|
|
f.TopMost = true;
|
|
f.ShowDialog();
|
|
}
|
|
|
|
UpdateControl();
|
|
|
|
if (PUB.setting.CameraIndexL >= 0)
|
|
{
|
|
PUB.IsLive[PUB.setting.CameraIndexL] = l0;
|
|
PUB.IsTrigger[PUB.setting.CameraIndexL] = t0;
|
|
PUB.IsProcess[PUB.setting.CameraIndexL] = p0;
|
|
}
|
|
|
|
if (PUB.setting.CameraIndexR >= 0)
|
|
{
|
|
PUB.IsLive[PUB.setting.CameraIndexR] = l0;
|
|
PUB.IsTrigger[PUB.setting.CameraIndexR] = t0;
|
|
PUB.IsProcess[PUB.setting.CameraIndexR] = p0;
|
|
}
|
|
|
|
}
|
|
|
|
private void toolStripButton5_Click(object sender, EventArgs e)
|
|
{
|
|
Util.RunExplorer(PUB.setting.ImageSavePath);
|
|
}
|
|
|
|
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
exit = true;
|
|
this.Close();
|
|
}
|
|
|
|
private void toolStripButton7_Click(object sender, EventArgs e)
|
|
{
|
|
exit = true;
|
|
this.Close();
|
|
}
|
|
|
|
|
|
private void toolStripButton9_Click_2(object sender, EventArgs e)
|
|
{
|
|
//camera image save
|
|
var bt = sender as ToolStripButton;
|
|
var camidx = bt.Name.Equals("toolStripButton9") ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camidx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
var sd = new SaveFileDialog();
|
|
sd.Filter = "bitmap|*.bmp";
|
|
if (sd.ShowDialog() != DialogResult.OK) return;
|
|
|
|
//이미지가 없다면 한장 찍는다
|
|
//if (this.iv[camidx].Image == null) CrevisGrab(camidx, true);
|
|
if (PUB.mre[camidx].WaitOne(100))
|
|
{
|
|
PUB.mre[camidx].Reset();
|
|
if (PUB.OrgImage[camidx] != null && PUB.OrgImage[camidx].IsVoid == false)
|
|
{
|
|
PUB.OrgImage[camidx].Save(sd.FileName);
|
|
PUB.log_[logIdx].Add($"File save completed {sd.FileName}");
|
|
}
|
|
else UTIL.MsgE("No image");
|
|
PUB.mre[camidx].Set();
|
|
}
|
|
else PUB.log_[logIdx].AddE($"Image is locked");
|
|
|
|
|
|
}
|
|
|
|
private void toolStripButton11_Click_1(object sender, EventArgs e)
|
|
{
|
|
var bt = sender as ToolStripButton;
|
|
var tagstr = bt.Tag.ToString();
|
|
|
|
OpenFileDialog od = new OpenFileDialog();
|
|
od.Filter = "image file|*.jpg;*.bmp";
|
|
od.FilterIndex = 0;
|
|
if (od.ShowDialog() != DialogResult.OK) return;
|
|
|
|
//Turn off live mode
|
|
var camIdx = tagstr == "L" ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
PUB.IsLive[camIdx] = false;
|
|
//iv[camidx].Image = null;
|
|
|
|
//Remove existing image
|
|
if (PUB.mre[camIdx].WaitOne(100))
|
|
{
|
|
PUB.mre[camIdx].Reset();
|
|
if (PUB.OrgImage[camIdx] != null) PUB.OrgImage[camIdx].Dispose();
|
|
PUB.OrgImage[camIdx] = new EImageBW8();
|
|
PUB.OrgImage[camIdx].Load(od.FileName);
|
|
|
|
var target = tagstr == "L" ? eTarget.Left : eTarget.Right;
|
|
var pan = target == eTarget.Left ? pivLeft : pIvRight;
|
|
|
|
//draw image
|
|
PUB.DrawImage(target, pan, PUB.OrgImage[camIdx]);
|
|
PUB.mre[camIdx].Set();
|
|
}
|
|
else
|
|
{
|
|
PUB.log_[logIdx].AddE($"Cannot execute because image is locked");
|
|
return;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void toolStripButton12_Click_1(object sender, EventArgs e)
|
|
{
|
|
//ivL.ZoomFit();
|
|
}
|
|
|
|
private void toolStripButton3_Click_1(object sender, EventArgs e)
|
|
{
|
|
// ivL.ZoomIn();
|
|
}
|
|
|
|
private void toolStripButton2_Click_1(object sender, EventArgs e)
|
|
{
|
|
//ivL.ZoomOut();
|
|
}
|
|
|
|
private void toolStripButton13_Click(object sender, EventArgs e)
|
|
{
|
|
// this.ivL.DebugMode = !this.ivL.DebugMode;
|
|
// this.ivL.Invalidate();
|
|
}
|
|
|
|
|
|
|
|
List<Util_Vision.SCodeData>[] coderesult = new List<Util_Vision.SCodeData>[] {
|
|
new List<Util_Vision.SCodeData>(),
|
|
new List<Util_Vision.SCodeData>()
|
|
};
|
|
|
|
private void toolStripMenuItem7_Click(object sender, EventArgs e)
|
|
{
|
|
var bt = sender as ToolStripMenuItem;
|
|
var tagstr = bt.Tag.ToString();
|
|
var camIdx = tagstr == "L" ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var target = PUB.GetTarget(camIdx);// tagstr == "L" ? eTarget.Left : eTarget.Right;
|
|
var logIdx = target == eTarget.Left ? 0 : 1;
|
|
if (target == eTarget.None)
|
|
{
|
|
UTIL.MsgE("Target not specified");
|
|
return;
|
|
}
|
|
|
|
PUB.log_[logIdx].Add("Image Test run");
|
|
|
|
System.Diagnostics.Stopwatch wat = new Stopwatch();
|
|
wat.Restart();
|
|
|
|
if (PUB.mre[camIdx].WaitOne(100))
|
|
{
|
|
PUB.mre[camIdx].Reset();
|
|
var rlt = Util_Vision.DetectQR(PUB.OrgImage[camIdx], null, 0,
|
|
out string resultMessage,
|
|
PUB.setting.erodevaluestr,
|
|
PUB.setting.GainOffsetListStr,
|
|
PUB.setting.blob_area_min,
|
|
PUB.setting.blob_area_max,
|
|
PUB.setting.blob_sigmaxy,
|
|
PUB.setting.blob_sigmayy,
|
|
PUB.setting.blob_sigmaxx,
|
|
PUB.setting.blob_minw,
|
|
PUB.setting.blob_maxw,
|
|
PUB.setting.blob_minh,
|
|
PUB.setting.blob_maxh);
|
|
coderesult[camIdx] = rlt.Item1;
|
|
|
|
PUB.ProcessTime[camIdx] = rlt.Item4;
|
|
var pan = target == eTarget.Left ? pivLeft : pIvRight;
|
|
|
|
PUB.DrawImage(target, pan, PUB.OrgImage[camIdx], rlt.Item1, rlt.Item2, rlt.Item3);
|
|
PUB.mre[camIdx].Set();
|
|
}
|
|
else PUB.log_[logIdx].AddE($"Image is locked");
|
|
|
|
wat.Stop();
|
|
PUB.log_[logIdx].Add($"{wat.ElapsedMilliseconds}ms");
|
|
}
|
|
|
|
private void toolStripMenuItem19_Click(object sender, EventArgs e)
|
|
{
|
|
var bt = sender as ToolStripMenuItem;
|
|
var camIdx = bt.Tag.ToString().Equals("L") ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
PUB.log_[logIdx].Add("Image Test run");
|
|
|
|
if (PUB.mre[camIdx].WaitOne(100) == false)
|
|
{
|
|
PUB.log_[logIdx].AddE($"Image is locked");
|
|
return;
|
|
}
|
|
PUB.mre[camIdx].Reset();
|
|
|
|
System.Diagnostics.Stopwatch wat = new Stopwatch();
|
|
wat.Restart();
|
|
|
|
var rlt = Util_Vision.DetectQR(PUB.OrgImage[camIdx], null, 0,
|
|
out string resultMessage,
|
|
PUB.setting.erodevaluestr,
|
|
PUB.setting.GainOffsetListStr,
|
|
PUB.setting.blob_area_min,
|
|
PUB.setting.blob_area_max,
|
|
PUB.setting.blob_sigmaxy,
|
|
PUB.setting.blob_sigmayy,
|
|
PUB.setting.blob_sigmaxx, PUB.setting.blob_minw,
|
|
PUB.setting.blob_maxw,
|
|
PUB.setting.blob_minh,
|
|
PUB.setting.blob_maxh);
|
|
coderesult[camIdx] = rlt.Item1;
|
|
|
|
PUB.mre[camIdx].Set();
|
|
PUB.ProcessTime[camIdx] = rlt.Item4;
|
|
|
|
|
|
Util_Vision.SCodeData codedata;
|
|
List<string> data = new List<string>();
|
|
Boolean FindAmkorQR = false;
|
|
if (coderesult[camIdx].Count > 0)
|
|
{
|
|
foreach (var item in coderesult[camIdx].OrderByDescending(t => t.sid))
|
|
{
|
|
//datalist.Add(item.data);
|
|
// ptlist.Add(item.corner);
|
|
if (FindAmkorQR == false)
|
|
{
|
|
var bcd = new Class.CAmkorSTDBarcode(item.data);
|
|
if (bcd.isValid)
|
|
{
|
|
codedata = item;
|
|
FindAmkorQR = true;
|
|
data.Add(item.data);// = item.data;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
PUB.IsTrigger[camIdx] = true;
|
|
if (PUB.setting.SendRawData) //211210
|
|
{
|
|
if (PUB.BarcodeParsing(camIdx, coderesult[camIdx], "CREVIS"))
|
|
PUB.parsetime = DateTime.Now;
|
|
else
|
|
PUB.parsetime = DateTime.Now.AddMilliseconds(50);
|
|
}
|
|
else
|
|
{
|
|
if (PUB.BarcodeParsing(camIdx, data, "CREVIS"))
|
|
PUB.parsetime = DateTime.Now;
|
|
else
|
|
PUB.parsetime = DateTime.Now.AddMilliseconds(50);
|
|
}
|
|
|
|
wat.Stop(); ;
|
|
PUB.log_[logIdx].Add($"{wat.ElapsedMilliseconds}ms");
|
|
}
|
|
|
|
private void toolStripMenuItem20_Click(object sender, EventArgs e)
|
|
{
|
|
if (PUB.setting.CameraIndexL >= 0)
|
|
SendStatus(eTarget.Left);
|
|
|
|
if (PUB.setting.CameraIndexR >= 0)
|
|
SendStatus(eTarget.Right);
|
|
}
|
|
|
|
private void toolStripButton21_Click(object sender, EventArgs e)
|
|
{
|
|
if (PUB.setting.CameraIndexL >= 0)
|
|
PUB.IsLive[PUB.setting.CameraIndexL] = !PUB.IsLive[PUB.setting.CameraIndexL];
|
|
}
|
|
|
|
|
|
private void btTrigR_Click(object sender, EventArgs e)
|
|
{
|
|
var but = sender as ToolStripButton;
|
|
if (but == null) return;
|
|
var camIdx = but.Tag.ToString().Equals("L") ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
PUB.triggerTime[camIdx] = DateTime.Now;
|
|
PUB.IsTrigger[camIdx] = !PUB.IsTrigger[camIdx];
|
|
PUB.lastdata[camIdx] = string.Empty;
|
|
PUB.log_[logIdx].Add("User trigger setting value:" + PUB.IsTrigger[camIdx].ToString());
|
|
}
|
|
|
|
private void toolStripButton25_Click(object sender, EventArgs e)
|
|
{
|
|
var camIdx = PUB.setting.CameraIndexL;
|
|
var camTarget = PUB.GetTarget(camIdx);
|
|
if (camTarget == eTarget.None) return;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
PUB.IsProcess[camIdx] = !PUB.IsProcess[camIdx];
|
|
PUB.log_[logIdx].Add("Process setting value:" + PUB.IsProcess.ToString());
|
|
}
|
|
|
|
private void btProcessR_Click(object sender, EventArgs e)
|
|
{
|
|
var bt = sender as ToolStripButton;
|
|
var camIdx = bt.Tag.ToString().Equals("L") ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
var camTarget = PUB.GetTarget(camIdx);
|
|
|
|
if (camTarget == eTarget.None)
|
|
{
|
|
UTIL.MsgE("Target camera not found");
|
|
return;
|
|
}
|
|
PUB.IsProcess[camIdx] = !PUB.IsProcess[camIdx];
|
|
PUB.log_[logIdx].Add("Process setting value:" + PUB.IsProcess.ToString());
|
|
}
|
|
|
|
|
|
|
|
private void btLiveR_Click(object sender, EventArgs e)
|
|
{
|
|
if (PUB.setting.CameraIndexR >= 0 && PUB.setting.CameraIndexR != PUB.setting.CameraIndexL)
|
|
PUB.IsLive[PUB.setting.CameraIndexR] = !PUB.IsLive[PUB.setting.CameraIndexR];
|
|
}
|
|
private void toolStripButton6_Click_1(object sender, EventArgs e)
|
|
{
|
|
//Use dummy image
|
|
var bt = sender as ToolStripButton;
|
|
var camIdx = bt.Tag.ToString().Equals("L") ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = camIdx == PUB.setting.CameraIndexL ? 0 : 1;
|
|
if (PUB.mre[camIdx].WaitOne(100))
|
|
{
|
|
PUB.mre[camIdx].Reset();
|
|
var OrgEImage = new EImageBW8(PUB.OrgImage[camIdx].Width, PUB.OrgImage[camIdx].Height);
|
|
PUB.OrgImage[camIdx].CopyTo(OrgEImage);
|
|
PUB.mre[camIdx].Set();
|
|
|
|
var f = new fTeach(OrgEImage);
|
|
f.TopMost = true;
|
|
f.ShowDialog();
|
|
OrgEImage.Dispose();
|
|
}
|
|
else PUB.log_[logIdx].AddE($"Image is locked");
|
|
}
|
|
|
|
|
|
|
|
private void pIvRight_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
var f = new fviewer(PUB.setting.CameraIndexR);
|
|
f.ShowDialog();
|
|
}
|
|
|
|
|
|
private void pivLeft_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
var f = new fviewer(PUB.setting.CameraIndexL);
|
|
f.ShowDialog();
|
|
}
|
|
|
|
}
|
|
} |