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

281 lines
11 KiB
C#

using ChoiceTech.Halcon.Control;
using HalconDotNet;
using Rs.Camera;
using Rs.Controls;
using Rs.Framework;
using Rs.Motion;
using Rs.Motion.GugaoEcat;
using Rs.MotionPlat.Commom;
using Rs.MotionPlat.Flow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
namespace Rs.MotionPlat.SysConfig
{
public partial class LookCamera : BaseFormHeader
{
public LookCamera()
{
InitializeComponent();
}
private void btnUpCameraGrab_Click(object sender, EventArgs e)
{
Task.Run(() => {
btnUpCameraGrab.Invoke(new Action(() => {
btnUpCameraGrab.Enabled = false;
}));
do
{
try
{
ImageProcess.ClearManualTrigger();
HikCamera.Instance.SetExposure("upCamera", float.Parse(txtUpCameraExposureTime.Text));
HikCamera.Instance.SetGain("upCamera", float.Parse(txtUpCameraGain.Text));
HikCamera.Instance.SetTrigger("upCamera", ETriggerMode.Manual, ETriggerSource.Software);
//AxisControl.LoadX.ComparePulse(2, false);
Ops.On("上相机光源");
Thread.Sleep(500);
HikCamera.Instance.Grab("upCamera");
HObject image = null;
Stopwatch timer = new Stopwatch();
timer.Start();
while (image == null && timer.ElapsedMilliseconds < 3000)
{
image = ImageProcess.GetManualImage();
if (image != null && image.IsInitialized())
{
HOperatorSet.RotateImage(image, out image, SysConfigParam.GetValue<double>("UpCameraRotate"), "constant");
himgNozzle8.Invoke(new Action(() =>
{
himgNozzle8.HobjectToHimage(image);
HOperatorSet.GetImageSize(image, out HTuple imgWidth, out HTuple imgHeight);
HOperatorSet.GenCrossContourXld(out HObject camCenter, imgHeight / 2, imgWidth / 2, Math.Max(imgHeight, imgWidth), 0);
himgNozzle8.DispObj(camCenter);
}));
break;
}
}
Ops.Off("上相机光源");
Thread.Sleep(500);
}
catch (Exception)
{
}
}
while (checkBox1.Checked);
btnUpCameraGrab.Invoke(new Action(() => {
btnUpCameraGrab.Enabled = true;
}));
});
}
private void btnDownCameraGrab_Click(object sender, EventArgs e)
{
Task.Run(() => {
btnDownCameraGrab.Invoke(new Action(() => {
btnDownCameraGrab.Enabled = false;
}));
do
{
ImageProcess.ClearManualTrigger();
HikCamera.Instance.SetExposure("locationCamera", GlobalVar.FlyGrabExposureTime);
HikCamera.Instance.SetGain("locationCamera", GlobalVar.FlyGrabGain);
HikCamera.Instance.SetTrigger("locationCamera", ETriggerMode.Manual, ETriggerSource.Software);
Ops.On("下相机光源");
Thread.Sleep(500);
HikCamera.Instance.Grab("locationCamera");
//AxisControl.LoadX.ComparePulse(1, false);
HObject image = null;
Stopwatch timer = new Stopwatch();
timer.Start();
while (image == null && timer.ElapsedMilliseconds<3000)
{
image = ImageProcess.GetManualImage();
if (image != null && image.IsInitialized())
{
HOperatorSet.RotateImage(image, out image, SysConfigParam.GetValue<double>("DownLocationCameraRotate"), "constant");
himgNozzle8.Invoke(new Action(() => {
himgNozzle8.HobjectToHimage(image);
HOperatorSet.GetImageSize(image, out HTuple imgWidth, out HTuple imgHeight);
HOperatorSet.GenCrossContourXld(out HObject camCenter, imgHeight / 2, imgWidth / 2, Math.Max(imgHeight, imgWidth), 0);
himgNozzle8.DispObj(camCenter);
}));
break;
}
}
Ops.Off("下相机光源");
Thread.Sleep(500);
}
while (checkBox1.Checked);
btnDownCameraGrab.Invoke(new Action(() => {
btnDownCameraGrab.Enabled = true;
}));
});
}
private void button1_Click(object sender, EventArgs e)
{
//Task.Run(() => {
// SlotPoint sp1 = TrayPointManager.GetSlotPoint("Default", "Turnover", 1, EPointType.RUN);
// SlotPoint sp2 = TrayPointManager.GetSlotPoint("Default", "Turnover", 8, EPointType.RUN);
// int speed = 20;
// AxisControl.LoadX.MovePos(sp1.X - 50, speed);
// AxisControl.LoadY.MovePos(sp1.Y, speed);
// while (true)
// {
// if (Ops.IsStop(AxisControl.LoadX, AxisControl.LoadY))
// {
// break;
// }
// }
// ImageProcess.ClearAutoTrigger();
// HikCamera.Instance.SetExposure("upCamera", GlobalVar.FlyGrabExposureTime);
// HikCamera.Instance.SetGain("upCamera", 15);
// HikCamera.Instance.SetTrigger("upCamera", ETriggerMode.Auto);
// double[] targetPos = new double[8];
// for (int i = 0; i < 8; i++)
// {
// targetPos[i] = sp1.X + (i * 45);
// }
// AxisControl.LoadX.SetPosCompare(2, targetPos);
// AxisControl.LoadX.MovePos(sp2.X + 50, speed);
// //AxisControl.LoadY.MovePos(sp2.Y, 4);
// while (true)
// {
// if (Ops.IsStop(AxisControl.LoadX, AxisControl.LoadY))
// {
// break;
// }
// }
// HObject[] images = new HObject[8];
// while (true)
// {
// images = ImageProcess.GetAutoImage();
// if (images.Length == 8)
// break;
// // break;
// }
// int ix = 0;
// foreach (HObject image in images)
// {
// HOperatorSet.RotateImage(image, out HObject imagex, SysConfigParam.GetValue<double>("UpCameraRotate"), "constant");
// HOperatorSet.WriteImage(imagex, "bmp", 0, $"d://images//{ix}");
// ix++;
// }
//});
}
private void button2_Click(object sender, EventArgs e)
{
Task.Run(() => {
AxisControl.LoadX.ClearCompare(2);
AxisControl.LoadX.MovePos(SysConfigParam.GetValue<double>($"Nozzle8CenterX") - 100, GlobalVar.WholeSpeed);
AxisControl.LoadY.MovePos(SysConfigParam.GetValue<double>($"Nozzle8CenterY"), GlobalVar.WholeSpeed);
while (true)
{
if (Ops.IsStop("LoadX", "LoadY") || GlobalVar.VirtualAxis)
{
break;
}
}
ImageProcess.ClearAutoTrigger();
HikCamera.Instance.SetTrigger("locationCamera", ETriggerMode.Auto);
HikCamera.Instance.SetGain("locationCamera", 0);
List<double> grabPoints = new List<double>();
for (int i = 8; i >0; i--)
{
grabPoints.Add(SysConfigParam.GetValue<double>($"Nozzle{i}CenterX"));
}
AxisControl.LoadX.SetPosCompare(1, grabPoints.ToArray());
AxisControl.LoadX.MovePos(SysConfigParam.GetValue<double>($"Nozzle1CenterX") + 30, GlobalVar.FlyCameraSpeed);
while (true)
{
if (Ops.IsStop("LoadX") || GlobalVar.VirtualAxis)
{
break;
}
}
HObject[] images = new HObject[8];
while (true)
{
images = ImageProcess.GetAutoImage();
if (images.Length == 8)
break;
// break;
}
int ix = 0;
foreach (HObject image in images)
{
HOperatorSet.RotateImage(image, out HObject imagex, SysConfigParam.GetValue<double>("UpCameraRotate"), "constant");
HOperatorSet.WriteImage(imagex, "bmp", 0, $"d://images//a{ix}");
ix++;
}
});
}
private void LookCamera_Load(object sender, EventArgs e)
{
//获取屏幕的宽度
int tWidth = Screen.PrimaryScreen.WorkingArea.Width;
int tHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.Opacity = 1;
this.Location = new Point(tWidth - Width, tHeight - Height);
}
private void txtUpCameraExposureTime_KeyUp(object sender, KeyEventArgs e)
{
if(e.KeyCode== Keys.Enter)
{
HikCamera.Instance.SetExposure("upCamera", float.Parse(txtUpCameraExposureTime.Text));
}
}
private void txtUpCameraGain_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
HikCamera.Instance.SetGain("upCamera", float.Parse(txtUpCameraGain.Text));
}
}
private void txtDownCameraExposureTime_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
HikCamera.Instance.SetExposure("locationCamera", float.Parse(txtDownCameraExposureTime.Text));
}
}
private void txtDownCameraGain_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
HikCamera.Instance.SetGain("locationCamera", float.Parse(txtDownCameraGain.Text));
}
}
}
}