Dear CVI community, I would like to modify an existing function, called “Scan_Diode_Array” to use the multithreading capabilities in CVI. My naïve solution results in an error and I am quite sure that I need to convert the pointers and references. Unfortunately I have never programmed in C/C++ so I would very much appreciate if you could help me out here. Thank you very much in advance for your kind help. Below, there is a description of the function and the code (modified for readability).
The function first calls the function “DoAcqSpectrumM3”, which acquires a number of laser shot spectra and when all shots are acquired, writes them to an array called “data”. The spectra in this array are then sorted according to some parameters via the function “Sort_Diode_Array_Data” and written to the array “sorted_data”. As Scan_Diode_Array will be called inside a loop, I would like to acquire the spectra in a separate thread and sort the “data” matrix from the previous iteration before the new spectra are written into it.
When I complile the modified function, I get the following warning:
2023, 68 warning: incompatible pointer types passing 'int (short **) __attribute__((stdcall))' to parameter of type 'CmtThreadFunctionPtr' (aka 'int (*)(void *) __attribute__((cdecl))')
void Scan_Diode_Array(double *sorted_data, int nr_of_laser_shots)
{
int threadID;
short int *data;
FILE *STATFILE;
close_gate() ;
//set the number of laser shots to be acquired by the diode array
SetNrShotsSpectrumM3(nr_of_laser_shots);
//initialize daq card of diode arrays
ARM_SpectrumM3();
//acquire data in different thread
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, DoAcqSpectrumM3, &data, &threadID);
//sort data acquired on preceding iteration step
Sort_Diode_Array_Data(sorted_data, data);
}
int DoAcqSpectrumM3(short int **data)
{
//set pointer to the data buffer used
*data = pvData;
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_STARTDMA | M2CMD_DATA_WAITDMA );
//check for an error
if (spcm_dwGetErrorInfo_i32 (hDrv, NULL, NULL, DaqSetup.szErrorText) != ERR_OK)
{
printf (DaqSetup.szErrorText); // print the error text
spcm_vClose (hDrv); // close the driver
return 1;
}
spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_CARD_STOP);
return 0;
}