Esempio n. 1
0
void collect_fast_streaming_triggered (void)
{
	unsigned long	i;
	FILE 	*fp;
	short  overflow;
	int 	ok;
	short ch;
	unsigned long nPreviousValues = 0;
	short values_a[BUFFER_SIZE_STREAMING];
	short values_b[BUFFER_SIZE_STREAMING];
	unsigned long	triggerAt;
	short triggered;
	unsigned long no_of_samples;
	double startTime = 0;



	fprintf (stderr, "Ready to stream...\n" );
	printf (stderr, "Press a key to start\n" );
	getch ();

	set_defaults ();

	set_trigger_advanced ();

	unitOpened.trigger.advanced.autoStop = 0;
	unitOpened.trigger.advanced.totalSamples = 0;
	unitOpened.trigger.advanced.triggered = 0;

	//Enable and set channel A with AC coupling at a range of +/-2V
	if(ps2000_set_channel(unitOpened.handle,PS2000_CHANNEL_A,TRUE,FALSE,PS2000_2V))
        fprintf(stderr,"Channel A enabled and set..\n");
    else
        fprintf(stderr,"Unable to set channel A...\n");

    //Disable channel B
	if(ps2000_set_channel(unitOpened.handle,PS2000_CHANNEL_B,FALSE,FALSE,1))
        fprintf(stderr,"Channel B disabled..\n");
    else
        fprintf(stderr,"Unable to set channel B...\n");

	/* Collect data at 200ns intervals
	* 100000 points with an agregation of 1 : 1
	*	Auto stop after the 100000 samples
	*  Start it collecting,
	*/
	if(!ps2000_run_streaming_ns ( unitOpened.handle, 200, 2, BUFFER_SIZE_STREAMING, 1, 1, 40000 ))
        fprintf(stderr,"There was a problem running streaming...\n");

	/* From here on, we can get data whenever we want...
	*/

	while (!unitOpened.trigger.advanced.autoStop)
	{
		ps2000_get_streaming_last_values (unitOpened.handle, ps2000FastStreamingReady);
		if (nPreviousValues != unitOpened.trigger.advanced.totalSamples)
		{
			nPreviousValues = 	unitOpened.trigger.advanced.totalSamples;
		}
		Sleep (0);
	}

	ps2000_stop (unitOpened.handle);

	no_of_samples = ps2000_get_streaming_values_no_aggregation (unitOpened.handle,
                                                                &startTime, // get samples from the beginning
																values_a, // set buffer for channel A
                                                                values_b,	// set buffer for channel B
                                                                NULL,
																NULL,
																&overflow,
																&triggerAt,
																&triggered,
																BUFFER_SIZE_STREAMING);

    fprintf(stderr,"%d samples collected, representing %d mains cycles",no_of_samples,no_of_samples/99000);
	// if the unit triggered print out ten samples either side of the trigger point
	// otherwise print the first 20 readings
	/*for ( i = (triggered ? triggerAt - 10 : 0) ; i < ((triggered ? triggerAt - 10 : 0) + 20); i++)
	{
		for (ch = 0; ch < unitOpened.noOfChannels; ch++)
		{
			if (unitOpened.channelSettings[ch].enabled)
			{
				printf ("%d, ", adc_to_mv ((!ch ? values_a[i] : values_b[i]), unitOpened.channelSettings[ch].range) );
			}
		}
		printf ("\n");
	}
    */

	//fp = fopen ( "data.txt", "w" );

	for ( i = 0; i < no_of_samples; i++ )
	{
	    printf ("%d ", adc_to_mv (values_a[i], unitOpened.channelSettings[0].range) );
	}
	printf ("\n");
	//fclose ( fp );

	getch ();
}
Esempio n. 2
0
void collect_fast_streaming (void)
{
	unsigned long	i;
	FILE 	*fp;
	short  overflow;
	int 	ok;
	short ch;
	unsigned long nPreviousValues = 0;
	short values_a[BUFFER_SIZE_STREAMING];
	short values_b[BUFFER_SIZE_STREAMING];
	unsigned long	triggerAt;
	short triggered;
	unsigned long no_of_samples;
	double startTime = 0;


	printf ( "Collect fast streaming...\n" );
	printf ( "Data is written to disk file (data.txt)\n" );
	printf ( "Press a key to start\n" );
	getch ();

	set_defaults ();

	/* You cannot use triggering for the start of the data...
	*/
	ps2000_set_trigger ( unitOpened.handle, PS2000_NONE, 0, 0, 0, 0 );

	unitOpened.trigger.advanced.autoStop = 0;
	unitOpened.trigger.advanced.totalSamples = 0;
	unitOpened.trigger.advanced.triggered = 0;

	/* Collect data at 10us intervals
	* 100000 points with an agregation of 100 : 1
	*	Auto stop after the 100000 samples
	*  Start it collecting,
	*/
	ok = ps2000_run_streaming_ns ( unitOpened.handle, 10, PS2000_US, BUFFER_SIZE_STREAMING, 1, 100, 30000 );
	printf ( "OK: %d\n", ok );

	/* From here on, we can get data whenever we want...
	*/	
	
	while (!unitOpened.trigger.advanced.autoStop)
	{
		
		ps2000_get_streaming_last_values (unitOpened.handle, ps2000FastStreamingReady);
		if (nPreviousValues != unitOpened.trigger.advanced.totalSamples)
		{
			
			printf ("Values collected: %ld\n", unitOpened.trigger.advanced.totalSamples - nPreviousValues);
			nPreviousValues = 	unitOpened.trigger.advanced.totalSamples;

		}
		Sleep (0);
		
	}

	ps2000_stop (unitOpened.handle);

	no_of_samples = ps2000_get_streaming_values_no_aggregation (unitOpened.handle,
					&startTime, // get samples from the beginning
					values_a, // set buffer for channel A
					values_b,	// set buffer for channel B
					NULL,
					NULL,
					&overflow,
					&triggerAt,
					&triggered,
					BUFFER_SIZE_STREAMING);


	// print out the first 20 readings
	for ( i = 0; i < 20; i++ )
	{
		for (ch = 0; ch < unitOpened.noOfChannels; ch++)
		{
			if (unitOpened.channelSettings[ch].enabled)
			{
				printf ("%d, ", adc_to_mv ((!ch ? values_a[i] : values_b[i]), unitOpened.channelSettings[ch].range) );
			}
		}
			printf ("\n");
	}

	fp = fopen ( "data.txt", "w" );
	if (fp != NULL)
	{
		for ( i = 0; i < no_of_samples; i++ )
		{
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
				if (unitOpened.channelSettings[ch].enabled)
				{
					fprintf ( fp, "%d, ", adc_to_mv ((!ch ? values_a[i] : values_b[i]), unitOpened.channelSettings[ch].range) );
				}
			}
			fprintf (fp, "\n");
		}
		fclose ( fp );
	}
	else
		printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");

	getch ();
}
Esempio n. 3
0
void collect_streaming (void)
{
	int		i;
	int		block_no;
	FILE 	*fp;
	int		no_of_values;
	short  overflow;
	int 	ok;
	short ch;

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

	set_defaults ();

	/* You cannot use triggering for the start of the data...
	*/
	ps2000_set_trigger ( unitOpened.handle, PS2000_NONE, 0, 0, 0, 0 );

	/* Collect data at 10ms intervals
	* Max BUFFER_SIZE points on each call
	*  (buffer must be big enough for max time between calls
	*
	*  Start it collecting,
	*  then wait for trigger event
	*/
	ok = ps2000_run_streaming ( unitOpened.handle, 10, 1000, 0 );
	printf ( "OK: %d\n", ok );

	/* From here on, we can get data whenever we want...
	*/
	block_no = 0;
	fp = fopen ( "data.txt", "w" );
	while ( !kbhit () )
	{
		no_of_values = ps2000_get_values ( unitOpened.handle, 
			unitOpened.channelSettings[PS2000_CHANNEL_A].values,
			unitOpened.channelSettings[PS2000_CHANNEL_B].values,
			NULL,
			NULL,
			&overflow,
			BUFFER_SIZE );
		printf ( "%d values\n", no_of_values );

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

		/* Print out the first 10 readings
		*/
		if (fp != NULL)
		{
			for ( i = 0; i < no_of_values; i++ )
			{
				for (ch = 0; ch < unitOpened.noOfChannels; ch++)
				{
					if (unitOpened.channelSettings[ch].enabled)
					{
						fprintf ( fp, "%d, ", adc_to_mv (unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
					}
				}
				fprintf (fp, "\n");
			}
		}
		else
			printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");

		/* Wait 100ms before asking again
		*/
		Sleep ( 100 );
	}
	fclose ( fp );

	ps2000_stop ( unitOpened.handle );

	getch ();
}
Esempio n. 4
0
void collect_block_ets (void)
{
	int		i;
	int		trigger_sample;
	FILE 	*fp;
	short 	auto_trigger_ms = 0;
	long 	time_indisposed_ms;
	short 	overflow;
	long  	ets_sampletime;
	short ok;
	short ch;

	printf ( "Collect ETS block...\n" );
	printf ( "Collects when value rises past 1500mV\n" );
	printf ( "Press a key to start...\n" );
	getch ();

	set_defaults ();

	/* Trigger enabled
	* Channel A - to trigger unsing this channel it needs to be enabled using ps2000_set_channel
	* Rising edge
	* Threshold = 1500mV
	* 10% pre-trigger  (negative is pre-, positive is post-)
	*/
	unitOpened.trigger.simple.channel = PS2000_CHANNEL_A;
	unitOpened.trigger.simple.delay = -10.f;
	unitOpened.trigger.simple.direction = PS2000_RISING;
	unitOpened.trigger.simple.threshold = 1500.f;


	ps2000_set_trigger ( unitOpened.handle,
		(short) unitOpened.trigger.simple.channel,
		mv_to_adc (1500, unitOpened.channelSettings[(short) unitOpened.trigger.simple.channel].range),
		unitOpened.trigger.simple.direction ,
		(short) unitOpened.trigger.simple.delay,
		auto_trigger_ms );

	/* Enable ETS in fast mode,
	* the computer will store 60 cycles
	*  but interleave only 4
	*/
	ets_sampletime = ps2000_set_ets ( unitOpened.handle, PS2000_ETS_FAST, 60, 4 );
	printf ( "ETS Sample Time is: %ld\n", ets_sampletime );
	/* Start it collecting,
	*  then wait for completion
	*/
	ok = ps2000_run_block ( unitOpened.handle, BUFFER_SIZE, timebase, 1, &time_indisposed_ms );

	printf ( "Waiting for trigger..." );
	printf ( "Press a key to abort\n" );

	while ( (!ps2000_ready (unitOpened.handle)) && (!kbhit ()) )
	{
		Sleep (100);
	}

	if ( kbhit () )
	{
		getch ();
		printf ( "data collection aborted\n" );
	}
	else
	{
		ps2000_stop ( unitOpened.handle );
		/* Get the times (in microseconds)
		*  and the values (in ADC counts)
		*/
		ok = (short)ps2000_get_times_and_values ( unitOpened.handle,
																							times,
																							unitOpened.channelSettings[PS2000_CHANNEL_A].values,
																							unitOpened.channelSettings[PS2000_CHANNEL_B].values,
																							NULL,
																							NULL,
																							&overflow,
																							PS2000_PS,
																							BUFFER_SIZE);

		/* Print out the first 10 readings,
		*  converting the readings to mV if required
		*/

		printf ( "Ten readings around trigger\n" );
		printf ( "(ps)\t(mv)\n");

		/* This calculation is correct for 10% pre-trigger
		*/
		trigger_sample = BUFFER_SIZE / 10;

		for ( i = trigger_sample - 5; i < trigger_sample + 5; i++ )
		{
			printf ( "%ld\t", times [i]);
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
				if (unitOpened.channelSettings[ch].enabled)
				{
					printf ( "%d\t\n", adc_to_mv (unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range));
				}
			}
			printf ("\n");
		}

		fp = fopen ( "data.txt","w" );
		if (fp != NULL)
		{
			for ( i = 0; i < BUFFER_SIZE; i++ )
			{
				fprintf ( fp, "%ld,", times[i] );
				for (ch = 0; ch < unitOpened.noOfChannels; ch++)
				{
					if (unitOpened.channelSettings[ch].enabled)
					{
						fprintf ( fp, "%ld, %d, %d", times[i],  unitOpened.channelSettings[ch].values[i], adc_to_mv (unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
					}
				}
				fprintf (fp, "\n");
			}
			fclose( fp );
		}
		else
			printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");
	}
}
Esempio n. 5
0
void collect_block_advanced_triggered ()
{
int		i;
  int		trigger_sample;
  long 	time_interval;
  short 	time_units;
  short 	oversample;
  long 	no_of_samples = BUFFER_SIZE;
  FILE 	*fp;
  long 	time_indisposed_ms;
  short 	overflow;
  int 	threshold_mv =1500;
  long 	max_samples;
	short ch;

  printf ( "Collect block triggered...\n" );
  printf ( "Collects when value rises past %dmV\n", threshold_mv );
  printf ( "Press a key to start...\n" );
  getch ();

  set_defaults ();

	set_trigger_advanced ();


  /*  find the maximum number of samples, the time interval (in time_units),
   *		 the most suitable time units, and the maximum oversample at the current timebase
   */
	oversample = 1;
  while (!ps2000_get_timebase ( unitOpened.handle,
                        timebase,
  					      	    no_of_samples,
                        &time_interval,
                        &time_units,
                        oversample,
                        &max_samples))
	  timebase++;

  /* Start it collecting,
   *  then wait for completion
   */
  ps2000_run_block ( unitOpened.handle, BUFFER_SIZE, timebase, oversample, &time_indisposed_ms );

  printf ( "Waiting for trigger..." );
  printf ( "Press a key to abort\n" );

  while (( !ps2000_ready ( unitOpened.handle )) && ( !kbhit () ))
  {
    Sleep ( 100 );
  }

  if (kbhit ())
  {
    getch ();

    printf ( "data collection aborted\n" );
  }
  else
  {
    ps2000_stop ( unitOpened.handle );

    /* Get the times (in units specified by time_units)
     *  and the values (in ADC counts)
     */
    ps2000_get_times_and_values ( unitOpened.handle,
			                            times,
																	unitOpened.channelSettings[PS2000_CHANNEL_A].values,
																	unitOpened.channelSettings[PS2000_CHANNEL_B].values,
																	NULL,
																	NULL,
																	&overflow, time_units, BUFFER_SIZE );

    /* Print out the first 10 readings,
     *  converting the readings to mV if required
     */
    printf ("Ten readings around trigger\n");
    printf ("Time\tValue\n");
    printf ("(ns)\t(%s)\n", adc_units (time_units));

    /* This calculation is correct for 10% pre-trigger
     */
    trigger_sample = BUFFER_SIZE / 10;

    for (i = trigger_sample - 5; i < trigger_sample + 5; i++)
    {
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
				if(unitOpened.channelSettings[ch].enabled)
				{
					printf ( "%d\t", adc_to_mv ( unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
				}
			}
			printf("\n");
    }
 
    fp = fopen ( "data.txt","w" );
  
    if (fp != NULL)
    {
	  for ( i = 0; i < BUFFER_SIZE; i++ )
    {
		  fprintf ( fp,"%ld ", times[i]);
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
				if(unitOpened.channelSettings[ch].enabled)
				{
					fprintf ( fp, ",%d, %d,", unitOpened.channelSettings[ch].values[i],
																		adc_to_mv ( unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
				}
			}
		  fprintf(fp, "\n");
	  }
    fclose(fp);
    }
	else
		printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");
  }
}
Esempio n. 6
0
/****************************************************************************
 * 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)
{
    int		i;
    long 	time_interval;
    short 	time_units;
    short 	oversample;
    long 	no_of_samples = BUFFER_SIZE;
    FILE 	*fp;
    short 	auto_trigger_ms = 0;
    long 	time_indisposed_ms;
    short 	overflow;
    long 	max_samples;
    short   ch = 0;

  printf ( "Collect block immediate...\n" );
  printf ( "Press a key to start\n" );
  getch ();

  set_defaults ();

  /* Trigger disabled
   */
  ps2000_set_trigger ( unitOpened.handle, PS2000_NONE, 0, PS2000_RISING, 0, auto_trigger_ms );

  /*  find the maximum number of samples, the time interval (in time_units),
   *		 the most suitable time units, and the maximum oversample at the current timebase
   */
	oversample = 1;
  while (!ps2000_get_timebase ( unitOpened.handle,
              timebase,
              no_of_samples,
              &time_interval,
              &time_units,
              oversample,
              &max_samples))
	  timebase++;

  printf ( "timebase: %hd\toversample:%hd\n", timebase, oversample );
  /* Start it collecting,
   *  then wait for completion
   */
  ps2000_run_block ( unitOpened.handle, no_of_samples, timebase, oversample, &time_indisposed_ms );
  while ( !ps2000_ready ( unitOpened.handle ) )
    {
    Sleep ( 100 );
    }

  ps2000_stop ( unitOpened.handle );

  /* Should be done now...
   *  get the times (in nanoseconds)
   *   and the values (in ADC counts)
   */
  ps2000_get_times_and_values ( unitOpened.handle, times,
																unitOpened.channelSettings[PS2000_CHANNEL_A].values, 
																unitOpened.channelSettings[PS2000_CHANNEL_B].values,
																NULL,
																NULL,
																&overflow, time_units, no_of_samples );

  /* Print out the first 10 readings,
   *  converting the readings to mV if required
   */
  printf ( "First 10 readings\n" );
  printf ( "Value\n" );
  printf ( "(%s)\n", adc_units ( time_units ) );

  for ( i = 0; i < 10; i++ )
  {
		for (ch = 0; ch < unitOpened.noOfChannels; ch++)
		{
			if(unitOpened.channelSettings[ch].enabled)
  		{
				//printf ( "%d\t", adc_to_mv ( unitOpened.channelSettings[ch].values[i], unitOpened.channelSettings[ch].range) );
				printf ( "%d\t", unitOpened.channelSettings[ch].values[i] );
			}
		}
		printf("\n");
  }

  fp = fopen ( "data.txt","w" );
  if (fp != NULL)
  {
	for ( i = 0; i < BUFFER_SIZE; i++)
	{
			fprintf ( fp,"%ld ", times[i]);
			for (ch = 0; ch < unitOpened.noOfChannels; ch++)
			{
			if(unitOpened.channelSettings[ch].enabled)
				{
					fprintf ( fp, ",%d, %d,", unitOpened.channelSettings[ch].values[i],
																		adc_to_mv ( unitOpened.channelSettings[ch].values[i],	unitOpened.channelSettings[ch].range) );
				}
			}
			fprintf(fp, "\n");
		}
	fclose(fp);
  }
  else
	printf("Cannot open the file data.txt for writing. \nPlease ensure that you have permission to access. \n");
}