Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't load type "Image_struct" using .NET 2003

I have an IMAQ PCI-1411 and the Vision software/driver suite. I am attempting to write a C program using .NET 2003 and the Labwindows/CVI functions provided to acquire an image. I have written some test code around the imaqEasyAcquire as a sanity test before diving into image analysis. The code I have written is as follows:

#include <stdio.h>
#include <conio.h>
#include "nivision.h"

int ErrorCode;
int borderSize;
Image* image = NULL;

void main()
{
    borderSize = 0;

    image = imaqCreateImage(IMAQ_IMAGE_HSL,borderSize);

    if ( image == NULL )
    {
        ErrorCode = imaqGetLastError();
        printf("Error: NULL Returned\n");
        printf("Errorcode = %i\n",ErrorCode);
    }
    printf("Press Enter to Test imaqEasyAcquire\n");
    getch();
   
    image = imaqEasyAcquire("img0");

    if ( image == NULL )
    {
        ErrorCode = imaqGetLastError();
        printf("Error: NULL Returned\n");
        printf("Errorcode = %i\n",ErrorCode);
    }
    else
        printf("Test Complete\n");

    ErrorCode = imaqDispose(image);
   
    if ( ErrorCode == 0 )
    {
        ErrorCode = imaqGetLastError();
        printf("Error: Image could not be dumped.\n");
        printf("Errorcode = %i\n",ErrorCode);
    }

    getch();

}

This compiles fine but the program crashes on execution of the line

"image = imaqCreateImage(IMAQ_IMAGE_HSL,borderSize);"

The error message tells me that it "Could not load type Image_struct from assembly." Image_struct is not defined in the header "nivision.h," so I see why this problem occurs.

Can anyone tell me where "Image_struct" is defined? Or, if I am on the wrong track entirely, let me know. I'm a mechanical engineer and my programming skills are shaky outside of Matlab and Motorola Assembly, so don't hesitate to give me an obvious/condescending answer.
0 Kudos
Message 1 of 5
(4,113 Views)
Sorry, not familiar with CVI, but I did notice a funny thing in your code. You have a pointer to type "image" declared as "image *imaq". This pointer is first initialized with the call to imaqCreateImage(...), but then later on you go ahead and overwite this value with the output from imaqEasyAcquire(). I would think you need to do only one or the other, but not both.

The "image_struct" is not something you will find in a <niimaq.h> or any header file. It's a compiler-generated construct that is derived from the "image" pointer you used. I assume that if you looked carefully enough (and if NI provided the source) you will find a declaration of image to be a structure, e.g. "struct image { ...};".

That error message you are getting seems to be related to initialization/creation of a image structure. Structures (struct) in C++ can have their own custom functions for creation (aka constructor). You probably don't have the source code to see it, but I would double check the documentation for ImageCreate and see what it needs to be passed as input. In anycase, I wouldn't be surprised if you could just use imaqSimpleAcquire() without the imageCreate.

I'm sure NI has samples/example code that can probably point you in the right direction.
--
[System info: NI-1429e running in 'Base' CL-mode plugged into an x4 PCI-e slot on a Dell PowerEdge 1800, dual 3.2Ghz Xenon, 6GB RAM, Windows 2003 Server SP1, LV8.0/7.1, IMAQ v3.5, Dell CERC SATA RAID controller card with 4x250GB Seagate HDD, one Seagate 250GB HDD connected to system's primary SATA port for OS.]
0 Kudos
Message 2 of 5
(4,105 Views)
Thank you for your prompt reply.

I believe that you are correct; I don't need both imaqCreateImage() and imaqEasyAcquire().

In nivision.h, Image is given the structure:

    typedef struct Image_struct Image;

Any Imaq function I try to use immediately crashes the program with the same complaint:

    "Could not load type Image_struct from assembly"

I reviewed the example code "Easy Acquire" as best I could and could not figure out how it was functionally any different than what I've tried. On another note, the example code "Easy Acquire," while compiling and running without crashing, fails to display the image at all when the "Acquire" button is pressed. The "Quit" button, however, is fully functional. Perhaps my problems are related? And don't
say PEBKAC...
   
0 Kudos
Message 3 of 5
(4,101 Views)
What is PEBKAC? I didn't install CVI so I'm not familiar with it at all, but the "assembly" error message sounds like the new ".NET" foundation class assemblies. I would be surprised (but it's totally possible) if NI made their IMAQ Vision development as .NET assemblies. I don't believe you have this issue, but in general, for managed code/.NET assemblies, you must create all instances of the object on the heap. This means that instead of something like:

Image img;

You would need always:
Image *img=new Image;

But you only use the output from the functions imaqCreateImage() and imaqEasyAcquire(), so that shouldn't be the problem. Sorry I couldn't be of any more help.
--
[System info: NI-1429e running in 'Base' CL-mode plugged into an x4 PCI-e slot on a Dell PowerEdge 1800, dual 3.2Ghz Xenon, 6GB RAM, Windows 2003 Server SP1, LV8.0/7.1, IMAQ v3.5, Dell CERC SATA RAID controller card with 4x250GB Seagate HDD, one Seagate 250GB HDD connected to system's primary SATA port for OS.]
0 Kudos
Message 4 of 5
(4,094 Views)
Well, it looks like things got better once I turned off "Use Managed Extensions" in the VC03 compiler options. Still up sh*t creek, but I've found a paddle.
0 Kudos
Message 5 of 5
(4,008 Views)