AlexShkarin / pyLabLib

Python package for device control and experiment automation
http://pylablib.readthedocs.io
GNU General Public License v3.0
130 stars 30 forks source link

Function serial_readline() fails with error about type mismatch #7

Closed voslik closed 2 years ago

voslik commented 2 years ago

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

AlexShkarin commented 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:

Sincerely,

Alexey.

voslik commented 2 years ago

Yes, that worked. Thank you.