I use a camera SDK with a DLL (ctypes.WinDLL).
camera_path = 'cam://0'.encode('utf-8')
handle = xdll.XDLL.open_camera(camera_path, 0, 0)
# (The handle returned is 1)
xdll.XDLL.set_property_value_f(handle, b'IntegrationTime', c_double(2500))
This gives an the following error:
OSError: exception: access violation reading 0x0000000000000001
The weird thing is, that the code works as expected with a random print in between:
camera_path = 'cam://0'.encode('utf-8')
handle = xdll.XDLL.open_camera(camera_path, 0, 0)
# (The handle returned is 1)
print('random print')
xdll.XDLL.set_property_value_f(handle, b'IntegrationTime', c_double(2500))
Any idea what print()
does to prevent such an error?
If time.sleep(1)
is used instead of print()
it shows the error, so the time spent on printing should not make a difference.
EDIT: The interesting lines from the header file:
typedef int XCHANDLE; ///< Handle type used to identify an initialised session to a camera.
XCHANDLE IMPEXPC XC_OpenCamera (const char * pCameraName = "cam://default", XStatus pCallBack = 0, void * pUser = 0); ///< @sa XCamera::Create
ErrCode IMPEXPC XC_SetPropertyValueF (XCHANDLE h, const char * pPrp, double dValue, const char * pUnit);
methods in xdll.XDLL:
open_camera = _xenethDLL.XC_OpenCamera
open_camera.restype = c_int32 # XCHANDLE
set_property_value_f = _xenethDLL.XC_SetPropertyValueF
set_property_value_f.restype = c_ulong # ErrCode
set_property_value_f.argtypes = (c_int32, c_char_p, c_double)