using the DLL to talk to cleverscope using C/C++

Using the DLL to talk to cleverscope using C/C++, a forum discussion on Cleverscope. Join us for more discussions on Using the DLL to talk to cleverscope using C/C++ on our Other Issues forum.

Back to Forum Index : Back to Other Issues   RSS

13 Apr 2006
Posts:

I'm trying to talk to the cleverscope using C/C++, whenever I call the function ""CScopeControlDriver"" I get a segmentation fault somewhere inside the driver.

The function takes a large number of arguments and probably one of the arguments I give it is not what it was expecting. My problem is which one! There is currently no cleverscope supplied example code and the documentation isn't completely explicit*.

Has anyone been able to interface with the driver using a text-based programming language, if so I'd love to know how you did it and perhaps see the code snippet you use.

Cheers
Jevon

P.S. my attempt is at http://wwwrsphysse.anu.edu.au/~jjl111/cscope.cpp

* e.g. the int32 valued variable ChanAAllocSpace is ""Used to declare how much space has been allocated to the Chan A Data array"" So what does one put in here, the number of samples, amount of memory in bytes? (Neither seems to work)

22 Apr 2006
Posts: 398

Hello Jevon, Thanks very much for your post. To answer it we have put a C code application in the Resources section of the site. The zip includes a sample application which illustrates amplitude and time axis control, trigger level and channel, and signal generator frequency and amplitude.

The allocation question is the space available, in bytes, for the output signal array.

5 May 2006
Posts:

I thought I'd write this down in case anyone else has my problem

I still had a bit of trouble getting code to work in a console applicaton, it was because the driver seems to need windows messages to be processed and just calling ""Sleep()"" in between check_for_samples() from a console application doesn't cause this to happen.

Below is a simple example application which works for me.

Thanks for you help Bart.
Jevon.

#include ""stdafx.h""

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>


#include ""cscope interface.h""



void DoEvents()


{
MSG msg;
long sts;

do {
if (sts = PeekMessage(&msg, (HWND) NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} while (sts);
}




int main(int argc, char* argv[])
{
FILE *fp;
int k,j;
double a_vert = 1.0,b_vert=1.0,horz = 1.0e-3;
double sig_gen_freq=500;
double sig_gen_volts=4.0;
double trig_volts=0.0;
int trig_channel=0;
int num_points=1000;
double delta_t=0,t_zero=0;

double awave[max_samples], bwave[max_samples];
memset(awave, 0, max_samples*sizeof(double));
memset(bwave, 0, max_samples*sizeof(double));


printf(""initialising
"");
k = scope_init();
if(k!=0){
printf(""error %d initialising scope"",k);
}


printf(""configuring
"");
k = scope_config (a_vert, b_vert, horz, num_points,
sig_gen_freq,sig_gen_volts,trig_volts, trig_channel);

if(k!=0){
printf(""error %d configing scope"",k);
}

printf(""triggering acquisition
"");
k = scope_acquire ();
if(k!=0){
printf(""error %d acquiring"",k);
}


for(j=0;j<100;j++){
k = check_for_samples();
printf(""checkforsamples returns : %d
"",k);
if (k!=0) break;
DoEvents();
Sleep(50);
}

k = scope_read_waveform (awave, bwave, &num_points, &delta_t, &t_zero);
if(k!=0){
printf(""erroe code %d, reading waveform
"",k);
}else{
printf(""numsamples=%d,delta_t = %g,t_zero= %g
"",num_points,delta_t,t_zero);
}


printf(""closing scope
"");
j = scope_close();
if(j!=0){
printf(""error %d closing scope"",j);
}

fp=fopen(""out.dat"",""wb"");
fwrite (&num_points, sizeof(int),1,fp);
fwrite (awave,sizeof(double),num_points,fp);
fwrite (bwave,sizeof(double),num_points,fp);
fclose(fp);


return 0;
}
Back to Forum Index : Back to Other Issues   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.

×

Your shopping cart is empty.