Test and Measurement Forum

C program from the SDK

Post your C and C++ discussions here

C program from the SDK

Postby Eminar1101 » Thu Jul 05, 2012 6:26 am

Hi all,
I'm trying to run the C program on visual studio 2008 and 2010 provided in the sdk but it is not working.
What I'm doing is: I'm creating a new visual C++ Win32 Console Application empty project. then I'm adding the 2 header files: PicoStatus.h and UsbDrDaqApi.h to the header files directory, the USBDrDAQ.lib to the resource files directory, and the USBDrDAQcon.c to the source files directory.

When I compiled it as it is it gives me an error in line 38:
(#include "c:\CVSROOT\PICO\PROD\USBDrDAQ\Drivers\Windows\usbDrDaqApi.h")
I thought it is because of the wrong directory so I changed it to the directory of the directory of my project then debugged the project. There were no errors but the application could not start. It shows me the following message:
"The application has failed to start because UsbDrDaq.dll was not found. Re-installing the application may fix this problem."

Can some1 please tell me what am I doing wrong?
Thank you
Eminar1101
Newbie
 
Posts: 0
Joined: Mon Mar 05, 2012 8:12 am

Re: C program from the SDK

Postby Martyn » Thu Jul 05, 2012 6:33 am

Either install Picoscope 6 software which will put the UsbDrDaq.dll in a directory that is on the system path, or copy UsbDrDaq.dll to the bin directory under release or debug for your project.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C program from the SDK

Postby Eminar1101 » Thu Jul 05, 2012 6:41 am

Thanks. I copied the dll file to the debug directory and now its working. But I have already installed Picoscope and it didn't work. Anyhow, now it is! thank you =]
Eminar1101
Newbie
 
Posts: 0
Joined: Mon Mar 05, 2012 8:12 am

Re: C program from the SDK

Postby Eminar1101 » Sat Jul 14, 2012 9:55 am

Hi again,
I'm editing on the example program provided in the SDK and what I'm trying to do is to get 6 seconds of readings at 1000 samples/second from the scope channel. This is what I come up to so far:
Code: Select all
/**************************************************************************
*
* Filename: USBDrDAQcon.c   
*
* Copyright: Pico Technology Limited 2010
*
* Author: RPM     
*
* Description:
*   This is a console-mode program that demonstrates how to use the
*   USB DrDAQ driver.
*
* There are the following examples:
*   Collect a block of samples immediately
*   Collect a block of samples when a trigger event occurs
*   Use windowing to collect a sequence of overlapped blocks
*   Write a continuous stream of data to a file
*   Take individual readings
*      Set the signal generator
*      Set digital outputs
*      Get states of digital inputs
*      Set PWM
*      Pulse counting
*      Set the RGB LED
*
* To build this application
*   set up a project for a 32-bit console mode application
*   add this file, UsbDrDaqApi.h, picoStatus.h and
*   USBDrDAQ.lib (Microsoft C only) to the project and then
*   build it
*
***************************************************************************/

#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include "picoStatus.h"
#include "C:\Users\Eminar1101\Documents\Visual Studio 2008\Projects\USBDrDAQcon\usbDrDaqApi.h"

#define TRUE      1
#define FALSE      0

int   scale_to_mv;
unsigned short   max_adc_value;
short g_handle;
short isReady;
short d1State, d2State, d3State, d4State = 0;
PICO_STATUS status;
USB_DRDAQ_INPUTS channel;

/****************************************************************************
*
* adc_to_mv
*
* If the user selects scaling to millivolts,
* Convert a 12-bit ADC count into millivolts
*
****************************************************************************/
int adc_to_mv (int raw)                              
{      
   int   scaled;

   if (scale_to_mv)
   {
      scaled = raw * 2500 / max_adc_value;
   }
   else
   {
      scaled = raw;
   }
   return scaled;
}

/****************************************************************************
*
* mv_to_adc
*
* Convert a millivolt value into an ADC count
*
*  (useful for setting trigger thresholds)
*
****************************************************************************/
int mv_to_adc (int mv)
{
   return mv * max_adc_value / 2500;
}

/****************************************************************************
*
* channel_select
*  Allow user to select channel
*
****************************************************************************/
void channel_select()
{
   int value;

   printf("\n");
   printf("1: External Sensor 1\n");
   printf("2: External Sensor 2\n");
   printf("3: External Sensor 3\n");
   printf("4: Scope Channel\n");
   printf("5: PH\n");
   printf("6: Resistance\n");
   printf("7: Light\n");
   printf("8: Thermistor\n");
   printf("9: Microphone Waveform\n");
   printf("10:Microphone Level\n");
   printf("\n");
   
   do
   {
      printf("Enter channel number: ");
      scanf_s("%d", &value);
   }while(value < USB_DRDAQ_CHANNEL_EXT1 || value > USB_DRDAQ_MAX_CHANNELS);

   channel = (USB_DRDAQ_INPUTS)value;
}

/****************************************************************************
*
* Collect_block_immediate
*  this function demonstrates how to collect a single block of data
*  from the unit (start collecting immediately)
*
****************************************************************************/

void collect_block_immediate (void)
{
   unsigned int i;
   unsigned long nSamples = 6000;
   short nChannels = 1;
   unsigned long nSamplesPerChannel = 6000;
   unsigned long nSamplesCollected;
   short samples[6000];
   unsigned long usForBlock = 6000000;
   unsigned short overflow;
   unsigned long triggerIndex = 0;
   FILE *fp;

   printf ("Collect block immediate (channel %d)...\n", channel);
   printf ("Press a key to start\n");
   //_getch();

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

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

   //printf("Press any key to stop\n");
   fopen_s(&fp, "test.out", "w");
   printf("file opened\n");
   //while(!_kbhit())
   //{
      //Run
      status = UsbDrDaqRun(g_handle, nSamples, BM_SINGLE);

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

      nSamplesCollected = nSamplesPerChannel;
      status = UsbDrDaqGetValues(g_handle, samples, &nSamplesCollected, &overflow, &triggerIndex);
      printf("get values\n");
      //Print out the first 10 readings, converting the readings to mV if required
      //printf ("First 10 readings of %i (press any key to stop)\n", nSamplesCollected);
      //for (i = 0; i < 10; i++)
      //{
      //   printf ("%d\n", adc_to_mv(samples[i]));
      //}
      for (i = 0; i < nSamplesCollected; i++)
      {
         fprintf (fp, "%d\n", adc_to_mv(samples[i]));
      }
      printf ("Done");   
      fclose(fp);
      status = UsbDrDaqStop(g_handle);
      
      //Sleep(100);
   }
   //fclose(fp);
   //status = UsbDrDaqStop(g_handle);
   //_getch();


/****************************************************************************
*
* Collect_block_triggered
*  this function demonstrates how to collect a single block of data from the
*  unit, when a trigger event occurs.
*
****************************************************************************/

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

   printf ("Collect block triggered (channel %d)...\n", channel);
   printf ("Enter threshold:");
   scanf_s("%d", &threshold);
   printf ("\nPress a key to start...\n");
   _getch();

   //Set the trigger
   status = UsbDrDaqSetTrigger(g_handle, TRUE, 0, 0, channel, (unsigned short)threshold, 16000, 0, -50);

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

   printf ("Trigger delay is set to -50%% (trigger event in centre of block)\n");
   printf ("\nWaiting for trigger...\n\n");
   printf ("Press a key to abort\n");

   fopen_s(&fp, "test.out", "w");

   //Run
   status = UsbDrDaqRun(g_handle, nSamples, BM_SINGLE);

   //Wait until unit is ready
   isReady = 0;
   while(isReady == 0 && (!_kbhit ()))
   {
      status = UsbDrDaqReady(g_handle, &isReady);
   }

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

   //Print out the first 10 readings, converting the readings to mV if required
   printf ("5 readings either side of trigger event (%i samples collected)\n", nSamplesCollected);
   for (i = triggerIndex-5; i < triggerIndex+6; i++)
   {
      printf ("%d\n", adc_to_mv(samples[i]));
   }
   for (i = 0; i < nSamplesCollected; i++)
   {
      fprintf (fp, "%d\n", adc_to_mv(samples[i]));
   }

   fclose(fp);
   status = UsbDrDaqStop(g_handle);
}


