From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Save CWIMAQViewer image & overlay in VB

hi all,
 
having solved the earlier problem,i have run into another error.
i have defined this program as a class library in vb.net..and i am attempting to use it in another vb.net project(which is a console app).the reason i use a console app is because i dont want any display from the program.i just want it to return 1 if its successful and 0 if its not.
i get this error : An unhandled exception of type 'InvalidActiveXStateException' occurred in nationalinstruments.axcwimaqcontrolslib.interop.dll
at:                     IMAQVision.LearnColor(myImage, ColInfo, ViewRect)
 
here's my code:

Dim IMAQVision As New NationalInstruments.CWIMAQControls.AxCWIMAQVision

*************************************************************************************************

Public Sub New()

MyBase.New()

myImage = New NationalInstruments.CWIMAQControls.CWIMAQImage

t1 = New System.Timers.Timer(250)

myImage.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeRGB32

errorCode = CWIMAQ1394.CameraOpen2("cam0", CWIMAQ1394.CameraMode.IMG1394_CAMERA_MODE_CONTROLLER, sid)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

GoTo ErrorHandler

End If

t1.Enabled =

True

errorCode = CWIMAQ1394.SetupGrabCW(sid)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

GoTo ErrorHandler

End If

ErrorHandler:

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

End If

End Sub

*************************************************************************************************

Public Function GetLedColor() As Integer

'Dim objTest As VisionTool = New VisionTool

Dim roi As New CWIMAQRegions

Dim roiRect As New CWIMAQRectangle

roiRect.Initialize(111, 54, 7, 15)

ViewRect.AddRectangle(roiRect)

IMAQVision.LearnColor(myImage, ColInfo, ViewRect)

IMAQVision.MatchColor(myImage, ColInfo, Scores, ViewRect)

Return 2

End Function

*******************************************************************************************************

Public Sub TimerFired(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles t1.Elapsed

errorCode = CWIMAQ1394.Grab2CW(sid, 1, BufferNumber, myImage)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

t1.Enabled =

False

End If

End Sub

End

Class

all i can figure out is,there is some control that a console application cannot handle.but the only control in this code is the CWIMAQControl. (i removed the viewer, and the windows timer control)without it i cant access any of the vision functions.is there any way around this?Smiley Sad

0 Kudos
Message 11 of 20
(7,920 Views)
hi all,
i managed to solve the problem..i added this code in my form load event: IMAQVision.createcontrol(). and that did the trick.however,there's something weird going on in my program.when i step thru the code manually(using F11 key),i get the output,no problem.but when i remove all the breakpoints and let it run normally,i get 1000 as the output everytime.wat could be the problem?seems like the program is not performing the matching function properly..any ideas?
0 Kudos
Message 12 of 20
(7,909 Views)
hi,
well,the problem is delay again..seems like when the matching function is called,the ColInfo doesnt have the information yet..so,i inserted a delay after LearnColor,and it worked fine..but i have to admit that its slowing down the execution.if anyone can tell me if there;s any other way..would be very helpful..
thanks..
0 Kudos
Message 13 of 20
(7,895 Views)
rebecs,

It looks like you've got this issue open on these other two threads as well. 

delay in output

VDM8.0: InvalidActiveXStateException thrown by AxCWIMAQVision.MatchPattern

Please continue to use the delay in output thread for this issue.  In the future, please keep one thread per issue.  This is important for several reasons.
  1. It allows other users to more easily follow the conversation on a particular issue.
  2. It causes less clutter on the forums by having each thread be a separate issue.
  3. It helps NI better track support issues for customers.
As for the delay, I'm still not convinced that its caused by creating an image data structure aside from an image control.  I think something else may be the cause.

Regards,
Luke H

Message Edited by Luke H on 06-06-2007 10:05 AM

0 Kudos
Message 14 of 20
(7,870 Views)
hi luke,
 
sorry for the multiple posts again..actually,i posted in different forums for different errors,and after solving all those error,im down to the delay problem.i will stick to the ' delay in output' thread from now..thanks Smiley Happy
0 Kudos
Message 15 of 20
(7,863 Views)

Another thing that can be said about IMAQ ActiveX,  multi-threading and forms

 

IMAQ 8.0 is an ActiveX wrapped for dotNet 2.0

The requirements for activeX is that they method must be called from the STA thread that has created them.

For instance if you want to do multithreading with IMAQ, create multiple thread, each thread hosting the message loop of a form that contains IMAQ processing.

 

Example:

 

class Main

   private shared sub m_fThreadProc

       Application.Run(new Form_Ni_Processing)

   end sub

 

   public sub New()

        InitializeComponent()

        for i as integer=0 to 3

             dim t as new thread(addressOf fThreadProc)

             t.SetApartmentState(ApartmentState.STA)

             t.Start()

        next

end

0 Kudos
Message 16 of 20
(5,795 Views)

Oups ,  I forgot one thing:

 

after each thread start, do a sleep for 1 second:

threading.thread.currentThread.Sleep(1000)

 

when using multi threading occurences of IMAQ, it avoids the occurence of Reflection.TargetException ....

 

don't ask me why, but it is the way I solved this NI issue.

Otherwise you can step back to good old C++  Smiley Happy

0 Kudos
Message 17 of 20
(5,793 Views)

Hi,

 

I'm developing one application using NI Vision 8.2.1 and VB6.

I'm facing an error "31913 - Invalid Template Descriptor" for my pattern matching function.

I'm very new to VB. I'm working on an already developed code which is functioning fine and I want to modify this code for my application.

The patterns currently available are working fine with the application. But I want to create new patterns for my new application.

I have gone through the following link, and it gives a LabVIEW based example for creating Templates.

http://digital.ni.com/public.nsf/websearch/F05924D50AD6472B86256F320075CDBF?OpenDocument

Can anyone please provide me an example code in VB6 which can create Templates?

 

Thanks in advance...

Into the pursuit...
Maverick
0 Kudos
Message 18 of 20
(4,758 Views)

Hi Maverick,

 

I am not any more fluent with VB6.

My best advice will be to ask you if you know .Net technologies ? There are a lot of good example on on how to use templates .... however not on how to create them.

Here my best advice is to tell you to read the concept manual AND to look carefully at the function description (in the help file).

 

In Vision Assistant there is also a tool that allows to create C code; so you can create a script and then export it in C .... and see what functions are called and from which DLL.

 

One last thing to know about template: template information associated with an image can be saved with the image (under the NI PNG format) using a function whose name might be like WriteFileAndVisionInformation() .

It means that ONE PNG file can contain the image, the pattern matching definition, the geometric template and the goldent template AT ONCE !!!

 

If you need more info  you can write me directly at areymondier@aureus-ingenierie.fr

 

regards

 

I am

0 Kudos
Message 19 of 20
(4,752 Views)

Hi everybody!

I am trying to do a mirror image of the video that i grabbed using ez grabber devices.

However, the program seems unstable.

Sometimes it shows the image correctly, other times it just stop the program with a warning "The image is not large enough for the operation"

I'm not sure what is wrong.

Attached below is the program

0 Kudos
Message 20 of 20
(4,480 Views)