# cbLogReadAIChannels()

Reads analog input data from a binary file, and stores the values in an array.

## Function Prototype

C/C++

int cbLogReadAIChannels(char* Filename, int StartSample, int Count, float* AIChannels)

Visual Basic

Function cbLogReadAIChannels(ByVal Filename$, ByVal StartSample&, ByVal SampleCount&, ByRef AIChannelData!) As Long

## Arguments

FileName

The name of the file to retrieve the information from.

StartSample

The first sample to read from the binary file.

Count

The number of samples to read from the binary file.

AIChannels

Receives the analog input values.

## Returns

- Error code or 0 if no errors
- AIChannels – Returns the analog input values logged in the file.

## Notes

- The units of the analog input data that is returned is set by the value of the Units preference. Refer to cbLogSetPreferences().
- The units preference is only applied if the logged data is temperature data. This value is ignored if the data logged is raw.

### Analog array

The user is responsible for allocating the size of the analog array, and ensuring that it is large enough to hold the data that will be returned. You can calculate the array allocation using the sampleCount value from cbLogGetSampleInfo(), and the aiCount value from cbLogGetAIChannelCount():

float* AIChannels = new float[sampleCount * AICount];

The figure below shows the layout of the analog array, and how the elements should be indexed.

where n is (AICount – 1).

CH0 – CHn refer to the channels in the array, not the input channels of the device.

For example, assume that all of the even number input channels are logged. The analog array channels are mapped as shown here:

Array Channel | Device Input Channel
0 | 0
1 | 2
2 | 4
3 | 6

Use the following code fragment to access the elements of the analog array:

for (i=0; i<numberOfSamples; i++)

{

for (j=0; j<numberOfAIChannels; j++)

{

a = analogArray[(i * numberOfAIChannels) + j];

}

}

where

the numberOfSamples is set by the SampleCount value from cbLogGetSampleInfo().

the numberOfAIChannels is set by the AICount value from cbLogGetAIChannelCount().