VisionPro - VisionPro Advanced – Section 2 Building a VB.Net App Step 1 Lab Approximate Duration: 15 minutes môn Tiếng Anh | Học viện Nông nghiệp Việt Nam

In VisualStudio view the GUI designer window.• Drag a button to the form from the “Common Controls” section of the toolbox.• Change the text of the button to “Run Once”.• Change the name of the button to “btnRunOnce”.• Double-click on the button to automatically generate the btnRunOnce_Click method. • Add the following code to the btnRunOnce_Click() method. Tài liệu giúp bạn tham  khảo, ôn tập và đạt kết quả cao. Mời đọc đón xem!

Môn:

Tiếng Anh (HVNN) 87 tài liệu

Trường:

Học viện Nông nghiệp Việt Nam 593 tài liệu

Thông tin:
6 trang 2 tuần trước

Bình luận

Vui lòng đăng nhập hoặc đăng ký để gửi bình luận.

VisionPro - VisionPro Advanced – Section 2 Building a VB.Net App Step 1 Lab Approximate Duration: 15 minutes môn Tiếng Anh | Học viện Nông nghiệp Việt Nam

In VisualStudio view the GUI designer window.• Drag a button to the form from the “Common Controls” section of the toolbox.• Change the text of the button to “Run Once”.• Change the name of the button to “btnRunOnce”.• Double-click on the button to automatically generate the btnRunOnce_Click method. • Add the following code to the btnRunOnce_Click() method. Tài liệu giúp bạn tham  khảo, ôn tập và đạt kết quả cao. Mời đọc đón xem!

