0

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)
riffraff
  • 1
  • 1

1 Answers1

0

I forgot to add a required parameter (char * pUnit) to the argtypes. Therefore, i got some weird/undefined behaviour.

Now, after i added the parameter the code executes as expected.

riffraff
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 23 '22 at 11:34