/****************************************************************************
*
* Collect_windowed_blocks
*
* This function demonstrates how to use windowed blocks.
*
****************************************************************************/

void collect_windowed_blocks (void)
{
   unsigned int i;
   unsigned long nSamples = 1000;
   short nChannels = 1;
   unsigned long nSamplesPerChannel = 1000;
   unsigned long nSamplesCollected;
   short samples[1000];
   unsigned long usForBlock = 10000000;   //10 seconds
   unsigned short overflow;
   unsigned long triggerIndex = 0;
   short nLines = 0;
   FILE *fp;

   printf ("Collect windowed block (channel %d)...\n", channel);
   printf ("First block appears after 10 seconds,\n");
   printf ("then 10 second blocks are collected every second\n");
   printf ("Press a key to start\n");
   _getch();

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

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

   //Start
   status = UsbDrDaqRun(g_handle, nSamples, BM_WINDOW);

   //Wait until unit is ready
   printf ("Waiting for first block...\n");
   isReady = 0;
   while(isReady == 0)
   {
      status = UsbDrDaqReady(g_handle, &isReady);
   }

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

   while(!_kbhit())
   {
      nSamplesCollected = nSamplesPerChannel;
      status = UsbDrDaqGetValues(g_handle, samples, &nSamplesCollected, &overflow, &triggerIndex);

      printf("%d values\n", nSamplesCollected);
      if(nLines == 20)
      {
         printf("Press any key to stop\n");
         nLines = 0;
      }
      else
         nLines++;

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

      Sleep(30000);      //Wait 1 second before collecting next 10 second block.
   }
   fclose(fp);
   status = UsbDrDaqStop(g_handle);

   _getch();
}

