07-15-2016 07:23 PM
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 !
Solved! Go to Solution.
07-16-2016 05:34 AM
07-16-2016 08:28 AM
But, I get the same error regardless of the value that I use there, even if it is less than 0x7FFFFFFF
07-16-2016 09:00 AM
07-16-2016 09:23 AM
I see. How do I avoid this error ? Its very reproducible.
07-16-2016 02:23 PM
07-16-2016 02:33 PM
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))
07-16-2016 03:00 PM
@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.
07-16-2016 05:14 PM
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))