-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_logic-pattern.cpp
78 lines (60 loc) · 2.25 KB
/
test_logic-pattern.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "WF_SDK/WF_SDK.h" // include all classes and functions
#include <iostream> // needed for input/output
#include <string> // needed for error handling
#include <fstream>
#include <vector>
using namespace wf;
#define DIO_IN 14
#define DIO_OUT 14
/* ----------------------------------------------------- */
int main(void) {
// connect to the device
Device::Data *device_data;
try {
device_data = device.open();
/* ----------------------------------------------------- */
// use instruments here
// initialize the logic analyzer with default settings
logic.open(device_data);
// set up triggering on selected DIO
logic.trigger(device_data, true, DIO_IN, 0, 0, false);
// generate a 100KHz PWM signal with 30% duty cycle on selected DIO
pattern.generate(device_data, DIO_OUT, pattern.function.pulse, 100e03, 30);
// wait 1 second
tools.sleep(1000);
// record data on selected DIO
std::vector<unsigned short> buffer = logic.record(device_data, DIO_IN);
// limit displayed data size
int length = buffer.size();
if (length > 10000) {
length = 10000;
}
// save data
std::ofstream file;
file.open("test_logic-pattern.csv");
file << "time [us],logic value\n";
for (int index = 0; index < length; index++) {
file << std::to_string(index * 1e06 / logic.data.sampling_frequency) << "," << std::to_string(buffer[index]) << std::endl;
}
file.close();
// plot
system("python plotting.py test_logic-pattern.csv");
// reset the logic analyzer
logic.close(device_data);
// reset the pattern generator
pattern.close(device_data);
/* ----------------------------------------------------- */
// close the connection
device.close(device_data);
}
catch (Error error) {
// if an error occurs display it
std::cout << "Error: ";
std::cout << error.instrument << " -> ";
std::cout << error.function << " -> ";
std::cout << error.message << std::endl;
// close the connection
device.close(device_data);
}
return 0;
}