/****************************************************************************
*
* Collect_streaming
*
* This function demonstrates how to use streaming.
*
****************************************************************************/

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

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

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

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

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

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

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

   while(!_kbhit())
   {
      nSamplesCollected = nSamplesPerChannel;
      status = UsbDrDaqGetValues(g_handle, samples, &nSamplesCollected, &overflow, &triggerIndex);

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

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

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

      Sleep(100);
   }
   fclose(fp);
   status = UsbDrDaqStop(g_handle);

   _getch();
}

/****************************************************************************
*
* Collect_individual
*
****************************************************************************/

void collect_individual (void)
{
   int      sample_no;
   int      c;
   short value;
   unsigned short overflow;

   printf ("Collect individual...\n");
   printf ("Takes individual readings under program control\n");
   printf ("Sample from all channels\n");
   printf ("Press a key to start\n");
   _getch();

   sample_no = 20;
   while (!_kbhit ())
   {
      Sleep(100);
      if (++sample_no > 20)   //Print headings again
      {
         sample_no = 0;
         printf ("\nPress any key to stop\n \n");
         for (c = 1; c <= USB_DRDAQ_MAX_CHANNELS; c++)
         {
            printf ("ch%d\t", c);
         }
      }
      for (c = 1; c <= USB_DRDAQ_MAX_CHANNELS; c++)
      {
         value = 0;
         UsbDrDaqGetSingle(g_handle, c, &value, &overflow);
         printf ("%d\t", adc_to_mv (value));
      }
   }
   _getch ();
}

/****************************************************************************
*
* Set/clear digital outputs
*
****************************************************************************/
void outputToggle(USB_DRDAQ_GPIO IOChannel)
{
   switch(IOChannel)
   {
   case USB_DRDAQ_GPIO_1:
      {
         if(d1State)
            d1State = 0;
         else
            d1State = 1;

         UsbDrDaqSetDO(g_handle, IOChannel, d1State);
         break;
      }
   case USB_DRDAQ_GPIO_2:
      {
         if(d2State)
            d2State = 0;
         else
            d2State = 1;

         UsbDrDaqSetDO(g_handle, IOChannel, d2State);
         break;
      }
   case USB_DRDAQ_GPIO_3:
      {
         if(d3State)
            d3State = 0;
         else
            d3State = 1;

         UsbDrDaqSetDO(g_handle, IOChannel, d3State);
         break;
      }
   case USB_DRDAQ_GPIO_4:
      {
         if(d4State)
            d4State = 0;
         else
            d4State = 1;

         UsbDrDaqSetDO(g_handle, IOChannel, d4State);
         break;
      }
   }
}

/****************************************************************************
*
* Display digital output states
*
****************************************************************************/
void displayOutputStates()
{
   printf("\nDigital Outputs\n");
   printf("===============\n");
   printf("GPIO 1\tGPIO 2\tGPIO 3\tGPIO 4\t\n");
   printf("%i\t%i\t%i\t%i\t\n\n", d1State, d2State, d3State, d4State);
}

