LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Vision interop runtime problem

Solved!
Go to solution

I'm attempting to user the vision development module with VB.net in VS 2005. The code is replicating an application that was written in a VBA macro inside Excel. I know that the API dll's are correctly installed and registered on the machine because I was able to run the macro without any problems. Now that I've rewritten the code in VB.net I'm getting a runtime problem with the interop. The CWIMAQVision object instatiates without a problem, but when I make a metod call on the object, an unhandled COM Exception is returned in the catch block. The error is enumerated as E_UNHANDLED and the message text describes it as a "Catastrophic Error." Following the stack trace produces nothing as the error is not detailed any further.

 

My .net project references to the NI Vision API are:

 

C:\Program Files\National Instruments\Vision\dotNET\Assemblies\Current\NationalInstruments.AxCWIMAQControlsLib.Interop.dll

C:\Program Files\National Instruments\Vision\dotNET\Assemblies\Current\NationalInstruments.AxCWIMAQHelpButton.Interop.dll

C:\Program Files\National Instruments\Vision\dotNET\Assemblies\Current\NationalInstruments.AxCWMV.Interop.dll

C:\Program Files\National Instruments\Vision\dotNET\Assemblies\Current\NationalInstruments.AxNIOCRLib.Interop.dll

 

The method call is about as simplistic as you can get:

 

Public Function GetImage(ByVal filepath As String) As Integer

 Dim machineVision As New CWIMAQVision()

Dim fileInformation As New CWIMAQFileInformation()

 

Dim success As Integer

Try

success = machineVision.ReadImage(Me.CurrentImage, filepath)

 

Catch COMex As System.Runtime.InteropServices.COMException

 

MessageBox.Show("COM Error occured: " & COMex.ErrorCode & Environment.NewLine & COMex.Message, "COM Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

 

End Try

Return success

 

End Function

 

Is this a problem in the interop, or I am missing something?

0 Kudos
Message 1 of 3
(2,892 Views)

Hi Sswing

 

Have you tried placing a break point before the ReadImage Method and checking to see if you have a valid filepath? Upon failure of this method it should return a negative one a catastrophic error leads me to believe there may be a problem with the image itself you are calling. Please make sure your image is of a valid format (PNG,JPEG,JPEG2000,TIFF,AIPD and BMP).


Thank You
Eric Reid
National Instruments
Motion R&D
0 Kudos
Message 2 of 3
(2,864 Views)
Solution
Accepted by topic author sswing11

Thanks Eric; unfortunately the answer is that the API can't be instantiated outside of a form level control. I was attempting the use the interop by creating a new instance in a class, but this is not possible. The solution was to include the interop control on a form and pass the API be reference to the class that invoking the API methods. It's not good programming practice, but based on the way the interop is coded, the only alternative is use roundabout code from the reflection namespace to handle the instantiation and marshaling of the COM object at run-time. Way too much overhead...

 

 

0 Kudos
Message 3 of 3
(2,858 Views)