一、相机硬件接线图
2号引脚接传感器的触发信号引脚,5号与传感器共地连接。
二、pylon软件设置
三、halcon软触发相机拍照
Halcon采集助手设置软触发:
1.set_framegrabber_param (AcqHandle, 'TriggerMode', 'On')
2.set_framegrabber_param (AcqHandle, 'TriggerSource', 'Software')
还有注意就是,软触发不要设置grab_timeout采集超时,否则会一直卡住Halcon的,硬触发可以开启!
那么怎么触发呢?点击下面红色方框里面的TriggerSoftWare就可以触发采集了!
不能在Halcon里面用代码实现触发采集,因为采集图像是同步进行的。
可以使用C#联合Halcon开发,在C#里面利用set_framegrabber_callback设置回调方式进行,Halcon里面是不支持的!
四、C#联合Halcon实现外部触发回调函数采集图像
1 HalconDotNet.HalconAPI.HFramegrabberCallback delegateCallback; //定义回调函数委托
2
3
4 //开启相机
5 HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive",
6 -1, "default", -1, "false", "default", "Devin",
7 0, -1, out hv_AcqHandle);
8 //下面开启硬触发
9 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "TriggerMode", "On");
10 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "TriggerSource", "Line1");
11 //下面设置连续采集,上升沿触发,曝光模式等
12 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "AcquisitionMode", "Continuous");
13 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "TriggerSelector", "FrameStart");
14 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "TriggerActivation", "RisingEdge");
15 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureMode", "Timed");
16 //设置曝光时间
17 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureTime", 80000.0);
18 //下面为设置用不超时
19 HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "grab_timeout", -1);
20 //给委托绑定
21 delegateCallback = MyCallbackFunction;
22
23
24 private int test = 1;//随便定义的一个变量,后面会取其地址带入回调函数的user_context
25
26
27 //回调函数
28 public int MyCallbackFunction(IntPtr handle, IntPtr context, IntPtr user_context)
29 {
30 try
31 {
32 HOperatorSet.GrabImage(out img, hv_AcqHandle);
33 if (this.hWindowControl1.InvokeRequired)//线程亲和性判定
34 {
35 this.Invoke(new MethodInvoker(() => { HOperatorSet.DispObj(img, this.hWindowControl1.HalconWindow); img.Dispose(); }));//把图像显示出来(这里是委托方式显示)
36 }
37 else
38 {
39 HOperatorSet.DispObj(img, this.hWindowControl1.HalconWindow);//把图像显示出来
40 img.Dispose();
41 }
42 return 0;
43 }
44 catch (Exception ex)
45 {
46 // MessageBox.Show(ex.Message);//显示错误
47 return -1;
48 }
49 }
50
51
52 IntPtr ptr = Marshal.GetFunctionPointerForDelegate(delegateCallback);//取回调函数的地址
53 IntPtr ptr1 = GCHandle.Alloc(test, GCHandleType.Pinned).AddrOfPinnedObject();//取test变量的地址
54 HOperatorSet.SetFramegrabberCallback(hv_AcqHandle, "LineStatus", ptr, ptr1);//注册回调函数
55 IntegralforLove/java/article/details/94722689