/****************************************************************************
*
* Set pulse width modulation
*
****************************************************************************/
void pwm()
{
      int period = 0;
      int cycle = 0;
      int IOChannel;

      printf("\n----------PWM----------\n");
      do
      {
            printf("Select GPIO channel (1 or 2):");
            scanf_s("%d", &IOChannel);
            fflush(stdin);
      }while(IOChannel < 1 || IOChannel > 2);

      do
      {
            printf("Enter period (0 to 65535 microseconds):");
            scanf_s("%d", &period);
            fflush(stdin);
      }while(period < 0 || period > 65535);

      do
      {
            printf("Enter duty cycle (0 to 100%%):");
            scanf_s("%d", &cycle);
            fflush(stdin);
      }while(cycle < 0 || cycle > 100);
      
      UsbDrDaqSetPWM(g_handle, IOChannel, (unsigned short)period, (unsigned char)cycle);

      //Clear state of channel we are using
      if(IOChannel == 1)
         d1State = 0;
      else if(IOChannel == 2)
         d2State = 0;
}

/****************************************************************************
*
* Read digital inputs
*
****************************************************************************/
void DigitalInput()
{
   short value;
   USB_DRDAQ_GPIO channel;

   printf("Press any key to stop...\n");

   while(!_kbhit())
   {
      for(channel = USB_DRDAQ_GPIO_1; channel <= USB_DRDAQ_GPIO_4; channel++)
      {
         UsbDrDaqGetInput(g_handle, channel, 0, &value);            //Not using pull-up resistor
         printf("%d\t", value);
      }
      printf("\n");
      
      Sleep(500);
   }
   _getch();

   //reset digital output status
   d1State = d2State = d3State = d4State = 0;
}

/****************************************************************************
*
* Pulse counting
*
****************************************************************************/
void PulseCounting()
{
   int value, direction;
   USB_DRDAQ_GPIO IOChannel;
   short count;

   do
   {
      printf("Select GPIO (1 or 2):");
      scanf_s("%d", &value);
   }while(value != USB_DRDAQ_GPIO_1 && value != USB_DRDAQ_GPIO_2);

   printf("\n");
   
   IOChannel = (USB_DRDAQ_GPIO)value;
   
   do
   {
      printf("Select direction (0: rising. 1: falling):");
      scanf_s("%d", &direction);
   }while(direction != 0 && direction != 1);

   printf("\n");

   printf("Press any key to start counting pulses\n");
   _getch();
   
   UsbDrDaqStartPulseCount(g_handle, IOChannel, (short)direction);

   printf("Press any key to stop...\n");

   while(!_kbhit())
   {
      Sleep(1000);
      
      UsbDrDaqGetPulseCount(g_handle, IOChannel, &count);
      printf("%d\n", count);
   }
   _getch();

   //reset digital output status
   if(IOChannel == USB_DRDAQ_GPIO_1)
      d1State = 0;
   else if(IOChannel == USB_DRDAQ_GPIO_2)
      d2State = 0;
}


/****************************************************************************
*
* Set the signal generator
*
****************************************************************************/
void SigGen()
{
   USB_DRDAQ_WAVE   waveType;
   int frequency = 0;
   int pToP = 0;
   int value, offset;

   printf("0: Sine\n");
   printf("1: Square\n");
   printf("2: Triangle\n");
   printf("3: Ramp Up\n");
   printf("4: Rampe Down\n");
   printf("5: DC\n");
   printf("99: OFF\n");

   do
   {
      printf("\nSelect wave type:");
      scanf_s("%d", &value);
   }while((value < 0 || value > 5) && value != 99);

   if(value == 99)
   {
      UsbDrDaqStopSigGen(g_handle);
      return;
   }

   waveType = (USB_DRDAQ_WAVE)value;

   do
   {
      printf("\nEnter offset (microvolts):");
      scanf_s("%d", &offset);
   }while(offset < -1500000 || offset > 1500000);

   if(waveType != USB_DRDAQ_DC)      //Frequency and peak to peak are ignored for DC output
   {

      do
      {
         printf("\nEnter frequency (0 to 20,000 Hz):");
         scanf_s("%d", &frequency);
      }while(frequency < 0 || frequency > 20000);

      do
      {
         printf("Enter peak-to-peak amplitude (microvolts)");
         scanf_s("%d", &pToP);
      }while(pToP < 0|| pToP > 3000000);
   }

   UsbDrDaqSetSigGenBuiltIn(g_handle, (long)offset, (unsigned long)pToP, (short)frequency, waveType);
}


