import numpy as np import time from datetime import datetime import pandas as pd import os ### Function Definitions def get_adc_hits(polldata): # parse the adc hits from the poll data polldatalist = polldata.split('\n') hits = int(polldatalist[15].strip().split(':')[1].strip()) return hits def get_conductivity(polldata): # parse the conductivity from the poll data polldatalist = polldata.split('\n') conductivity = float(polldatalist[20].strip().split(':')[1].strip()[0:-4]) return conductivity ### # load the Python API for the Analog Devices CN0359 evaluation board # from automatedtesting.instruments.analog_devices_conductivity_board import AnalogDevicesConductivityBoard from modules.analog_devices_conductivity_board import AnalogDevicesConductivityBoard # create an instance of the CN0359 Eval Board cond1 = AnalogDevicesConductivityBoard() #cond1.create_connection('/dev/ttyUSB0', '31') cond1.create_connection('COM3', '31') ### ### Parameters ### # Set the number of data points to collect at each sampling frequency N = 100 # Define frequency of the excitation signal on the CN0359 # Fext = 1000 # set the excitation frequency on the EVAL-CN0359 board # cond1.set_frequency(Fext) # Define the polling frequencies at which to collect data Fps = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000] # Define the excitation frequency at which to collect data Fexts = [100, 200, 500, 1000, 2000, 5000] # Define the path to the folder where the data will be stored # parentdirectory = '/mnt/VMShare/DavidC/data/CN0359/' parentdirectory = r'C:\Users\ven.asrivastava\Desktop\My_Folder\Project\Jira_tasks\Conductivity_sensor_decoding\New_conductivity _sensor\David_Python_Scripts\Data' # Define the directory that the data set will be stored in # the parent directory directory = 'diality_unmodified_fw' ### ### end parameters ### # Create a timestamp for the current data set timestamp = datetime.now().strftime('%Y%m%d_%H%M') # append the timestamp to the data directory directory = directory + '_' + timestamp # create the data storage path os.makedirs(os.path.join(parentdirectory, directory), exist_ok=True) # loop over the list of excitation frequencies for Fext in Fexts: # set the excitation frequency on the EVAL-CN0359 board # DDC Note - I noticed that the excitation frequency was not being # changed inside the loop at 1500h 2025-12-10. Any data collected # before that time with this script is not valid. cond1.set_frequency(Fext) # create a Pandas dataframe in which to store the adc_hits data hitsdf = pd.DataFrame() # create a Pandas dataframe in which to store the conductivity data conductivitydf = pd.DataFrame() # Create filename in which to store the adc hits collected at the current polling frequency adchitsfilename = 'adc_hits_{:.0f}.csv'.format(Fext) # concatenate the data file path and the adc hits file name adchitsfile = os.path.join(parentdirectory, directory, adchitsfilename) # Create filename in which to store the conductivities collected at the current polling frequency conductivitiesfilename = 'conductivities_{:.0f}.csv'.format(Fext) # concatenate the date file path and the conductivity file name conductivitiesfile = os.path.join(parentdirectory, directory, conductivitiesfilename) # Loop over the list of polling frequencies for Fp in Fps: print('{}, {}'.format(Fp, Fext)) Tp = 1 / Fp # Calculate the polling period from the polling rate # Create a list to keep the poll data frames in # The poll data frames are not parsed in the loop to save time polldata = [] # Collect N datapoints. Pause for the polling period between collecting poll data frames for ii in range(N): polldata.append(cond1.get_poll()) time.sleep(Tp) # create a numpy array in which to keep the adc_hits data hits = np.array([]) conductivities = np.array([]) for poll in polldata: hits = np.append(hits, get_adc_hits(poll)) conductivities = np.append(conductivities, get_conductivity(poll)) # create a dataframe column label for the current polling frequency collabel = 'Fp{}'.format(Fp) # append the adc hits data to the adc hits dataframe hitsdf[collabel] = hits # append the conductivity data to the conductivity dataframe conductivitydf[collabel] = conductivities # after the loop over the polling frequency has been # completed write the data in the dataframes to csv files hitsdf.to_csv(adchitsfile) conductivitydf.to_csv(conductivitiesfile)