NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Strain Gauge data quisition using NI 9218 and python

I am trying to get the strain gauge data using NI 9218 module. i am using python codes with nidaqmx python library module to acquire the data. the obtained is not at all similar to the data obtained via Ni Daq Max  tasks. please see the below code I am using.

 

import nidaqmx
import csv

# Define the strain gauge channel
strain_gauge_channel = "cDAQ1Mod1/ai0" # Change this to match your actual channel

# Create an empty list to store the acquired data
acquired_data = []

# Create a Task for the strain gauge measurement
with nidaqmx.Task() as task:
# Add the strain gauge channel to the task
task.ai_channels.add_ai_strain_gage_chan(strain_gauge_channel)

# Configure the acquisition settings
task.timing.cfg_samp_clk_timing(rate=100, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS)

# Start the task
task.start()

# Read and append strain gauge data continuously until terminated
print("Press Ctrl+C to stop the acquisition.")
try:
while True:
data = task.read(number_of_samples_per_channel=1)
acquired_data.append(data)
except KeyboardInterrupt:
# Stop the task if Ctrl+C is pressed
task.stop()

# Save the acquired data to a CSV file
csv_filename = "acquired_data.csv"
with open(csv_filename, "w", newline="") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerows(acquired_data)

print(f"Acquired data saved to {csv_filename}")

0 Kudos
Message 1 of 2
(48 Views)

This is the forum for NI TestStand, a test executive software.

Your question is best to be posted on the Multifunction DAQ board.

 

You need to specify your strain gauge parameters when calling add_ai_strain_gage_chan

add_ai_strain_gage_chan(physical_channel, name_to_assign_to_channel='', min_val=-0.001, max_val=0.001, units=StrainUnits.STRAIN, strain_config=StrainGageBridgeType.FULL_BRIDGE_I, voltage_excit_source=ExcitationSource.INTERNAL, voltage_excit_val=2.5, gage_factor=2.0, initial_bridge_voltage=0.0, nominal_gage_resistance=350.0, poisson_ratio=0.3, lead_wire_resistance=0.0, custom_scale_name='')

 

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 2
(29 Views)