Visionpro学习笔记 :QuickBuild-Based Application Run-Once Button
1) Creating a Run-Once Button
通过JobManager调用VisionPro文件。所有的过程放到一个Try/Catch块中。
Private Sub RunOnceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunOnceButton.Click Try myJobManager.Run() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 多次点击Button会发现有错误:CogNotStopperException。原因是我们是异步调用VisionPro的,要等到程序结束之后才可以继续调用。
2) Handling Job Manager Events
防止用户在程序未完时再次调用:
Private Sub RunOnceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunOnceButton.Click Try RunOnceButton.Enabled = False myJobManager.Run() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 同时需要在Job完成时通知用户Button可以再次使用了。于是添加JobManager的Stopped事件:
Private Sub myJobManager_Stopped(ByVal sender As Object, ByVal e As CogJobManagerActionEventArgs) RunOnceButton.Enabled = True End Sub
接下来如何让Job manager知道有这么一个事件在等他:利用Addhandler来注册事件的句柄:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myJobManager = CType(CogSerializer.LoadObjectFromFile("C:\Program Files\Cognex\VisionPro\Samples\Programming\QuickBuild\advancedAppOne.vpp"), CogJobManager) myJob = myJobManager.Job(0) myIndependentJob = myJob.OwnedIndependent
myJobManager.UserQueueFlush() myJobManager.FailureQueueFlush() myJob.ImageQueueFlush() myIndependentJob.RealTimeQueueFlush()
AddHandler myJobManager.Stopped, AddressOf myJobManager_Stopped End Sub 当注册事件的句柄时,在程序关闭时需要移除句柄:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing RemoveHandler myJobManager.Stopped, AddressOf myJobManager_Stopped myJobManager.Shutdown() End Sub 当我们运行以上程序时还会有错误:Cross-thread operation not valid。
3)Handling Cross-Thread Function Calls
Remember that the job manager creates several threads. One of these threads fires the Stoppedevent that runs the stopped event handler and eventually attempts to reenable the Run Oncebutton. This sequence of events is illegal because a button -- or any other Microsoft Windows Forms control -- can only be accessed by the thread that created that control. The button was not created by any of the job manager threads.
原因是Job manager在运行时同时创建了几个线程。当其中某一个线程完成时也会触发Stopped事件,这时显示的“Run Once”按钮可用是虚假的。如何保证在真正完成时触发,可考虑用Delegate,委托是类型安全的。
在Stopped事件句柄之前添加:
Delegate Sub myJobManagerDelegate(Byval sender As Object, ByVal e As CogJobManagerActionEventArgs)
检查句柄是否为错误的线程调用,如果是的话就利用委托创建句柄的指针,再用Invoke循环调用:
Private Sub myJobManager_Stopped(ByVal sender As Object, ByVal e As CogJobManagerActionEventArgs) If InvokeRequired Then Dim myDel As New myJobManagerDelegate(AddressOf myJobManager_Stopped) Dim eventArgs() As Object = {sender, e}
Invoke(myDel, eventArgs) Return End If RunOnceButton.Enabled = True End Sub
Visionpro学习笔记 :QuickBuild-Based Application Run-Once Button的更多相关文章
- Visionpro学习笔记(壹)
注册4年,第一次发了随笔.我的博客将主要涉及到visionPro软件的学习,labview数据采集方面的思考,c#及VS的学习 此随笔系列主要是关于VisionPro(以后简称VP)的学习及使用. 近 ...
- Spark学习笔记1:Application,Driver,Job,Task,Stage理解
看了spark的原始论文和相关资料,对spark中的一些经常用到的术语做了一些梳理,记录下. 1,Application application(应用)其实就是用spark-submit提交的程序.比 ...
- VisionPro学习笔记:用IEEE1394相机抓取图像
1)找到采集卡: CogFrameGrabber1394DCAMs cameras = new CogFrameGrabber1394DCAMs(); 2)列举相连接的相机: ICogFrameGra ...
- php学习笔记之动态生成一组单选button
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Self-Host c#学习笔记之Application.DoEvents应用 不用IIS也能執行ASP.NET Web API
Self-Host 寄宿Web API 不一定需要IIS 的支持,我们可以采用Self Host 的方式使用任意类型的应用程序(控制台.Windows Forms 应用.WPF 应用甚至是Wind ...
- [原创]java WEB学习笔记47:Servlet 监听器简介, ServletContext(Application 对象), HttpSession (Session 对象), HttpServletRequest (request 对象) 监听器,利用listener理解 三个对象的生命周期
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务(老罗学习笔记6)
一:Eclipse下 1.创建工程: ---- 2.创建后目录 3.添加java函数 4.在src下创建package,在package下创建file 5.res---layout下创建xml文件,命 ...
- [原创]java WEB学习笔记15:域对象的属性操作(pageContext,request,session,application) 及 请求的重定向和转发
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- Spring boot 官网学习笔记 - Spring Boot 属性配置和使用(转)-application.properties
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overridin ...
随机推荐
- python Database Poll for SQL SERVER
python连接SQL SERVER数据库: Python编程中可以使用SQL SERVER 进行数据库的连接及诸如查询/插入/更新等操作,但是每次连接SQL SERVER 数据库请求时,都是独立的去 ...
- 一个大四毕业生想对自学Android的大学生说一些话
本人大四,经历了秋招和春招,秋招拿了华为的android offer,春招是拿的java后台开发的offer,一路走来,感慨很多,有一些话想对在自学Android的大学生说.本文只是帮助像我一样的大学 ...
- Nginx是如何处理Request的?
nginx是如何匹配过来的请求,然后做处理的呢?这个匹配的过程可以分为两步: 1.选择server 2.选择location 选择server 仅仅匹配server name 加入Nginx的配 ...
- 关于soapui简介与入门
SoapUI简介 SoapUI是一个开源测试工具,通过soap/http来检查.调用.实现Web Service的功能/负载/符合性测试.该工具既可作为一个单独的测试软件使用,也可利用插件集成到Ecl ...
- MySQL索引 - 索引的类型
索引的类型 B-Tree索引 B-Tree 索引 通常意味着所有的值都是按顺序存储的,并且每一个叶子页到根的距离相同. B-Tree 索引 能够加快访问数据的速度,存储引擎不再需要进行全表扫描来获取需 ...
- 线程池的使用及ThreadPoolExecutor的分析(一)
说明:本作者是文章的原创作者,转载请注明出处:本文地址:http://www.cnblogs.com/qm-article/p/7821602.html 一.线程池的介绍 在开发中,频繁的创建和销毁一 ...
- flask设置配置文件的四钟方式
# -*- coding: utf-8 -*- DEBUG = True # -*- coding: utf-8 -*- from flask import Flask,session,current ...
- 开发 | 微信小程序API-wx.setScreenBrightness/wx.getScreenBrightness
前言 最近接触了微信小程序 API - wx.setScreenBrightness .wx.getScreenBrightness 接口,调用该接口可以调节并显示手机屏幕亮度数据.对于喜欢腾讯新闻. ...
- [bzoj2462] [BeiJing2011]矩阵模板
二维的hash.. 注意n的范围是1000........ 真相似乎是全部输出1就行了233 #include<cstdio> #include<iostream> #incl ...
- CodeForces839-B. Game of the Rows-水题(贪心)
最近太zz了,老是忘记带脑子... 补的以前的cf,发现脑子不好使... B. Game of the Rows time limit per test 1 second memory limit ...