Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

nivision library - imaqMakeRect : access violation writing location

Solved!
Go to solution

 I'm writing an image acquistion script using the nivision and niimaqdx libraries in python 2.7 using ctypes. When I use the function imaqMakeRect to make a Rect structure to use in the imaqImagetoArray function, I get an access violation writing error. 

 

This is the line causing the problem - imaqMakeRect(c_int32(0), c_int32(0), c_int32(0x7FFFFFFF), c_int32(0x7FFFFFFF)).

resulting in the error : WindowsError: exception: access violation writing 0x00000008

 

The access violation location seems to depend on the value of the first argument. Any ideas about what might be going on ? and how to fix it ?

 

Thanks !

0 Kudos
Message 1 of 9
(4,801 Views)
this 0x7FFFFFFF means that you overflow maximum possible number 4294967296
it limit your access of memory
0 Kudos
Message 2 of 9
(4,788 Views)

But, I get the same error regardless of the value that I use there, even if it is less than 0x7FFFFFFF

0 Kudos
Message 3 of 9
(4,782 Views)
access violation writing 0x00000008 error
accrue when you try to use part of memory that other program of process is using that part of memory and it is busy
0 Kudos
Message 4 of 9
(4,780 Views)

I see. How do I avoid this error ? Its very reproducible.

0 Kudos
Message 5 of 9
(4,778 Views)
Without posting any of your code it is impossible to know what the issue is, but it would seem likely that you are not wrapping the C functions properly in Python. A quick Google shows that someone has already wrapped NI Vision in Python:
https://github.com/robotpy/pynivision

Maybe try this wrapper code instead?

Eric
0 Kudos
Message 6 of 9
(4,767 Views)

Even these three lines here reproduces the problem : 

 

from ctypes import *

imaq = windll.nivision

IMAQ_NO_RECT =  imaq.imaqMakeRect(c_int32(0), c_int32(0), c_int32(100), c_int32(100))

0 Kudos
Message 7 of 9
(4,765 Views)

@MIT20 wrote:

Even these three lines here reproduces the problem : 

 

from ctypes import *

imaq = windll.nivision

IMAQ_NO_RECT =  imaq.imaqMakeRect(c_int32(0), c_int32(0), c_int32(100), c_int32(100))


I'm no python or cytpes guru, but this above example doesn't seem like it would be defining the function prototype for imaqMakeRect properly. SInce the functions are exported from the DLL as undecorated C functions, Python has no way to know the calling convention or the return value type. I'd imagine you'd have to specify a more complete function definition to make this work properly. Specifically, imaqMakeRect returns a structure, not an integer, and this may be the issue you are seeing.

 

I highly suggest looking at an existing wrapper like the one I pointed to that already does the wrapping for you.

Message 8 of 9
(4,760 Views)
Solution
Accepted by topic author MIT20

Thaks for the suggestions !

 

This fixed it - 

 

from ctypes import *
imaq = windll.nivision

 

class Rect(Structure):
    _fields_ = [
        ("top", c_int32),
        ("left", c_int32),
        ("height", c_int32),
        ("width", c_int32),
        ]

 

imaq.imaqMakeRect.restype = Rect

 

IMAQ_NO_RECT = imaq.imaqMakeRect(c_int32(0), c_int32(0), c_int32(100), c_int32(100))

0 Kudos
Message 9 of 9
(4,756 Views)