|
10 | 10 | Edge, |
11 | 11 | ExcitationSource, |
12 | 12 | FilterResponse, |
13 | | - LoggingMode, |
14 | | - LoggingOperation, |
15 | 13 | Slope, |
16 | 14 | StrainGageBridgeType, |
17 | 15 | TerminalConfiguration, |
18 | 16 | ) |
| 17 | +import time |
19 | 18 |
|
| 19 | +import nidaqmx.system |
20 | 20 | import nipanel |
21 | | - |
22 | 21 | panel_script_path = Path(__file__).with_name("nidaqmx_analog_input_filtering_panel.py") |
23 | 22 | panel = nipanel.create_panel(panel_script_path) |
24 | 23 | panel.set_value("is_running", False) |
| 24 | + |
| 25 | +system = nidaqmx.system.System.local() |
| 26 | + |
| 27 | +channel_name = [] |
| 28 | +for dev in system.devices: |
| 29 | + for chan in dev.ai_physical_chans: |
| 30 | + channel_name.append(chan.name) |
| 31 | +panel.set_value("channel_name", channel_name) |
| 32 | +trigger_sources = [] |
| 33 | +for dev in system.devices: |
| 34 | + if hasattr(dev, "terminals"): |
| 35 | + for term in dev.terminals: |
| 36 | + trigger_sources.append(term) |
| 37 | +panel.set_value("trigger_sources", trigger_sources) |
25 | 38 | try: |
26 | 39 | print(f"Panel URL: {panel.panel_url}") |
27 | 40 | print(f"Waiting for the 'Run' button to be pressed...") |
28 | 41 | print(f"(Press Ctrl + C to quit)") |
29 | 42 | while True: |
30 | 43 | while not panel.get_value("run_button", False): |
31 | 44 | panel.set_value("is_running", False) |
| 45 | + # time.sleep(0.1) |
32 | 46 | panel.set_value("is_running", True) |
33 | 47 | panel.set_value("stop_button", False) |
34 | 48 |
|
35 | 49 | # How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/ |
36 | 50 | with nidaqmx.Task() as task: |
| 51 | + |
37 | 52 | chan_type = panel.get_value("chan_type", "1") |
38 | 53 |
|
39 | 54 | if chan_type == "2": |
40 | 55 | chan = task.ai_channels.add_ai_current_chan( |
41 | | - "Mod3/ai10", |
| 56 | + panel.get_value("physical_channel", ""), |
42 | 57 | max_val=panel.get_value("max_value_current", 0.01), |
43 | 58 | min_val=panel.get_value("min_value_current", -0.01), |
44 | 59 | ext_shunt_resistor_val=panel.get_value("shunt_resistor_value", 249.0), |
|
50 | 65 |
|
51 | 66 | elif chan_type == "3": |
52 | 67 | chan = task.ai_channels.add_ai_strain_gage_chan( |
53 | | - "Mod3/ai10", |
| 68 | + panel.get_value("physical_channel", ""), |
54 | 69 | nominal_gage_resistance=panel.get_value("gage_resistance", 350.0), |
55 | 70 | voltage_excit_source=ExcitationSource.EXTERNAL, # Only mode that works |
56 | 71 | max_val=panel.get_value("max_value_strain", 0.001), |
|
66 | 81 | ) |
67 | 82 | else: |
68 | 83 | chan = task.ai_channels.add_ai_voltage_chan( |
69 | | - "Mod3/ai10", |
| 84 | + panel.get_value("physical_channel", ""), |
70 | 85 | terminal_config=panel.get_value( |
71 | 86 | "terminal_configuration", TerminalConfiguration.DEFAULT |
72 | 87 | ), |
73 | 88 | max_val=panel.get_value("max_value_voltage", 5.0), |
74 | 89 | min_val=panel.get_value("min_value_voltage", -5.0), |
75 | 90 | ) |
| 91 | + |
76 | 92 |
|
77 | 93 | task.timing.cfg_samp_clk_timing( |
78 | 94 | rate=panel.get_value("rate", 1000.0), |
79 | 95 | sample_mode=AcquisitionType.CONTINUOUS, |
80 | 96 | samps_per_chan=panel.get_value("total_samples", 100), |
81 | 97 | ) |
82 | | - panel.set_value("actual_sample_rate", task._timing.samp_clk_rate) |
| 98 | + panel.set_value("actual_sample_rate", task.timing.samp_clk_rate) |
83 | 99 | panel.set_value("sample_rate", panel.get_value("rate", 100.0)) |
84 | | - |
85 | | - task.in_stream.configure_logging( |
86 | | - file_path=panel.get_value("tdms_file_path", "data.tdms"), |
87 | | - logging_mode=panel.get_value("logging_mode", LoggingMode.OFF), |
88 | | - operation=LoggingOperation.OPEN_OR_CREATE, |
89 | | - ) |
| 100 | + |
90 | 101 | if panel.get_value("filter", "Filter") == "Filter": |
91 | 102 | chan.ai_filter_enable = True |
92 | 103 | chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) |
|
101 | 112 | panel.set_value("actual_filter_freq", 0.0) |
102 | 113 | panel.set_value("actual_filter_response", FilterResponse.COMB) |
103 | 114 | panel.set_value("actual_filter_order", 0) |
104 | | - |
| 115 | + |
105 | 116 | trigger_type = panel.get_value("trigger_type") |
106 | 117 | if trigger_type == "5": |
107 | 118 | task.triggers.start_trigger.cfg_anlg_edge_start_trig( |
108 | 119 | trigger_source="APFI0", |
109 | 120 | trigger_slope=panel.get_value("slope", Slope.FALLING), |
110 | 121 | trigger_level=panel.get_value("level", 0.0), |
111 | 122 | ) |
| 123 | + |
| 124 | + |
112 | 125 | if trigger_type == "2": |
113 | 126 | task.triggers.start_trigger.cfg_dig_edge_start_trig( |
114 | 127 | trigger_source="/Dev2/PFI0", trigger_edge=panel.get_value("edge", Edge.FALLING) |
|
0 commit comments