23 12 lượt tải Tải xuống
lOMoARcPSD| 47708777
VisionPro - VisionPro Advanced Section 2
Building a VB.Net App Step 1 Lab
Approximate Duration: 15 minutes
The following may be used as a reference on the basic steps for building a VisionPro application in Microsoft
Visual Basic .NET. This should be used in conjunction with the notes presented in Section 2 of the class.
Objectives:
Construct the framework of a Simple Custom Application using development model 3
Start a new project
Open VisualStudio 2010 Express
Create a new VB.NET Windows application named “VBSampleApp”.
Add references to these .NET assemblies:
Cognex.VisionPro defines low-level objects
Cognex.VisionPro.Core more low-level stuff
Cognex.VisionPro.QuickBuild.Core the CogJobManager lives here.
Import your Namespaces, Declare your variables
In VisualStudio open the code window for “Form1.vb” and at the very top type:
Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild
Public Class Form1
End Class
Also type declarations for three instance variables inside your “Form1” class:
Public Class Form1
lOMoARcPSD| 47708777
Private WithEvents myJobManager As CogJobManager
Private myJob As CogJob
Private myIndependentJob As CogJobIndependent
End Class
Load your saved CogJobManager in the Form1_Load() event handler, setup your variables and prepare the
CogJobManager to run.
Back in VisualStudio, switch tabs to the GUI designer and double-click on your form.
This creates a “Form1_Load()” method that will be called when your application first loads.
Add the following code to Form1_Load:
'Load your QuickBuild application
myJobManager = CType( _
CogSerializer.LoadObjectFromFile( _
"C:\Documents and Settings\mperez\My _
Documents\Temp\Cognex\VisionPro\Demos\DemoPlate.vpp"), _
CogJobManager)
'Initialize variable myJob =
myJobManager.Job("CogJob1")
myIndependentJob = myJob.OwnedIndependent
'Flush queues
myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush()
myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush()
Make sure the Application closes gracefully.
In VisualStudio select the “FormClosing” event from the right-hand dropdown box at the top of the
code window.
This creates a Form1_FormClosing method that will be called when you close the form.
Add the following code to the method:
'Shut down the CogJobManager to clean up threads properly
myJob.AcqFifo.FrameGrabber.Disconnect(False)
myJobManager.Shutdown()
Run Your App
lOMoARcPSD| 47708777
Add a RunOnce button to the GUI.
In VisualStudio view the GUI designer window.
Drag a button to the form from the “Common Controls” section of the toolbox.
Change the text of the button to “Run Once”.
Change the name of the button to “btnRunOnce”.
Double-click on the button to automatically generate the btnRunOnce_Click method.
Add the following code to the btnRunOnce_Click() method.
'Attempt to run the application
Try
myJobManager.Run()
Catch ex As Exception
'If there is a problem show the error message
MessageBox.Show(ex.Message)
End Try
Run your App
We’ve created a simple application that uses our saved CJM and can be run on its own.
Test your app by running it. Click on the “RunOnce” button.
Now click the btnRunOnce as fast as you can.
Notice that you quickly get an error from “CogJobManager1”.
In Part 2 we’ll fix this error.
Complete Solution (in VB)
lOMoARcPSD| 47708777
Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild
Public Class Form1
Private WithEvents myJobManager As CogJobManager
Private myJob As CogJob
Private myIndependentJob As CogJobIndependent
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Shut down the CogJobManager to clean up threads properly
myJob.AcqFifo.FrameGrabber.Disconnect(False)
myJobManager.Shutdown()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
'Load your QuickBuild application
myJobManager = CType( _
CogSerializer.LoadObjectFromFile( _
"C:\Documents and Settings\mperez\My
Documents\Temp\Cognex\VisionPro\Demos\DemoPlate.vpp"), _
CogJobManager)
'Initialize variable myJob =
myJobManager.Job("CogJob1")
myIndependentJob = myJob.OwnedIndependent
'Flush queues
myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush()
myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush()
End Sub
Private Sub btnRunOnce_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRunOnce.Click
'Attempt to run the application
Try myJobManager.Run()
Catch ex As Exception
'If there is a problem show the error message
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
lOMoARcPSD| 47708777
Complete Solution (in C#)
using System;
using System.Collections.Generic;
using System.ComponentModel; using
System.Data; using System.Drawing;
using System.Linq; using
System.Text; using
System.Windows.Forms;
using Cognex.VisionPro; using
Cognex.VisionPro.QuickBuild;
namespace May2013_VPro
{ public partial class Form1 :
Form
{
private CogJobManager myJobManager;
private CogJob myJob;
private CogJobIndependent myIndependentJob;
public
Form1()
{
InitializeComponent();
// Load QuickBuild Application
myJobManager =
(CogJobManager)(CogSerializer.LoadObjectFromFile(@"C:\MyDataAnalysis.vpp"));
// Initialize variables myJob =
myJobManager.Job("CogJob1");
myIndependentJob = myJob.OwnedIndependent;
// Flush Queues
myJobManager.UserQueueFlush();
myJobManager.FailureQueueFlush();
myJob.ImageQueueFlush();
myIndependentJob.RealTimeQueueFlush();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Gracefully clean up threads
myJob.AcqFifo.FrameGrabber.Disconnect(false); myJobManager.Shutdown();
}
private void btnRunOnce_Click(object sender, EventArgs e)
{ try {
myJobManager.Run();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
lOMoARcPSD| 47708777
}
}
| 1/6

Preview text:

lOMoAR cPSD| 47708777
VisionPro - VisionPro Advanced – Section 2
Building a VB.Net App Step 1 Lab
Approximate Duration: 15 minutes
The following may be used as a reference on the basic steps for building a VisionPro application in Microsoft
Visual Basic .NET. This should be used in conjunction with the notes presented in Section 2 of the class. Objectives:
Construct the framework of a Simple Custom Application using development model 3
Start a new project
• Open VisualStudio 2010 Express
• Create a new VB.NET Windows application named “VBSampleApp”.
• Add references to these .NET assemblies:
 Cognex.VisionPro  defines low-level objects
 Cognex.VisionPro.Core  more low-level stuff
 Cognex.VisionPro.QuickBuild.Core  the CogJobManager lives here.
Import your Namespaces, Declare your variables
• In VisualStudio open the code window for “Form1.vb” and at the very top type: Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild Public Class Form1 End Class
• Also type declarations for three instance variables inside your “Form1” class: Public Class Form1 lOMoAR cPSD| 47708777
Private WithEvents myJobManager As CogJobManager Private myJob As CogJob
Private myIndependentJob As CogJobIndependent End Class
Load your saved CogJobManager in the Form1_Load() event handler, setup your variables and prepare the
CogJobManager to run.
• Back in VisualStudio, switch tabs to the GUI designer and double-click on your form.
• This creates a “Form1_Load()” method that will be called when your application first loads.
• Add the following code to Form1_Load:
'Load your QuickBuild application myJobManager = CType( _
CogSerializer.LoadObjectFromFile( _
"C:\Documents and Settings\mperez\My _
Documents\Temp\Cognex\VisionPro\Demos\DemoPlate.vpp"), _ CogJobManager) 'Initialize variable myJob = myJobManager.Job("CogJob1")
myIndependentJob = myJob.OwnedIndependent 'Flush queues myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush() myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush()
Make sure the Application closes gracefully.
• In VisualStudio select the “FormClosing” event from the right-hand dropdown box at the top of the code window.
• This creates a Form1_FormClosing method that will be called when you close the form.
• Add the following code to the method:
'Shut down the CogJobManager to clean up threads properly
myJob.AcqFifo.FrameGrabber.Disconnect(False)
myJobManager.Shutdown() Run Your App lOMoAR cPSD| 47708777
Add a RunOnce button to the GUI.
• In VisualStudio view the GUI designer window.
• Drag a button to the form from the “Common Controls” section of the toolbox.
• Change the text of the button to “Run Once”.
• Change the name of the button to “btnRunOnce”.
• Double-click on the button to automatically generate the btnRunOnce_Click method.
• Add the following code to the btnRunOnce_Click() method.
'Attempt to run the application Try myJobManager.Run() Catch ex As Exception
'If there is a problem show the error message MessageBox.Show(ex.Message) End Try Run your App
• We’ve created a simple application that uses our saved CJM and can be run on its own.
• Test your app by running it. Click on the “RunOnce” button.
• Now click the btnRunOnce as fast as you can.
• Notice that you quickly get an error from “CogJobManager1”.
• In Part 2 we’ll fix this error.
Complete Solution (in VB) lOMoAR cPSD| 47708777 Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild Public Class Form1
Private WithEvents myJobManager As CogJobManager Private myJob As CogJob
Private myIndependentJob As CogJobIndependent
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Shut down the CogJobManager to clean up threads properly
myJob.AcqFifo.FrameGrabber.Disconnect(False) myJobManager.Shutdown() End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Load your QuickBuild application myJobManager = CType( _
CogSerializer.LoadObjectFromFile( _
"C:\Documents and Settings\mperez\My
Documents\Temp\Cognex\VisionPro\Demos\DemoPlate.vpp"), _ CogJobManager) 'Initialize variable myJob = myJobManager.Job("CogJob1")
myIndependentJob = myJob.OwnedIndependent 'Flush queues myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush() myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush() End Sub
Private Sub btnRunOnce_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRunOnce.Click
'Attempt to run the application Try myJobManager.Run() Catch ex As Exception
'If there is a problem show the error message MessageBox.Show(ex.Message) End Try End Sub End Class lOMoAR cPSD| 47708777
Complete Solution (in C#) using System;
using System.Collections.Generic;
using System.ComponentModel; using
System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Cognex.VisionPro; using Cognex.VisionPro.QuickBuild; namespace May2013_VPro
{ public partial class Form1 : Form {
private CogJobManager myJobManager; private CogJob myJob;
private CogJobIndependent myIndependentJob; public Form1() { InitializeComponent();
// Load QuickBuild Application myJobManager =
(CogJobManager)(CogSerializer.LoadObjectFromFile(@"C:\MyDataAnalysis.vpp"));
// Initialize variables myJob = myJobManager.Job("CogJob1");
myIndependentJob = myJob.OwnedIndependent; // Flush Queues
myJobManager.UserQueueFlush();
myJobManager.FailureQueueFlush(); myJob.ImageQueueFlush();
myIndependentJob.RealTimeQueueFlush(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
// Gracefully clean up threads
myJob.AcqFifo.FrameGrabber.Disconnect(false); myJobManager.Shutdown(); }
private void btnRunOnce_Click(object sender, EventArgs e) { try { myJobManager.Run(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } lOMoAR cPSD| 47708777 } }