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 (); }
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 (); }