Old Nick
Advanced Member level 1
I'm currently trying to neaten up some code I've written and make elements of it more portable. The code I've written controls an ADC card (measurment computing) which strips data from camera's we've designed.
We use the functions supplied by the card manufacturer to read the data into an array and when the frames have been grabbed then write the data to a file.
The way the code is now means there is a lot of repetition,
this has to be repeated for every channel. Now what I want to do is create a function with this code and just pass the channel number etc to the function, which is no problem.
However I'm a bit unsure as to hae to treat the array. I'm currently usin 4 ADC channels, so I want to call the funtion 4 times which requires four arrays. Can I pass an array to a function, fill the array in the function and then have access to the data outside the function?
My memory of C is a bit rusty, but i suspect this is going to require the passing of pointers.......gulp!
I hope I've got my question across clearly(ish) enough.
Any help appreciated,
Cheers,
Nick
We use the functions supplied by the card manufacturer to read the data into an array and when the frames have been grabbed then write the data to a file.
The way the code is now means there is a lot of repetition,
Code:
UDStat = cbAIn (BoardNum, Chan0, Gain, &DataValueA); //sample channel 0
UDStat = cbToEngUnits (BoardNum, Gain, DataValueA, &EngUnitsA); //convert raw data to voltage
if (photoNumber==0)//nothing to average - load the array
{
DataArrayA[row][column] = EngUnitsA;
}
else //start averaging - (old value + new value)
{
DataArrayA[row][column] = (DataArrayA[row][column] + EngUnitsA); //
}
this has to be repeated for every channel. Now what I want to do is create a function with this code and just pass the channel number etc to the function, which is no problem.
However I'm a bit unsure as to hae to treat the array. I'm currently usin 4 ADC channels, so I want to call the funtion 4 times which requires four arrays. Can I pass an array to a function, fill the array in the function and then have access to the data outside the function?
My memory of C is a bit rusty, but i suspect this is going to require the passing of pointers.......gulp!
I hope I've got my question across clearly(ish) enough.
Any help appreciated,
Cheers,
Nick