I am working on an embedded board (iMX6) with Python 3.4 and get a type error reading string features like that:
with pymba.Vimba() as vimba:
camera = vimba.getCamera(cameraSerialNumber)
camera.openCamera()
currentCameraModelName = camera.DeviceModelName
It looks like the call to ctypes create_string_buffer in vimbafeature.py is wrong:
def _getStringFeature(self):
"""
Get the value of a string feature.
:returns: string -- value of the specified feature.
"""
# create args
bufferSize = 256
valueToGet = create_string_buffer('\000' * bufferSize)
sizeFilled = c_uint32()
errorCode = VimbaDLL.featureStringGet(self._handle,
self._name,
valueToGet,
bufferSize,
byref(sizeFilled))
if errorCode != 0:
raise VimbaException(errorCode)
return valueToGet.value.decode()
The function is called with a string which raises a TypeError in cytpes/__init__.py:
def create_string_buffer(init, size=None):
"""create_string_buffer(aBytes) -> character array
create_string_buffer(anInteger) -> character array
create_string_buffer(aString, anInteger) -> character array
"""
if isinstance(init, bytes):
if size is None:
size = len(init)+1
buftype = c_char * size
buf = buftype()
buf.value = init
return buf
elif isinstance(init, int):
buftype = c_char * init
buf = buftype()
return buf
raise TypeError(init)
I was able to resolve the issue by changing the call to create_string_buffer with a bytearray as argument:
valueToGet = create_string_buffer(('\000' * bufferSize).encode())
But: as reading string features is quite common, I wonder why no one else had this issue before. Am I missing something?
I am working on an embedded board (iMX6) with Python 3.4 and get a type error reading string features like that:
It looks like the call to ctypes
create_string_buffer
invimbafeature.py
is wrong:The function is called with a string which raises a TypeError in
cytpes/__init__.py
:I was able to resolve the issue by changing the call to
create_string_buffer
with a bytearray as argument:valueToGet = create_string_buffer(('\000' * bufferSize).encode())
But: as reading string features is quite common, I wonder why no one else had this issue before. Am I missing something?