/****************************************************************************
*
* Get availabe scaling for current channel and allow user to select
* the scaling to use
*
****************************************************************************/
void ChannelScaling()
{
   short nScales, currentScale, i;
   char names[1000];
   char   ch;
   int selectedScaleNo;

   UsbDrDaqGetScalings(g_handle, channel, &nScales, &currentScale, names, 1000);

   printf("%d scale(s) available for channel %d:\n\n", nScales, channel);

   i = 0;
   while(names[i] != NULL)
   {
      if(names[i] == 13) //Carriage return
         printf("\n");
      else
         printf("%c", names[i]);
      
      i++;
   }

   if(nScales > 1)
   {
      printf("\ncurrent scale: %d\n\n", currentScale);

      printf("Press 'C' to change scale or any other key to continue\n");

      ch = toupper(_getch());

      if(ch == 'C')
      {
         do
         {
            printf("Select scale (0 to %d):", nScales - 1);
            scanf_s("%d", &selectedScaleNo);
            printf("\n");
         }while(selectedScaleNo < 0 || selectedScaleNo > nScales - 1);

         UsbDrDaqSetScalings(g_handle, channel, (short)selectedScaleNo);
      }
   }
}

/****************************************************************************
*
* Enable or disable the RGB LED
*
****************************************************************************/
void LED()
{
   int enable, red, green, blue;

   printf("\n");
   printf("0: Disable RGB LED\n");
   printf("1: Enable RGB LED\n");

   do
   {
      printf("\n>");
      scanf_s("%d", &enable);
   }while(enable < 0 || enable > 1);

   UsbDrDaqEnableRGBLED(g_handle, (short)enable);

   if(enable)
   {
      do
      {
         printf("\nEnter Red value (0 to 255):");
         scanf_s("%d", &red);
      }while(red < 0);               //Doesn't matter if > 255

      do
      {
         printf("\nEnter Green value (0 to 255):");
         scanf_s("%d", &green);
      }while(green < 0);
      
      do
      {
         printf("\nEnter Blue value (0 to 255):");
         scanf_s("%d", &blue);
      }while(blue < 0);   

      UsbDrDaqSetRGBLED(g_handle, (unsigned short)red, (unsigned short)green, (unsigned short)blue);
   }
}

/****************************************************************************
*
*
****************************************************************************/

