Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Error with CWIMAQVision.ReadImage() in C#

Solved!
Go to solution

Hi, I want to load a .bmp file saved on my harddisk and show it in a CWIMAQViewer. I use C#.

 

My code:

NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();

NationalInstruments.CWIMAQControls.CWIMAQImage myImageLoad = new NationalInstruments.CWIMAQControls.CWIMAQImage();

axCWIMAQViewer1.Attach(myImageLoad);

objVision.ReadImage(myImageLoad, sPath, axCWIMAQViewer1.Palette); //<<<< this throws an Exception

 

But the ReadImage() method throws the Exception:

"Fatal Error (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

 

What do i do wrong?

0 Kudos
Message 1 of 13
(6,424 Views)

thesam -

 

If you don't care about the palette, I would call ReadImage() like so:

 

object missing = System.Type.Missing;

objVision.ReadImage(myImageLoad, sPath, missing);

 

Does that help?

 

Greg Stoll

Vision R&D

National Instruments

Greg Stoll
LabVIEW R&D
0 Kudos
Message 2 of 13
(6,396 Views)

No, that does not help.

Also when i pass a null-object for the third parameter, it is the same behavior. The same exception is thrown. The StackTrace information of the exception is as follows:

 

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

at NationalInstruments.CWIMAQControls.CWIMAQVisionClass.ReadImage(CWIMAQImage DestImage, String Path, Object ColorPalette)

 

I use the >>NationalInstruments.AxCWIMAQControlsLib.Interop.dll<< assembly in version 8.0.0.0

Are there any other assemblies this assembly depends on?

 

More ideas?

0 Kudos
Message 3 of 13
(6,387 Views)

thesam -

 

there must be an example given after the installation of the Vision Development System which handles this issue. Have you checked it?

 

Regards, Jan

Jan Kniewasser | Applications Engineer | Tel.: +49 89 7413130 | Fax: +49 89 7146035

»
0 Kudos
Message 4 of 13
(6,378 Views)

It seems that the problem is the assembly itself or the vision-class or something like that. Because when i call WriteImage() or DrawText() from the Vision-Class, the same error occurs.

I use Win2000, Visual Studio 2005, C#. I referenced only the assemblies >>NationalInstruments.AxCWIMAQControlsLib.Interop.dll<< and >>NationalInstruments.CWIMAQ1394.Interop.dll<< in my C# project.

All ideas are welcome...

 

@ Jan: What example do you mean?

 

0 Kudos
Message 5 of 13
(6,374 Views)

thesam -

 

Can you post the code you're using for the cases where you're getting an exception?

 

Greg Stoll

Vision R&D

National Instruments

Greg Stoll
LabVIEW R&D
0 Kudos
Message 6 of 13
(6,371 Views)

Hi Greg,

here is the code the exception occurs with DrawText():

 

NationalInstruments.CWIMAQControls.
CWIMAQTextOptions objText = new NationalInstruments.CWIMAQControls.CWIMAQTextOptions();objText.FontName = "Arial";

objText.Size = 10;

NationalInstruments.CWIMAQControls.
CWIMAQPointClass objPoint = new NationalInstruments.CWIMAQControls.CWIMAQPointClass();

objPoint.X = 100;

objPoint.Y = 100;

int iWitdh = 0;

NationalInstruments.CWIMAQControls.CWIMAQImage myImage2 = new NationalInstruments.CWIMAQControls.CWIMAQImage();NationalInstruments.CWIMAQControls.

AxCWIMAQVision objVision = new NationalInstruments.CWIMAQControls.AxCWIMAQVision();

objVision.DrawText2(myImage, myImage2, objPoint, objText, "TEXT", ref iWitdh, false); // <<< EXCEPTION

 

 

and here the exception with ReadImage() again:

 

NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();NationalInstruments.CWIMAQControls.CWIMAQImageClass myImageLoad = new NationalInstruments.CWIMAQControls.CWIMAQImageClass();

axCWIMAQViewer1.Attach(myImageLoad);

object missing = System.Type.Missing;

objVision.ReadImage(myImageLoad, @"C:\test.bmp", missing); // <<< EXCEPTION

0 Kudos
Message 7 of 13
(6,367 Views)

I just tried the VB.NET example in "C:\Programme\National Instruments\Vision\Examples\MSVB.NET\1. Getting Started". There also the ReadImage() -Function is called. This example works fine.

Are there any other DLLs i have to reference in my C# project?

0 Kudos
Message 8 of 13
(6,327 Views)
Solution
Accepted by topic author thesam

I found my mistake. I dynamically instantiated the Vision object with:

NationalInstruments.CWIMAQControls.CWIMAQVisionClass objVision = new NationalInstruments.CWIMAQControls.CWIMAQVisionClass();

 

That doen't work. I have to insert the Vision control "axCWIMAQVision1" in my form and work with that object:

axCWIMAQVision1.ReadImage(axCWIMAQViewer1.Image, sFileName, axCWIMAQViewer1.Palette);

0 Kudos
Message 9 of 13
(6,301 Views)

I'm having the same problem, but I have no viewer or form - I'm working with a .NET assembly.  The assembly is to read an image from the drive and perform some analysis on it - there's no UI.  I am receiving the same error (to be expected as my code is the same).   Here is my code:

 

 CWIMAQVisionClass vision = new CWIMAQVisionClass();

CWIMAQImageClass image = new CWIMAQImageClass();

object missing = System.Type.Missing;

vision.ReadImage(image, redLEDFileName, missing);

 

... Throws the exception, evertime.

0 Kudos
Message 10 of 13
(5,934 Views)