Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

VDM8.0: InvalidActiveXStateException thrown by AxCWIMAQVision.MatchPattern

hi jonathan,
thank you so much for your wonderful explanation...Smiley Happy
 
as it turns out,the problem was with the AxCWIMAQVision,but not because a console application cant recognise it, but because it was not initialised.
so i added the code IMAQVision.createcontrol()  in my constructor,after IMAQVision= new NationalInstruments.CWIMAQControls.AxCWIMAQVision
and that solved the problem(i got this answer from another thread,here http://forums.ni.com/ni/board/message?board.id=200&message.id=13813&query.id=276408://)
 
now,to answer your questions:"how you are exactly calling the Windows Application from the Console Application?"
actually,i have two applications.one is a class library,called vision.vb,that does all the image capturing and processing,and finally returns an integer value to the calling application.i defined this as a windows application.here is the skeleton of my vision.vb:

Imports

NationalInstruments.CWIMAQControls

<ComClass(VisionTool.ClassId, VisionTool.InterfaceId, VisionTool.EventsId)> _

Public

Class VisionTool

***all variable initialization

Public IMAQVision As NationalInstruments.CWIMAQControls.AxCWIMAQVision

Dim myImage As NationalInstruments.CWIMAQControls.CWIMAQImage

#

Region "COM GUIDs"

Public Sub New() *constructor

MyBase.New()

IMAQVision =

New NationalInstruments.CWIMAQControls.AxCWIMAQVision

IMAQVision.createcontrol()

*all other initializations

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

errorCode = CWIMAQ1394.SetupGrabCW(sid)

End Sub

Public Function GetLedColor() As Integer

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

End

Class

the other file is a console application that calls the vision.vb library.it just creates an object of the VisionTool class, and calls the GetLedColor() function,and prints the value returned( 2) to console..

i am not sure whether i used any Windows App methods,but the program halts at LearnColor only..when i commented it out,it worked fine..

thanks alot for all ur help..Smiley Very Happy

have a good day!!!Smiley Wink

0 Kudos
Message 11 of 15
(2,389 Views)
Hi rebecs,

Okay, I see how you have your application set up and thanks for explaining. I had to modify your code just a little so I could test it out and run it on my end. For me, since I don't have any IMAQ hardware or cameras, I had to just programmatically create an image and use that.  When I initially did that and then called that assembly from my console application, I received a "invalid image" error. Then after doing a little reading up, I determined that I needed to set the image type to RGB32 (other values I assume would work; If you have any questions on that, post back and then we can get one of the IMAQ engineers to give you some more detailed information on that).  After setting up those few things, I had no problems calling the LearnColor method and the return value was 0 which indicates success. I launched my console app and then stepped through the class library code just to make sure everything returned correct values and it did. 
 
The simple code I used was:

Dim

myImage As NationalInstruments.CWIMAQControls.CWIMAQImage
myImage = IMAQVision.CreateCWIMAQImage
myImage.Type = CWIMAQImageTypes.cwimaqImageTypeRGB32

For i = 0 To 100
      For j = 0 To 100
              data(i, j) = i + j
      Next j
Next i

myImage.ArrayToImage(data)
status = IMAQVision.LearnColor(myImage, ColInfo)

In the console app, I simply instantiated the VisionTool class and then called the GetLedColor method and all worked correctly. Perhaps that type property is essential.

Let me know if this helps any!

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 12 of 15
(2,381 Views)

hi jonathan,

thanks for ur help..i really appreciate u going thru all that trouble..Smiley Happy

but perhaps i was not clear in my previous post..actually the problem is solved Smiley Very Happy..after i inserted the IMAQVision.createcontrol(), it worked fine..and i must apologise for something else,too.i did insert the type property..but in my quest to simplify my codes in the post,i accidently deleted that piece of code.i am so sorry for troubling u Smiley Sad

here is my constructor,which does all the initializations.

MyBase.New()

IMAQVision =

New NationalInstruments.CWIMAQControls.AxCWIMAQVision

IMAQVision.CreateControl()

'image initialization

myImage =

New NationalInstruments.CWIMAQControls.CWIMAQImage

myImage.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeRGB32

'timer initialization

t1 =

New System.Timers.Timer(250)

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

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

Console.WriteLine(" camera error!!")

GoTo ErrorHandler

End If

t1.Enabled =

True

errorCode = CWIMAQ1394.SetupGrabCW(sid)

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

Console.WriteLine(" grab error!!")

GoTo ErrorHandler

End If

ErrorHandler:

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

'DisplayError(errorCode)

End If

End Sub

so,now the library works fine..but there is something that affects its performance though..there seems to be some delay in saving the image into the variable,so i had to insert a system delay in GetLedColor.then there is also some kind of delay in storing the results of LearnColor in ColInfo,so i had to insert another delay before MatchColor..though these 2 delays add up to less than 1 sec,it still slows down the execution.if it is possible,i would like my application to be a real time kinda thing..and when i call this library from MS DOS command prompt,it takes forever to return the value(especially the first time).i wonder if this is a problem in NI Vision itself,or whether it has something to with the computer speed as well.

any ideas?

thank you

0 Kudos
Message 13 of 15
(2,376 Views)
Hi rebecs,

Putting the delay might have something to do with the NI Vision driver but honestly I am not sure. If any of the Vision engineers have any ideas, they can post as well. The only thing I can think of from a .NET perspetctive is that since you are using .NET/COM interop then maybe there is some delay needed for marshaling between .NET and COM.  Besides that, I'm not to sure so I'll leave the rest up to the Vision group.

Best Regards,

Message Edited by Jonathan N on 05-30-2007 08:23 PM

Jonathan N.
National Instruments
Message 14 of 15
(2,373 Views)
rebecs,

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

delay in output

Save CWIMAQViewer image & overlay in VB


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

0 Kudos
Message 15 of 15
(2,325 Views)