C Console Example doesn't work

Post your C and C++ discussions here
Post Reply
APOG
Newbie
Posts: 0
Joined: Thu Oct 10, 2013 11:25 am

C Console Example doesn't work

Post by APOG »

Hello,

i own a Picoscope 6402B device and i used the c console example of the sdk to learn the syntax of the picoscope. i can compile the example, the program finds the picoscope and show me some values of the 4 channels (i used the block mode). If i analyse the data, all the time value in the block.txt is 0 and the values make no sense. I used the TA150 Probe(350 MHz) and i touch the tip with my finger to produce the sinus wave. The Picoscope 6 software shows me this, but with the c console program, the values of the Channel are constant and don't describe the sinus wave. I had the same behavior with a buffer size of 124000 instead of the 1024.

This are the first3 Rows of the Blockdata:
Time Ch Max ADC Max mV Min ADC Min mV Ch Max ADC Max mV Min ADC Min mV Ch Max ADC Max mV Min ADC Min mV Ch Max ADC Max mV Min ADC Min mV
0 ChA -1024 = -157mV, -12851 = -1976mV ChB 256 = +39mV, -12851 = -1976mV ChC 0 = +0mV, -12851 = -1976mV ChD 256 = +39mV, -12851 = -1976mV
0 ChA -1024 = -157mV, -12851 = -1976mV ChB 256 = +39mV, -12851 = -1976mV ChC 0 = +0mV, -12851 = -1976mV ChD 256 = +39mV, -12851 = -1976mV
0 ChA -1024 = -157mV, -12851 = -1976mV ChB 256 = +39mV, -12851 = -1976mV ChC 0 = +0mV, -12851 = -1976mV ChD 256 = +39mV, -12851 = -1976mV

I use vs c++ 2010 and vs c++ 2013 RC and in both versions are the same problem. Moreover, if i try to compile the c# console example with these 2 versions, the console trys to open the picoscope and give me an error message:

BadImageFormatException was not handled. On failure System.BadImageFormatException" in ps6000CSCon.exe

exception HRESULT: 0x8007000B




I use Windows 8 and i want to program the picoscope for a Windows Forms application in c++. With my program i can find the picoscope, set the settings and i don't get any errors. The return value was always 0.

Do you have another example for visual studio,especially in c++ or a Windows Form?

Best regards

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C Console Example doesn't work

Post by Martyn »

When running the console application did you set up the Channel voltage ranges using the "V" option and also change the timebase as by default it will be at the fastest. Without these selections it is likely that you will only see very similar values reported from the channels.

We don't have any forms based applications for the scope at the present time, just the C and C# console applications.
Martyn
Technical Support Manager

APOG
Newbie
Posts: 0
Joined: Thu Oct 10, 2013 11:25 am

Re: C Console Example doesn't work

Post by APOG »

Hi,

thank you for this and now the console program works. But I don't get it, why i cant get values with my own program. This is my code and i made it with your guide

unsigned long maxSamples = 100000;
short *buffers = new short[100000];

ps6000BlockReady(handle2);
short overflow2;
FILE * fp;
status = ps6000SetChannel(handle, PS6000_CHANNEL_A, EingangA, ChannelA_coupling, PS6000_1V, MAX_ANALOGUE_OFFSET_5V_20V, PS6000_BW_FULL);
status = ps6000SetChannel(handle, PS6000_CHANNEL_B, EingangB, ChannelB_coupling, PS6000_1V, MAX_ANALOGUE_OFFSET_5V_20V, PS6000_BW_FULL);
status = ps6000SetChannel(handle, PS6000_CHANNEL_A, EingangC, ChannelC_coupling, PS6000_1V, MAX_ANALOGUE_OFFSET_5V_20V, PS6000_BW_FULL);
status = ps6000SetChannel(handle, PS6000_CHANNEL_A, EingangD, ChannelD_coupling, PS6000_1V, MAX_ANALOGUE_OFFSET_5V_20V, PS6000_BW_FULL);
status = ps6000GetTimebase2(handle,10000,100000,nullptr,0,nullptr,0);
status = ps6000RunBlock(handle, 0, 100000, 10000, 0, nullptr, 0, handle2, 0);

status = ps6000SetDataBuffer(handle,PS6000_CHANNEL_A,buffers,sizeof(buffers),PS6000_RATIO_MODE_NONE);
status = ps6000GetValues(handle,0,&maxSamples,1,PS6000_RATIO_MODE_NONE,0,&overflow2);


fopen_s(&fp, "text.txt", "w");

