Commit cf3574bd 几米阳光

工作界面增加实时视频功能

1 个父辈 2d1e738e
......@@ -53,6 +53,10 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Basler.Pylon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e389355f398382ab, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\Basler.Pylon.dll</HintPath>
</Reference>
<Reference Include="halcondotnet">
<HintPath>..\dll\halcondotnet.dll</HintPath>
</Reference>
......@@ -99,6 +103,7 @@
<Compile Include="deviceLibrary\urRobot\URRobotControl.cs" />
<Compile Include="deviceLibrary\urRobot\URRobotClient.cs" />
<Compile Include="deviceLibrary\urRobot\URTcpClient.cs" />
<Compile Include="pylon\Camera.cs" />
<Compile Include="Robot\MoveType.cs" />
<Compile Include="Robot\soldering\AlarmType.cs" />
<Compile Include="bean\BoardManager.cs" />
......
using Basler.Pylon;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace URSoldering.DeviceLibrary
{
public class PylonCamera
{
private Camera cam = null;
private List<ICameraInfo> allCameras;
private PixelDataConverter conv = new PixelDataConverter();
private Stopwatch stopWatch = new Stopwatch();
private System.Windows.Forms.PictureBox pic;
public PylonCamera()
{
allCameras = CameraFinder.Enumerate();
}
~PylonCamera()
{
Close();
}
public int Index { set; get; }
public string ErrInfo { set; get; }
public int CameraCount
{
get { return allCameras.Count; }
}
public bool IsOpen
{
get { return cam != null; }
}
public string[] GetName()
{
string[] s = new string[allCameras.Count];
for (int i = 0; i < s.Length; i++)
s[i] = allCameras[i][CameraInfoKey.FullName].ToString();
return s;
}
public void Close()
{
if (cam != null)
{
cam.Close();
cam.Dispose();
cam = null;
}
}
public bool Open()
{
return Open(Index);
}
public bool Open(int idx)
{
if (idx < 0 || idx >= allCameras.Count) return false;
if (cam != null) Close();
try
{
Index = idx;
cam = new Camera(allCameras[idx]);
cam.ConnectionLost += OnConnectionLost;
cam.CameraOpened += OnCameraOpened;
cam.CameraClosed += OnCameraClosed;
cam.StreamGrabber.GrabStarted += OnGrabStarted;
cam.StreamGrabber.ImageGrabbed += OnImageGrabbed;
cam.StreamGrabber.GrabStopped += OnGrabStopped;
cam.Open();
//加载用户设置1
cam.Parameters[PLCamera.UserSetSelector].SetValue(PLCamera.UserSetSelector.UserSet1);
//执行设置
bool bln = cam.Parameters[PLCamera.UserSetLoad].TryExecute();
return true;
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
}
public void Stop()
{
if (cam != null)
{
cam.StreamGrabber.Stop();
}
}
public Bitmap syncShot()
{
cam.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
cam.StreamGrabber.Start();
IGrabResult grabResult = cam.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
if (!grabResult.IsValid) return null;
Bitmap bmp = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
conv.OutputPixelFormat = PixelType.BGRA8packed;
IntPtr ptrBmp = bmpData.Scan0;
int picSize = bmpData.Stride * grabResult.Height;
conv.Convert(ptrBmp, picSize, grabResult);
byte[] buff = new byte[picSize];
System.Runtime.InteropServices.Marshal.Copy(ptrBmp, buff, 0, picSize);
bmp.UnlockBits(bmpData);
cam.StreamGrabber.Stop();
return bmp;
}
public void asynShot( )
{
try
{
cam.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
cam.StreamGrabber.Start(1, GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
}
catch (Exception ex)
{
ErrInfo = ex.Message;
}
}
public void ContinuousShot( )
{
try
{
cam.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
cam.StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
}
catch (Exception ex)
{
ErrInfo = ex.Message;
}
}
private void OnConnectionLost(Object sender, EventArgs e)
{
Close();
}
private void OnCameraOpened(Object sender, EventArgs e)
{
}
private void OnCameraClosed(Object sender, EventArgs e)
{
}
private void OnGrabStarted(Object sender, EventArgs e)
{
stopWatch.Reset();
}
private void OnGrabStopped(Object sender, GrabStopEventArgs e)
{
stopWatch.Reset();
}
private void OnImageGrabbed(Object sender, ImageGrabbedEventArgs e)
{
//IGrabResult grabResult = e.GrabResult;
//if (!grabResult.IsValid)
//{ return; }
//if (!stopWatch.IsRunning || stopWatch.ElapsedMilliseconds > 33)
//{
// stopWatch.Restart();
//}
//Common_Asa.Param.cameraBmp = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb);
//BitmapData bmpData = Common_Asa.Param.cameraBmp.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
//conv.OutputPixelFormat = PixelType.BGRA8packed;
//IntPtr ptrBmp = bmpData.Scan0;
//int picSize = bmpData.Stride * grabResult.Height;
//conv.Convert(ptrBmp, picSize, grabResult);
//Common_Asa.Param.cameraBuffer = new byte[picSize];
//System.Runtime.InteropServices.Marshal.Copy(ptrBmp, Common_Asa.Param.cameraBuffer, 0, picSize);
//Common_Asa.Param.cameraBmp.UnlockBits(bmpData);
}
}
}
......@@ -50,9 +50,9 @@ namespace URSoldering.Client
private void btnCodeTest_Click(object sender, EventArgs e)
{
FrmAOISetting frm = new FrmAOISetting(this);
this.Visible = false;
frm.Show();
//FrmAOISetting frm = new FrmAOISetting(this);
//this.Visible = false;
//frm.Show();
}
}
}
......@@ -19,6 +19,8 @@ namespace URSoldering.Client
{
public partial class FrmWork : FrmBase
{
private PylonCamera camera = new PylonCamera();
private System.Timers.Timer VideoTimer = new System.Timers.Timer();
//private static string VideoCameraName = ConfigAppSettings.GetValue(Setting_Init.VideoCameraName);
private URSolderingRobot Robot = null;
public FrmWork()
......@@ -64,37 +66,46 @@ namespace URSoldering.Client
btnStop.Enabled = false;
Robot.IsAutoRun = chbXunHuan.Checked;
LoadAOI();
VideoTimer = new System.Timers.Timer();
VideoTimer.Enabled = false;
VideoTimer.AutoReset = true;
VideoTimer.Interval = 300;
VideoTimer.Elapsed += VideoTimer_Elapsed;
}
private bool IsLoad = false;
private void LoadAOI()
{
if (IsLoad)
{
return;
}
//位置配置到文件中
string appPath = Application.StartupPath;
string strFilePathName = ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string path2 = Path.GetDirectoryName(appPath + strFilePathName);
string filePath = path2 + @"\" + BoardManager.CurrBoard.AoiFileName;
if (File.Exists(filePath))
{
try
{
axCKVisionCtrl1.LoadConfigure(filePath);
axCKVisionCtrl1.ZoomView(2);
LogUtil.error("成功加载程序:" + BoardManager.CurrBoard.AoiFileName);
IsLoad = true;
}
catch (Exception ex)
{
LogUtil.error("加载程序【" + BoardManager.CurrBoard.AoiFileName + "】出错:" + ex.ToString());
}
}
else
{
LogUtil.error("未找到AOI程序文件:" + BoardManager.CurrBoard.AoiFileName);
}
//if (IsLoad)
//{
// return;
//}
////位置配置到文件中
//string appPath = Application.StartupPath;
//string strFilePathName = ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
//string path2 = Path.GetDirectoryName(appPath + strFilePathName);
//string filePath = path2 + @"\" + BoardManager.CurrBoard.AoiFileName;
//if (File.Exists(filePath))
//{
// try
// {
// axCKVisionCtrl1.LoadConfigure(filePath);
// axCKVisionCtrl1.ZoomView(2);
// LogUtil.error("成功加载程序:" + BoardManager.CurrBoard.AoiFileName);
// IsLoad = true;
// }
// catch (Exception ex)
// {
// LogUtil.error("加载程序【" + BoardManager.CurrBoard.AoiFileName + "】出错:" + ex.ToString());
// }
//}
//else
//{
// LogUtil.error("未找到AOI程序文件:" + BoardManager.CurrBoard.AoiFileName);
//}
}
private int ShowPointIndex = 5;
private void LoadCountPoint(bool isToday)
......@@ -517,7 +528,8 @@ namespace URSoldering.Client
{
Robot.StopRun();
}
axCKVisionCtrl1.UnloadConfigure();
btnStopVideo_Click(null, null);
//axCKVisionCtrl1.UnloadConfigure();
}
private void btnStart_Click(object sender, EventArgs e)
......@@ -672,42 +684,43 @@ namespace URSoldering.Client
private bool RunAOI(int num)
{
try
{
axCKVisionCtrl1.Execute(num);
axCKVisionCtrl1.ZoomView(2);
axCKVisionCtrl1.Redraw();
Thread.Sleep(1000);
axCKVisionCtrl1.Execute(num);
axCKVisionCtrl1.ZoomView(2);
axCKVisionCtrl1.Redraw();
return true;
}
catch (Exception ex)
{
LogUtil.error("Error: Could not extcute proc. Original error: " + ex.Message);
return false;
}
//try
//{
// axCKVisionCtrl1.Execute(num);
// axCKVisionCtrl1.ZoomView(2);
// axCKVisionCtrl1.Redraw();
// Thread.Sleep(1000);
// axCKVisionCtrl1.Execute(num);
// axCKVisionCtrl1.ZoomView(2);
// axCKVisionCtrl1.Redraw();
// return true;
//}
//catch (Exception ex)
//{
// LogUtil.error("Error: Could not extcute proc. Original error: " + ex.Message);
// return false;
//}
return false;
}
private int CKResult(string name,int dataId)
{
string result = "";
try
{
int idTool = axCKVisionCtrl1.GetTool(name);
//try
//{
// int idTool = axCKVisionCtrl1.GetTool(name);
double value = 0.0;
object objValue = new VariantWrapper(value);
if (axCKVisionCtrl1.GetValue(idTool, dataId, 0, ref objValue) == true)
{
result = objValue.ToString();
}
LogUtil.info("获取【" + name + "】:" + result);
}
catch (Exception ex)
{
LogUtil.error("获取【" + name + "】出错:" + ex.ToString());
}
// double value = 0.0;
// object objValue = new VariantWrapper(value);
// if (axCKVisionCtrl1.GetValue(idTool, dataId, 0, ref objValue) == true)
// {
// result = objValue.ToString();
// }
// LogUtil.info("获取【" + name + "】:" + result);
//}
//catch (Exception ex)
//{
// LogUtil.error("获取【" + name + "】出错:" + ex.ToString());
//}
if (result.ToLower().Equals("true"))
{
......@@ -767,5 +780,56 @@ namespace URSoldering.Client
MessageBox.Show("焊接失败:" + msg);
}
}
private void btnStartVideo_Click(object sender, EventArgs e)
{
string[] nameStr= camera.GetName();
if (nameStr.Length > 0)
{
if (camera.Open(0))
{
VideoTimer.Start();
}
}
}
private void btnStopVideo_Click(object sender, EventArgs e)
{
if (VideoTimer.Enabled)
{
VideoTimer.Start();
camera.Close();
}
}
private bool IsInProcess = false;
private void VideoTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (IsInProcess)
{
return;
}
IsInProcess = true;
//int index = cmbCamera.SelectedIndex;
//if (index < 0)
//{
// MessageBox.Show("请先选择相机");
// return;
//}
//camera.Open(index);
try
{
Bitmap bit = camera.syncShot();
if (bit != null)
{
this.picVideo.Image = bit;
}
}catch(Exception ex)
{
LogUtil.error(ex.ToString());
}
IsInProcess = false;
///*camera*/.Close();
}
}
}
......@@ -120,14 +120,6 @@
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="axCKVisionCtrl1.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAJQAAAAIB
AAAAAQAAAAAAAAAAAAAAABAAAAAAAAEAaAkAAKM4AAAAAAAACw==
</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>38</value>
</metadata>
......
......@@ -63,6 +63,16 @@ namespace URSoldering.Client.Properties {
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap smart_devices_logo03 {
get {
object obj = ResourceManager.GetObject("smart devices logo03", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap TE048_311000 {
get {
object obj = ResourceManager.GetObject("TE048-311000", resourceCulture);
......@@ -79,5 +89,15 @@ namespace URSoldering.Client.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 锐驰科技 {
get {
object obj = ResourceManager.GetObject("锐驰科技", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
......@@ -112,17 +112,22 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TE048-311000" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TE048-311000.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="锐驰科技" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\image\锐驰科技.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TE075-022030" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TE075-022030.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="TE048-311000" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TE048-311000.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="smart devices logo03" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\image\smart devices logo03.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
\ No newline at end of file
......@@ -73,12 +73,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FrmAOISetting.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmAOISetting.designer.cs">
<DependentUpon>FrmAOISetting.cs</DependentUpon>
</Compile>
<Compile Include="FrmBase.cs">
<SubType>Form</SubType>
</Compile>
......@@ -177,9 +171,6 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="FrmAOISetting.resx">
<DependentUpon>FrmAOISetting.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmBase.resx">
<DependentUpon>FrmBase.cs</DependentUpon>
</EmbeddedResource>
......@@ -278,23 +269,6 @@
<None Include="Resources\TE075-022030.jpg" />
</ItemGroup>
<ItemGroup>
<COMReference Include="AxCKVisionCtrlLib">
<Guid>{6649CE3E-A124-4D88-A05C-75D91DBE4F14}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="CKVisionCtrlLib">
<Guid>{6649CE3E-A124-4D88-A05C-75D91DBE4F14}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="stdole">
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
<VersionMajor>2</VersionMajor>
......@@ -306,6 +280,8 @@
</COMReference>
</ItemGroup>
<ItemGroup>
<None Include="image\锐驰科技.png" />
<None Include="image\smart devices logo03.png" />
<Content Include="robot.ico" />
<Content Include="记录.txt" />
</ItemGroup>
......
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!