mingw & PS3000A.dll

Post your C and C++ discussions here
Post Reply
magoyan
Newbie
Posts: 0
Joined: Mon Oct 14, 2013 1:46 pm

mingw & PS3000A.dll

Post by magoyan »

Hi,
I'm trying to use mingw with the PS30001.dll . A segmentation fault occurs during the ps3000aGetValues call.
I've included the very simple code that i've used for this test.
Any idea ?

Regards

Michel
OS : MS Windows7
GCC version 4.8.1
PICO_DRIVER_VERSION : 1.0.0.386
PICO_USB_VERSION: 2.0
PICO_HARDWARE_VERSION : 1
PICO_VARIANT_INFO: 3204MSO
PICO_BATCH_AND_SERIAL: CW000/036
PICO_CAL_DATE: 08Jan13
PICO_KERNEL_VERSION : 1.0
PICO_DIGITAL_HARDWARE_VERSION : 1
PICO_ANALOGUE_HARDWARE_VERSION :1

Code: Select all

#include "windows.h"
#include 
#include "ps3000aApi.h"

#include "picoStatus.h"
#include 

#define NB_OF_SEGMENTS  (1)
#define SEGMENT_INDEX_0 (0)
#define OFFSET_VOLTAGE  ((float)0)
#define ENABLED (1)
#define THRESHOLD_LEVEL (32)
#define DELAY   (0)
#define AUTO_TRIGGER_MS (0)
#define NB_SAMPLES (40000)
#define NB_PRETRIG_SAMPLES (0)
#define NB_POSTTRIG_SAMPLES (NB_SAMPLES)
#define TIMEBASE (5)
#define BUFF_LEN (80000000)

BOOL g_ready = FALSE;

short buffer[BUFF_LEN];

void call_back_run_block( short handle, PICO_STATUS status, void * pParameter)
{
  if (status != PICO_CANCELLED)
    g_ready = TRUE;
}

int main ()
{
// handle on the picoscope unit
  short psh;
  PICO_STATUS status;
  float sampling_time_period;
  short oversample=0;
  long time_busy_ms;
  long max_samples;
  char mess[1024];
  short mess_len_req;
  int i;

  if((status=ps3000aOpenUnit(&psh,NULL))!=PICO_OK)
  {
    fprintf(stderr,"unable to Open the scope %ld\n",status);
    exit(-1);
  }


  for(i=0;i<9;i++)
  {
    memset(mess,0,1024);
    status=ps3000aGetUnitInfo(psh,mess,1024,&mess_len_req,(PICO_INFO)i);
    if(status != PICO_OK)
    {
      fprintf(stderr, "fails to get unit info %ld\n",status);
      exit(-1);
    }
    printf("%s\n",mess);
  }
  if((status=ps3000aMemorySegments(psh,NB_OF_SEGMENTS,&max_samples)) !=PICO_OK)
  {
    fprintf(stderr,"unable to set the number of memory segments %ld\n",status);
    exit(-1);
  }

  printf("max samples for segment  = %ld\n",max_samples);

  if (ps3000aSetChannel(psh,PS3000A_CHANNEL_B,TRUE,PS3000A_DC,PS3000A_5V,OFFSET_VOLTAGE)!= PICO_OK)
  {
    fprintf(stderr, "unable to set channel B\n");
    exit(-1);
  }


  status=ps3000aGetTimebase2(psh,
                             TIMEBASE,
                             NB_SAMPLES,
                             &sampling_time_period,
                             oversample,
                             &max_samples,
                             SEGMENT_INDEX_0);
  if(status != PICO_OK)
  {
    fprintf(stderr, "unable to set the timebase  for Channel B %ld\n",status);
    exit(-1);
  }
  printf("sampling period = %f nb of samples = %ld\n",sampling_time_period,max_samples);

  status=ps3000aSetSimpleTrigger(psh,ENABLED,PS3000A_CHANNEL_B,THRESHOLD_LEVEL,PS3000A_RISING,DELAY,AUTO_TRIGGER_MS);
  if(status != PICO_OK)
  {
    fprintf(stderr, "unable to set the trigger %ld\n",status);
    exit(-1);
  }

 
  printf("run the acquisition \n");

  g_ready=FALSE;

  if(ps3000aRunBlock(psh,NB_PRETRIG_SAMPLES,NB_POSTTRIG_SAMPLES,TIMEBASE,oversample,&time_busy_ms,SEGMENT_INDEX_0,(ps3000aBlockReady)call_back_run_block,NULL )!=PICO_OK)
  {
    printf("error during runblock\n)");
  }

  printf("busy time = %ld ms\n",time_busy_ms);

#if 0
  short ready=0;
  do
  {
  if((status=ps3000aIsReady(psh,&ready)) != PICO_OK)
  {
  printf ("error during waiting trigger :%ld\n",status);
}
  
}while(ready==0);
#else

//waiting for acquisition complete
  while (!g_ready);
#endif

  //ps3000aStop(psh);

  printf("acquisition complete\n");

  

  unsigned long nb_of_samples=NB_SAMPLES;
  short overflow;


  //Sleep(10000);

 
  //short *buffer;
  //buffer=(short*)malloc(BUFFER_LEN* sizeof(short));

 
  status=ps3000aSetDataBuffer(psh,PS3000A_CHANNEL_B,buffer,BUFF_LEN,SEGMENT_INDEX_0,PS3000A_RATIO_MODE_NONE);

  if(status != PICO_OK)
  {
  printf("buffer allocation fails %ld\n",status);
}

  status=ps3000aGetValues(psh,0,&nb_of_samples,1,PS3000A_RATIO_MODE_NONE,SEGMENT_INDEX_0,&overflow);
    
  if(status != PICO_OK)
  {
  printf("get values fails%lud\n",status);
}

  printf("get values complete %lud\n",nb_of_samples);
  fflush(stdout);

  for (i=0;i

Post Reply