Test and Measurement Forum

C++ multi channel streaming

Post your C and C++ discussions here

C++ multi channel streaming

Postby psmart » Wed Dec 10, 2014 2:16 pm

I would like to see how to code in C++ to capture multi channels streaming
- the distributed example code shows only one channel and I cant make it work for 16 channels (400 samples in 400000uS, 6400 samples)

this is the one channel code (works)
* Collect_streaming
* This function demonstrates how to use streaming.

void collect_streaming (void)
unsigned int i;
short channels [] = {1};
unsigned long nSamples = 1000;
short nChannels = 1;
unsigned long nSamplesPerChannel = 1000;
unsigned long nSamplesCollected;
unsigned short samples[1000];
unsigned long usForBlock = 1000000;
unsigned short *overflow = 0;
unsigned long triggerIndex = 0;
short nLines = 0;
FILE *fp;

printf ("Collect streaming...\n");
printf ("Data is written to disk file (test.out)\n");
printf ("Press a key to start\n");

//Set the trigger (disabled)
status = pl1000SetTrigger(g_handle, FALSE, 0, 0, 0, 0, 0, 0, 0);

//set sampling rate and channels
status = pl1000SetInterval(g_handle, &usForBlock, nSamples, channels, nChannels);

//Start streaming
status = pl1000Run(g_handle, nSamples, BM_STREAM);

//Wait until unit is ready
isReady = 0;
while(isReady == 0)
status = pl1000Ready(g_handle, &isReady);

printf("Press any key to stop\n");
fopen_s(&fp, "test.out", "w");

nSamplesCollected = nSamplesPerChannel;
status = pl1000GetValues(g_handle, samples, &nSamplesCollected, overflow, &triggerIndex);

printf("%d values\n", nSamplesCollected);

if(nLines == 20)
printf("Press any key to stop\n");
nLines = 0;

for (i = 0; i < nSamplesCollected; i++)
fprintf (fp, "%d\n", adc_to_mv(samples[i]));

status = pl1000Stop(g_handle);

Posts: 0
Joined: Wed Dec 10, 2014 2:00 pm

Re: C++ multi channel streaming

Postby Hitesh » Thu Dec 11, 2014 5:26 pm

Hi psmart,

You will need to tell the device to collect on all channels:

Code: Select all
short   channels [] = {1,2}; // Initialise this array to contain the numbers 1 to 16 inclusive
short nChannels = 16;

You will also need to inform the device of the total number of samples and the time over which to collect them - try the following:

Code: Select all
unsigned long nSamples = 6400;
unsigned long nSamplesPerChannel = 400;
unsigned long usForBlock = 400000;
unsigned short samples[6400]; // This is a temporary buffer used to retrieve data from the driver

Please also refer to section 3.3.13 (pl1000SetInterval) in the PicoLog 1000 Series Programmer's Guide:


You will then need to loop calling the pl1000GetValues requesting data and stop when you have collected the required number of samples. When you call the pl1000GetValues function, it will indicate the number of values per channel that were collected since the last collection of data.

I hope this helps.

Technical Support Engineer
Site Admin
Site Admin
Posts: 2756
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests