first working recording, max 1 MS/s
This commit is contained in:
parent
f342f4001d
commit
eeea678d5f
@ -2,6 +2,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libps2000/ps2000.h>
|
#include <libps2000/ps2000.h>
|
||||||
|
|
||||||
@ -12,43 +13,64 @@ void capture_stop(int signal) {
|
|||||||
stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const uint32_t buffersize = 10000;
|
||||||
|
|
||||||
void get_overview_buffers(int16_t** overviewBuffers, int16_t overflow, uint32_t triggeredAt, int16_t triggered, int16_t auto_stop, uint32_t nValues) {
|
void get_overview_buffers(int16_t** overviewBuffers, int16_t overflow, uint32_t triggeredAt, int16_t triggered, int16_t auto_stop, uint32_t nValues) {
|
||||||
(void)overflow;
|
(void)overflow;
|
||||||
(void)triggeredAt;
|
(void)triggeredAt;
|
||||||
(void)triggered;
|
(void)triggered;
|
||||||
(void)auto_stop;
|
(void)auto_stop;
|
||||||
|
|
||||||
fwrite(overviewBuffers[0], sizeof(int16_t), nValues, stdout);
|
fprintf(stderr, "nValues: %u\n", nValues);
|
||||||
|
|
||||||
|
static float floatbuff[10000]; // TODO variable
|
||||||
|
for (unsigned i = 0; i < nValues; i++) {
|
||||||
|
floatbuff[i] = overviewBuffers[0][i];
|
||||||
|
floatbuff[i] /= 32768; // TODO limit.h
|
||||||
|
}
|
||||||
|
fwrite(floatbuff, sizeof(float), nValues, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
signal(SIGINT, &capture_stop);
|
|
||||||
|
|
||||||
int16_t unit = ps2000_open_unit();
|
int16_t unit = ps2000_open_unit();
|
||||||
|
|
||||||
if (ps2000_set_channel(unit, PS2000_CHANNEL_A, true, false, PS2000_100MV) == 0) {
|
if (ps2000_set_channel(unit, PS2000_CHANNEL_A, true, false, PS2000_10V) == 0) {
|
||||||
fprintf(stderr, "set channel unsuccesful!\n");
|
fprintf(stderr, "set_channel failed!\n");
|
||||||
ps2000_close_unit(unit);
|
ps2000_close_unit(unit);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ps2000_set_trigger(unit, PS2000_NONE, 0, 0, 0, 0) == 0) {
|
if (ps2000_set_trigger(unit, PS2000_NONE, 0, 0, 0, 0) == 0) {
|
||||||
fprintf(stderr, "set trigger unsuccesful!\n");
|
fprintf(stderr, "set_trigger failed!\n");
|
||||||
ps2000_close_unit(unit);
|
ps2000_close_unit(unit);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ps2000_run_streaming_ns(unit, 100, PS2000_US, 100000, false, 1, 100000) == 0) {
|
if (ps2000_run_streaming_ns(unit, 1000, PS2000_NS, buffersize, false, 1, 50000) == 0) {
|
||||||
fprintf(stderr, "run streaming unsuccesful!\n");
|
fprintf(stderr, "run_streaming_ns failed!\n");
|
||||||
ps2000_close_unit(unit);
|
ps2000_close_unit(unit);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal(SIGINT, &capture_stop);
|
||||||
|
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
ps2000_get_streaming_last_values(unit, &get_overview_buffers);
|
if (ps2000_get_streaming_last_values(unit, &get_overview_buffers) == 0) {
|
||||||
|
// fprintf(stderr, "callback won't be called!\n");
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int16_t overrun = 0;
|
||||||
|
if (ps2000_overview_buffer_status(unit, &overrun) != 0) {
|
||||||
|
fprintf(stderr, "failed to check overrun!\n");
|
||||||
|
} else if (overrun) {
|
||||||
|
fprintf(stderr, "overrun!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// usleep(0);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ps2000_stop(unit);
|
ps2000_stop(unit);
|
||||||
|
12
test/fft.py
Executable file
12
test/fft.py
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
with open("test", "rb") as f:
|
||||||
|
data = np.fromfile(f, dtype=np.int16)
|
||||||
|
|
||||||
|
plt.psd(data, Fs=1e6)
|
||||||
|
plt.show()
|
12
test/view.py
Executable file
12
test/view.py
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
with open("test", "rb") as f:
|
||||||
|
data = np.fromfile(f, dtype=np.int16)
|
||||||
|
|
||||||
|
plt.plot(data[:10000])
|
||||||
|
plt.show()
|
Loading…
Reference in New Issue
Block a user