acquire_4ch_trigger_software.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Red Pitaya C API example Acquiring a signal from a buffer
  2. * This application acquires a signal on a specific channel */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include "rp.h"
  7. #include "rp_hw-profiles.h"
  8. int main(int argc, char **argv){
  9. uint8_t c = 0;
  10. if (rp_HPGetFastADCChannelsCount(&c) != RP_HP_OK){
  11. fprintf(stderr,"[Error] Can't get fast ADC channels count\n");
  12. return 1;
  13. }
  14. if (c!= 4){
  15. fprintf(stderr,"[Error] The number of channels is wrong\n");
  16. return 1;
  17. }
  18. /* Print error, if rp_Init() function failed */
  19. if(rp_Init() != RP_OK){
  20. fprintf(stderr, "Rp api init failed!\n");
  21. }
  22. uint32_t buff_size = 16384;
  23. rp_AcqReset();
  24. rp_AcqSetDecimation(RP_DEC_8);
  25. rp_AcqSetTriggerDelay(0);
  26. rp_AcqStart();
  27. /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
  28. /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
  29. /*length and smaling rate*/
  30. sleep(1);
  31. rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW);
  32. rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
  33. while(1){
  34. rp_AcqGetTriggerState(&state);
  35. if(state == RP_TRIG_STATE_TRIGGERED){
  36. sleep(1);
  37. break;
  38. }
  39. }
  40. bool fillState = false;
  41. while(!fillState){
  42. rp_AcqGetBufferFillState(&fillState);
  43. }
  44. uint32_t pos = 0;
  45. rp_AcqGetWritePointerAtTrig(&pos);
  46. buffers_t *b = rp_createBuffer(4,buff_size,false,false,true);
  47. rp_AcqGetData(pos, b);
  48. int i;
  49. for(i = 0; i < buff_size; i++){
  50. printf("%f %f %f %f\n", b->ch_f[0][i],b->ch_f[1][i],b->ch_f[2][i],b->ch_f[3][i]);
  51. }
  52. /* Releasing resources */
  53. rp_deleteBuffer(b);
  54. rp_Release();
  55. return 0;
  56. }