for (int i = 0; i < 100000; i++)
{
fprintf(fp, "%f\n", buffers/32512.0);
}


fclose(fp);

I don't really understand the function of ps6000BlockReady. Use i it correctly? I only want to have the data from the Picoscope to my Pc and so i can use the data.

Best regards

APOG

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C Console Example doesn't work

Post by Martyn »

In the call to RunBlock you pass the name of a callback function. The driver will use this call to report back to your application that the scope has completed the data collection and that data can be read from the device.

So the general approach is that after the RunBlock call you have a wait loop

Code: Select all

	if((status = ps6000RunBlock(unit->handle, 0, sampleCount, timebase, oversample,	&timeIndisposed, 0, CallBackBlock, NULL)) != PICO_OK)

	while (!g_ready && !_kbhit())
	{
		Sleep(0);
	}
and the callback function when called by the drivers sets the flag that you are checking

Code: Select all

void PREF4 CallBackBlock(	short handle,
													PICO_STATUS status,
													void * pParameter)
{
	if (status != PICO_CANCELLED)
		g_ready = TRUE;
}
You can't call GetValues before this has happened as there will be no data.
Martyn
Technical Support Manager

APOG
Newbie
Posts: 0
Joined: Thu Oct 10, 2013 11:25 am

Re: C Console Example doesn't work

Post by APOG »

Hi,

so i wrote my code like your example(thanks for that) but now i get a return failure for GetVales. Its 37 invalid buffer. But i have an array with enough space. I am confused, because in the programming guide, this error should not bereturned after the getvalues function. All other parts give me a Zero (PICO_OK).

unsigned long maxSamples = 100000;
short buffers[100000];
short overflow2;
long time;
g_ready = FALSE;

status = ps6000GetTimebase2(handle,10000,100000,nullptr,0,nullptr,0);
status = ps6000SetTriggerChannelProperties(handle, nullptr, 0, 0, 0);
if(status = ps6000RunBlock(handle, 0, 100000, 10000, 0, &time, 0, CallBackBlock, nullptr) != PICO_OK)
while (!g_ready && !_kbhit())
{
Sleep(0);
}

status = ps6000SetDataBuffer(handle, PS6000_CHANNEL_A, buffers, maxSamples, PS6000_RATIO_MODE_NONE);
status = ps6000GetValues(handle,0,(unsigned long*)&maxSamples,0,PS6000_RATIO_MODE_NONE,0,&overflow2);

the function CallBackBlock is above definied. I need only a way to get my data into an array so i can modify the data or write it into a txt file.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C Console Example doesn't work

Post by Martyn »

Should be something like the following

Code: Select all

short * buffer;

...

buffer = (short*) malloc(sampleCount * sizeof(short));
status = ps6000SetDataBuffer(handle, PS6000_CHANNEL_A, buffer, maxSamples, PS6000_RATIO_MODE_NONE);

...

free(buffer);
Martyn
Technical Support Manager

APOG
Newbie
Posts: 0
Joined: Thu Oct 10, 2013 11:25 am

Re: C Console Example doesn't work

Post by APOG »

Thanks for your help.

So i wrote with my colleague a simple console version. We get each status report after the function was called. And i think i have the probleme:

My program does not go into the while sloop from your example:
g_ready = FALSE;
if((status = ps6000RunBlock(handle, 0, maxsample, 1000000000, 1, &messdauer, 0, CallBackBlock, NULL)) != PICO_OK)

while (!g_ready && !_kbhit())
{
Sleep(0);
}
maxsample is 10

In my program this status is always PICO_OK. so the while sloop will be skipped. My example want to measure 10 data points with a sample time between these points of 6.4 sec. So the program should be wait for 1 minute. I made differnt tests but i don't get into the while sloop. After the sloop i want to show the sample time, and the TimeIndisposed (in my example messdauer) and this will be shown instantly. Also, "the messdauer" is not affected by the function RunBlock. Its always 0 or the initial value.

Edit: Problem found and solved. The if sloop has skipped the while sloop. I missunderstand your program code. Without the if sloop the program gets the data and this data are correct

Thank you very much

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C Console Example doesn't work

Post by Martyn »

Apologies I removed a print line in the original post to try and clean up the code

Code: Select all

   if((status = ps6000RunBlock(unit->handle, 0, sampleCount, timebase, oversample,   &timeIndisposed, 0, CallBackBlock, NULL)) != PICO_OK)
   printf("BlockDataHandler:ps6000RunBlock ------ 0x%08lx \n", status);

   while (!g_ready && !_kbhit())
   {
      Sleep(0);
   }
Martyn
Technical Support Manager

Post Reply