增加自定义拍照事件

master
lhiven 1 year ago
parent 2009340fb4
commit 2ee75f0aa4

@ -57,6 +57,10 @@ namespace Rs.MotionPlat
double matchResultScore = 0.0; double matchResultScore = 0.0;
string LightName = ""; string LightName = "";
bool bGrab = false; bool bGrab = false;
/// <summary>
/// 自定义拍照事件
/// </summary>
public event Action CustomDefineGrabEvent;
public CameraTemplate() public CameraTemplate()
{ {
InitializeComponent(); InitializeComponent();
@ -264,16 +268,24 @@ namespace Rs.MotionPlat
private void btnGrab_Click(object sender, EventArgs e) private void btnGrab_Click(object sender, EventArgs e)
{
ImageProcess.ClearManualTrigger();
HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual);
bGrabContinue = false;
if (CustomDefineGrabEvent!=null)
{
CustomDefineGrabEvent?.Invoke();
LoadImage();
}
else
{ {
LightName = SysConfigParam.GetValue<string>(cameraName + "LightName"); LightName = SysConfigParam.GetValue<string>(cameraName + "LightName");
if (!string.IsNullOrEmpty(LightName)) if (!string.IsNullOrEmpty(LightName))
{ {
if (!string.IsNullOrEmpty(cameraName)) if (!string.IsNullOrEmpty(cameraName))
{ {
ImageProcess.ClearManualTrigger();
bGrabContinue = false;
bGrab = true; bGrab = true;
HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual);
if (ManualGrab == null) if (ManualGrab == null)
{ {
IoManager.Instance.WriteOut(LightName, 0); IoManager.Instance.WriteOut(LightName, 0);
@ -300,6 +312,8 @@ namespace Rs.MotionPlat
Msg.ShowError("未设置相机对应的光源,请到变量中配置!"); Msg.ShowError("未设置相机对应的光源,请到变量中配置!");
} }
} }
}
bool bGrabContinue = false; bool bGrabContinue = false;
public void StopGrab() public void StopGrab()
@ -307,13 +321,36 @@ namespace Rs.MotionPlat
bGrabContinue = false; bGrabContinue = false;
} }
private void btnGrabContinue_Click(object sender, EventArgs e) private void btnGrabContinue_Click(object sender, EventArgs e)
{
bGrabContinue = !bGrabContinue;
if (bGrabContinue)
{
btnGrabContinue.Text = "停止取图";
}
else
{
btnGrabContinue.Text = "连续取图";
}
if (CustomDefineGrabEvent!=null)
{
Task.Run(() => {
while (bGrabContinue)
{
bGrab = true;
ImageProcess.ClearManualTrigger();
CustomDefineGrabEvent?.Invoke();
LoadImage();
Thread.Sleep(300);
}
});
}
else
{ {
LightName = SysConfigParam.GetValue<string>(cameraName + "LightName"); LightName = SysConfigParam.GetValue<string>(cameraName + "LightName");
if (!string.IsNullOrEmpty(cameraName)) if (!string.IsNullOrEmpty(cameraName))
{ {
HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual); HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual);
bGrabContinue = !bGrabContinue; //bGrabContinue = !bGrabContinue;
Task.Run(() => { Task.Run(() => {
while (bGrabContinue) while (bGrabContinue)
{ {
@ -331,6 +368,13 @@ namespace Rs.MotionPlat
} }
} }
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
}
private void LoadImage() private void LoadImage()
{ {
Stopwatch time = new Stopwatch(); Stopwatch time = new Stopwatch();

@ -95,7 +95,7 @@
this.lblStatus.Name = "lblStatus"; this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(137, 36); this.lblStatus.Size = new System.Drawing.Size(137, 36);
this.lblStatus.TabIndex = 2; this.lblStatus.TabIndex = 2;
this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// label1 // label1
// //
@ -107,7 +107,7 @@
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(137, 36); this.label1.Size = new System.Drawing.Size(137, 36);
this.label1.TabIndex = 1; this.label1.TabIndex = 1;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
// //
// contextMenuStrip1 // contextMenuStrip1
// //

Loading…
Cancel
Save