Now I only see Scilab and Labview?? http://blog.redpitaya.com/examples-new/ ... r-acquire/
I need to get my program working, and my C binary has been returning corrupted data (Sometimes it works fine, sometimes it comes back very wonky).
Attached C code for those who are interested. Maybe you can quickly spot what I'm doing wrong, I need to figure this out i've been stuck for days. Any help would be greatly appreciated.
Code: Select all
/* Red Pitaya C API example Acquiring a signal from a buffer
* This application acquires a signal on a specific channel */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "redpitaya/rp.h"
#include <time.h>
#include <inttypes.h>
int main(int argc, char **argv){
int iterationsToRun = (int) strtol(argv[1], NULL, 0);
int fastinputchannel = (int) strtol(argv[2], NULL, 0);
struct timespec start, end;
if(rp_Init() != RP_OK){
fprintf(stderr, "Rp api init failed!\n");
}
uint32_t buff_size = 7000;
float *buff = (float *)malloc(buff_size * iterationsToRun * sizeof(float));
rp_AcqReset();
rp_AcqSetDecimation(1); // Sample rate 125Msps; Buffer time length 131us; Decimation 1
if(fastinputchannel == 1){
rp_AcqSetTriggerLevel(RP_CH_1, 0.1); //Trig level is set in Volts while in SCPI (threshold)
}
if(fastinputchannel == 2){
rp_AcqSetTriggerLevel(RP_CH_2, 0.1); //Trig level is set in Volts while in SCPI (threshold)
}
rp_AcqSetTriggerDelay(0);
rp_AcqSetSamplingRate(1);
uint32_t samplingRate = 0;
rp_AcqGetSamplingRate(&samplingRate);
printf("%" PRIu32 "\n", samplingRate);
for(int i=0; i< iterationsToRun; i++){
float *curBuffPosition = buff + (i * buff_size);
//printf("buff pos: %p\n", curBuffPosition);
clock_gettime(CLOCK_MONOTONIC, &start);
rp_AcqStart();
rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW);
rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED; // Is this even necessary?
while(1){
rp_AcqGetTriggerState(&state);
if(state == RP_TRIG_STATE_TRIGGERED){
break;
}
}
if(fastinputchannel == 1){
rp_AcqGetOldestDataV(RP_CH_1, &buff_size, curBuffPosition);
}
if(fastinputchannel == 2){
rp_AcqGetOldestDataV(RP_CH_2, &buff_size, curBuffPosition);
}
clock_gettime(CLOCK_MONOTONIC, &end);
//printf("Acquired in %lu seconds\n", (end.tv_nsec - start.tv_nsec));
char fileNameBuffer[32];
snprintf(fileNameBuffer, sizeof(char)*32, "data%i/output%i.txt", fastinputchannel, i);
FILE *f = fopen(fileNameBuffer, "wb");
for(int j=0; j<buff_size; j++){
fprintf(f,"%1.9g\n",buff[i*buff_size+j]);
}
}
/* Releasing resources */
free(buff);
rp_Release();
return 0;
}