void main (void)
{
   char   ch;
   char   info[20];
   short   requiredSize = 0;

   printf ("USB DrDAQ driver example program\n");
   printf ("Version 1.0\n\n");

   printf ("\n\nOpening the device...\n");
   status = UsbDrDaqOpenUnit(&g_handle);
   if (status != 0)
   {
      printf ("Unable to open device\nPress any key\n");
      _getch();
      return;
   }
   else
   {

      collect_block_immediate ();
   }

      /*
      printf ("Device opened successfully\n\n");
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_VARIANT_INFO);
      printf("Model:\t\t\t %s\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_BATCH_AND_SERIAL);
      printf("Serial Number:\t\t %s\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_CAL_DATE);
      printf("Calibration Date:\t %s\n\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_USB_VERSION);
      printf("%s\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_HARDWARE_VERSION);
      printf("Hardware version %s\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_DRIVER_VERSION);
      printf("USBDrDAQ.dll version %s\n", info);
      status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_KERNEL_VERSION);
      printf("%s\n", info);

      //Set to scope channel initially
      channel = USB_DRDAQ_CHANNEL_SCOPE;

      ch = ' ';
      while (ch != 'X')
      {
         printf ("\n");
         printf ("Select an operation:\n");
         printf ("B - Immediate block\t\t1, 2, 3, 4 - Toggle digital outputs\n");
         printf ("T - Triggered block\t\tP - Set PWM\n");
         printf ("W - Windowed block\t\tD - Get digital input states\n");
         printf ("S - Streaming\t\t\tE - Pulse counting\n");
         printf ("C - Select channel\t\tF - Set signal generator\n");
         printf ("G - Channel scaling\t\tH - Set RGB LED\n");
         printf ("A - Select mV or ADC counts\n");
         printf ("I - Individual reading\t\tX - exit\n");
         ch = toupper (_getch());
         printf ("\n");

         switch (ch)
         {

         case 'C':
            channel_select();
            break;

         case 'B':
            collect_block_immediate ();
            break;

         case 'T':
            collect_block_triggered ();
            break;

         case 'W':
            collect_windowed_blocks ();
            break;

         case 'S':
            collect_streaming ();
            break;

         case 'I':
            collect_individual ();
            break;

         case 'D':
            DigitalInput();
            break;
                     
         case 'E':
            PulseCounting();
            break;
                     
         case 'F':
            SigGen();
            break;

         case 'P':
            pwm();
            break;

         case 'G':
            ChannelScaling();
            break;

         case 'H':
            LED();
            break;

         case '1':
            outputToggle(USB_DRDAQ_GPIO_1);
            displayOutputStates();
            break;

         case '2':
            outputToggle(USB_DRDAQ_GPIO_2);
            displayOutputStates();
            break;

         case '3':
            outputToggle(USB_DRDAQ_GPIO_3);
            displayOutputStates();
            break;

         case '4':
            outputToggle(USB_DRDAQ_GPIO_4);
            displayOutputStates();
            break;

         case 'A':
            scale_to_mv = !scale_to_mv;

            if (scale_to_mv)
            {
               printf ("Values will be displayed in mV\n");
            }
            else
            {
               printf ("Values will be displayed in ADC counts\n");
            }
            break;

         case 'X':
            break;

         default:
            printf ("Invalid operation\n");
            break;
         }
      }
*/

   UsbDrDaqCloseUnit(g_handle);
   
}


I have put some of the lines to comment in order not to lose it.
For now, I want the program to take 6 seconds readings at 1000 samples/seconds (6000 readings) automatically from scope channel then stop.
The code above is giving me 6000 readings but doesnt seem to be for 6 seconds + it is not from the scope channel i think its from the Ext1 channel.
How can I modify it to get what I want. I tried reading the programmers guide but couldn't understand everything actually.
HELP PLZ
THANK YOU
Eminar1101
Newbie
 
Posts: 0
Joined: Mon Mar 05, 2012 8:12 am

Re: C program from the SDK

Postby Martyn » Mon Jul 16, 2012 11:54 am

You have commented out the line that sets the scope channel
Code: Select all
channel = USB_DRDAQ_CHANNEL_SCOPE;

which needs to be before you call
Code: Select all
collect_block_immediate ();
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C program from the SDK

Postby Eminar1101 » Wed Jul 18, 2012 7:25 pm

Still not working for me!

I want to collect 6000 readings in 6 seconds at sample rate 1000 sample/second from scope channel. Some of the issues:
1) Which function should I use? Collect Block Immediate, Streaming, or collect windowed block?
2) How can I set the sample and time interval in which to collect in the function?

Now the test.out file is empty after adding channel = USB_DRDAQ_CHANNEL_SCOPE; before collect_block_immediate ();
Eminar1101
Newbie
 
Posts: 0
Joined: Mon Mar 05, 2012 8:12 am

Re: C program from the SDK

Postby Martyn » Thu Jul 19, 2012 6:30 am

collect_block_immediate is the correct function to use, and you have the correct number of samples and sample interval. However you need to wait for the data to be collected before trying to get the values from the driver, the code to do this is there but you have commented it out

Code: Select all
      //Wait until unit is ready
      isReady = 0;
      while(isReady == 0)
      {
         status = UsbDrDaqReady(g_handle, &isReady);
      }


If you are still having difficulty try starting from scratch with the sample code, do not comment out anything, and manually run it using the menu options. Stepping through the code with your debugger will show you the values and actions as they happen.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: C program from the SDK

Postby Eminar1101 » Tue Jul 24, 2012 8:35 am

OK thank you for your help.
I tried the stream function and it is working fine with a few modifications. I limited its stream to 6 seconds using the "time.h" library. and it is working properly.

Again thanks for the help and I'll ask you if I needed some help again. I hope I wont =]
Eminar1101
Newbie
 
Posts: 0
Joined: Mon Mar 05, 2012 8:12 am


Return to C and C++

Who is online

Users browsing this forum: No registered users and 1 guest