|
35 | 35 | # How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/ |
36 | 36 | with nidaqmx.Task() as task: |
37 | 37 | chan_type = panel.get_value("chan_type", "1") |
38 | | - if chan_type == "1": |
39 | | - chan = task.ai_channels.add_ai_voltage_chan( |
40 | | - "Mod3/ai10", |
41 | | - terminal_config=panel.get_value( |
42 | | - "terminal_configuration", TerminalConfiguration.DEFAULT |
43 | | - ), |
44 | | - max_val=panel.get_value("max_value_voltage", 5.0), |
45 | | - min_val=panel.get_value("min_value_voltage", -5.0), |
46 | | - ) |
47 | | - chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) |
48 | | - chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB) |
49 | | - chan.ai_filter_order = 1 |
50 | | - |
51 | | - elif chan_type == "2": |
| 38 | + |
| 39 | + if chan_type == "2": |
52 | 40 | chan = task.ai_channels.add_ai_current_chan( |
53 | 41 | "Mod3/ai10", |
54 | 42 | max_val=panel.get_value("max_value_current", 0.01), |
|
59 | 47 | ), |
60 | 48 | units=panel.get_value("units", CurrentUnits.AMPS), |
61 | 49 | ) |
62 | | - chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) |
63 | | - chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB) |
64 | | - chan.ai_filter_order = 1 |
65 | 50 |
|
66 | 51 | elif chan_type == "3": |
67 | 52 | chan = task.ai_channels.add_ai_strain_gage_chan( |
|
79 | 64 | "strain_configuration", StrainGageBridgeType.FULL_BRIDGE_I |
80 | 65 | ), |
81 | 66 | ) |
82 | | - |
83 | | - chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) |
84 | | - chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB) |
85 | | - chan.ai_filter_order = 1 |
| 67 | + else: |
| 68 | + chan = task.ai_channels.add_ai_voltage_chan( |
| 69 | + "Mod3/ai10", |
| 70 | + terminal_config=panel.get_value( |
| 71 | + "terminal_configuration", TerminalConfiguration.DEFAULT |
| 72 | + ), |
| 73 | + max_val=panel.get_value("max_value_voltage", 5.0), |
| 74 | + min_val=panel.get_value("min_value_voltage", -5.0), |
| 75 | + ) |
86 | 76 |
|
87 | 77 | task.timing.cfg_samp_clk_timing( |
88 | 78 | rate=panel.get_value("rate", 1000.0), |
89 | 79 | sample_mode=AcquisitionType.CONTINUOUS, |
90 | 80 | samps_per_chan=panel.get_value("total_samples", 100), |
91 | 81 | ) |
| 82 | + panel.set_value("actual_sample_rate", task._timing.samp_clk_rate) |
| 83 | + panel.set_value("sample_rate", panel.get_value("rate", 100.0)) |
| 84 | + |
92 | 85 | task.in_stream.configure_logging( |
93 | 86 | file_path=panel.get_value("tdms_file_path", "data.tdms"), |
94 | 87 | logging_mode=panel.get_value("logging_mode", LoggingMode.OFF), |
95 | 88 | operation=LoggingOperation.OPEN_OR_CREATE, |
96 | 89 | ) |
| 90 | + if panel.get_value("filter","Filter") == "Filter": |
| 91 | + chan.ai_filter_enable = True |
| 92 | + chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) |
| 93 | + chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB) |
| 94 | + chan.ai_filter_order = panel.get_value("filter_order", 1) |
| 95 | + # Not all hardware supports all filter types. |
| 96 | + # Refer to your device documentation for more information. |
| 97 | + panel.set_value("actual_filter_freq", chan.ai_filter_freq) |
| 98 | + panel.set_value("actual_filter_response", chan.ai_filter_response) |
| 99 | + panel.set_value("actual_filter_order", chan.ai_filter_order) |
| 100 | + else: |
| 101 | + panel.set_value("actual_filter_freq", 0.0) |
| 102 | + panel.set_value("actual_filter_response", FilterResponse.COMB) |
| 103 | + panel.set_value("actual_filter_order", 0) |
97 | 104 |
|
98 | 105 | trigger_type = panel.get_value("trigger_type") |
99 | | - panel.set_value("sample_rate", task._timing.samp_clk_rate) |
100 | 106 | if trigger_type == "5": |
101 | 107 | task.triggers.start_trigger.cfg_anlg_edge_start_trig( |
102 | 108 | trigger_source="APFI0", |
|
112 | 118 | ) |
113 | 119 |
|
114 | 120 | try: |
115 | | - |
116 | 121 | task.start() |
117 | | - |
118 | 122 | while not panel.get_value("stop_button", False): |
119 | 123 | data = task.read(number_of_samples_per_channel=100) |
120 | | - panel.set_value("voltage_data", data) |
121 | | - panel.set_value("current_data", data) |
122 | | - panel.set_value("strain_data", data) |
123 | | - |
| 124 | + panel.set_value("acquired_data", data) |
124 | 125 | except KeyboardInterrupt: |
125 | 126 | pass |
126 | 127 | finally: |
|
0 commit comments