Closed voslik closed 2 years ago
You are right, there appears to be a type mismatch. You can fix it by replacing the two following lines inside site-packages/pylablib/devices/IMAQ/niimaq_lib.py
:
98
from
argprep={"buffer":lambda bufSize:ctypes.create_string_buffer(bufSize+1)}, byref=["bufSize"])
to
argprep={"buffer":lambda bufSize:ctypes_wrap.strprep(bufSize+1)()}, byref=["bufSize"])
101
from
argprep={"buffer":lambda bufferSize:ctypes.create_string_buffer(bufferSize+1)}, byref=["bufferSize"])
to
argprep={"buffer":lambda bufferSize:ctypes_wrap.strprep(bufferSize+1)()}, byref=["bufferSize"])
What it does is replacing ctypes.create_string_buffer(l)
with ctypes_wrap.strprep(l)()
, which does the same buffer allocation, but casts it to c_char_p
afterwards.
Could you check if this solves the issue? If it does, I will implement it in the next release.
Sincerely,
Alexey.
Yes, that worked. Thank you.
When I call the function serial_readline() to read bytes off of my camera, I get an error about mismatched types. As best as I can tell, it seems to me that the wrapper function is checking whether pv is of type c_char_p (it is not, it is c_char_Array) and then tries to convert it to a c_char_p, which fails.
My code:
from pylablib.devices import IMAQ
IMAQ.list_cameras() cam1 = IMAQ.IMAQCamera('img0.iid') cam1.setup_serial_params(write_term='\r', datatype='str')
msg_transmitted = '*IDN?' error_message = cam1.serial_write(msg_transmitted,timeout=1.0, term=None)
msg_received = cam1.serial_readline(timeout=1.0, datatype=None, maxn=1024)
Error output:
Traceback (most recent call last):
File "C:\Users\admin\Desktop\my_folder\test.py", line 28, in
msg_received = cam1.serial_readline(timeout=1.0, datatype=None, maxn=1024)
File "C:\Users\admin\anaconda3\lib\site-packages\pylablib\devices\IMAQ\IMAQ.py", line 397, in serialreadline msg,=lib.imgSessionSerialRead(self.sid,maxn,int(timeout*1000))
File "", line 1, in
File "C:\Users\admin\anaconda3\lib\site-packages\pylablib\core\utils\ctypes_wrap.py", line 271, in wrapped_func func_args=self._prepare_arguments(argnames,prep_argtypes,kwargs,argprep)
File "C:\Users\admin\anaconda3\lib\site-packages\pylablib\core\utils\ctypes_wrap.py", line 175, in _prepare_arguments cv=pv if isinstance(pv,t) else t(pv)
TypeError: bytes or integer address expected instead of c_char_Array_1025 instance