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 ...
随机推荐
- Coursera课程 Programming Languages 总结
课程 Programming Languages, Part A Programming Languages, Part B Programming Languages, Part C CSE341: ...
- 重构仿vue社区代码
半年前根据vue社区提供的开放api制作的vue社区,功能大部分和原vue社区一样,还一些功能没做完,项目是半年前做的,已经过了半年,当时因为公司一个项目打算要vue来重构,提取小试牛刀做了个dom试 ...
- js面向对象学习笔记(五):tab切换
重点是this指向问题 <style> .hide{display: none;} #box div,#box1 div{display: none;} .hover{background ...
- [bzoj4240] 有趣的家庭菜园
还是膜网上题解QAQ 从低到高考虑,这样就不会影响后挪的草了. 每次把草贪心地挪到代价较小的一边.位置为i的草,花费为min( 1..i-1中更高的草的数目,i+1..n中更高的草的数目 ) 因为更小 ...
- use ambiguous的错误——编译错误
出现这样的问题是因为namespace std里面已经有一个count了,而 using namespace std;语句把该namespace 打开了,这导致了后面的引用不明确: 不过这里也可以把u ...
- Centos7搭建Confluence破解版
Confluence破解版 应用环境: Confluence是一个专业的企业知识管理与协同软件,也可以用于构建企业wiki.通过它可以实现团队成员之间的协作和知识共享. 系统及安装软件 centos7 ...
- c++(数据选择)
在数学中,有一些数据选择的内容.举个例子来说,有这样一组数据:1.2.3.4.现在我们打算从中挑选出1个数据,那么有几种选择呢?结果应该是1.2.3.4:那么如果挑选2个数据呢,怎么选呢?那么结果应该 ...
- Scrum已经俘获中国开发者的心? ——从《2017年开发者调查报告》看真相!
云栖社区通过为期两个月,对7032份有效调查问卷分析统计,2017年12月发布了首份<2017中国开发者调查报告>.报告显示,37.3%的开发者表示,协作工具主要来自企业内部自研的协作工具 ...
- Spark学习笔记3(IDEA编写scala代码并打包上传集群运行)
Spark学习笔记3 IDEA编写scala代码并打包上传集群运行 我们在IDEA上的maven项目已经搭建完成了,现在可以写一个简单的spark代码并且打成jar包 上传至集群,来检验一下我们的sp ...
- VisualSVN Server启动错误(0x8007042a)
SVN Server启动错误(0x8007042a) 原因是SVN Server端口被占用 打开VisualSVN Server, 菜单->操作->Properties->Net ...