I am trying to wrap the Vimba C API (for grabbing data from machine vision cameras). I’m struggling with one aspect (it may be that it is my lack of C knowledge).
The function I’m currently wrapping is declared roughly as:
VmbError_t VmbCamerasList ( VmbCameraInfo_t* pCameraInfo,
VmbUint32_t listLength,
VmbUint32_t* pNumFound,
VmbUint32_t sizeofCameraInfo );
First we are supposed to call this function with a NULL pointer for pCameraInfo
to retreive the numer of cameras in the 3rd argument. i.e.
ncameras = Ref{VmbUint32_t}(0)
err = ccall((:VmbCamerasList,vmblib), VmbError_t,
(Ptr{VmbCameraInfo_t}, VmbUint32_t, Ref{VmbUint32_t}, VmbUint32_t),
C_NULL, 0, ncameras, sizeof(Ptr{VmbCameraInfo_t}))
My first question is what I should be doing with the last argument? The example in the API docs uses:
VmbCameraInfo_t *pCameras = NULL; // A list of camera details
VmbUint32_t nCount // Number of found cameras
err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras );
What is the Julia equivalent of sizeof *pCameras
? As far as I know, in C this just returns the size of the pointer type, not the size of VmbCameraInfo_t
let alone the array it points to.
Subsequently I am supposed to call with a correctly allocated array. The C example is:
pCameras = (VmbCameraInfo_t*) malloc( nCount * sizeof( *pCameras ));
if ( NULL != pCameras ) {
err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras ); }
which I translated as
cameras = Array{VmbCameraInfo_t}(ncameras[])
err = ccall((:VmbCamerasList,vmblib), VmbError_t,
(Ref{VmbCameraInfo_t}, VmbUint32_t, Ref{VmbUint32_t}, VmbUint32_t),
cameras, ncameras[], ncameras, sizeof(Ptr{VmbCameraInfo_t}))
does that make sense? I’m still confused about the last argument.
Also note that in the first call I declared the first argument to be Ptr{VmbCameraInfo_t}
becasue I wanted to pass C_NULL
, whereas in the second I declared it to be Ref{VmbHandle_t}
so I can directly pass Array{VmbCameraInfo_t}(ncameras[])
. Do I need to worry about the C_NULL
or does Ref
do the right thing here?