import parser import struct import time from datetime import datetime exp_coeff = [13.1, 10.006, 10.6, -11.0, 13.1, 10.03, 12.0, 199.0, 11.5, 17.1, 110.11, 110.12] exp_fw_ver = "v0.1.0" exp_hw_ver = "v0.1.1" exp_sn = "v0.1.2" ######################################################################################################################## # This function reads the sensor data and settings # {"poll", cmd_poll}, def cmd_poll(cond1): cond1.ser.write(b'poll\n') print("Sent command cmd_poll") i = 0 poll = "" while i <= 21: line = cond1.ser.readline() current_line_text = line.decode('utf-8', errors='replace') poll += current_line_text i += 1 print(poll) ######################################################################################################################## # This function updates the excitation voltage in the flash. # {"setvolt", cmd_voltage} def cmd_voltage(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"setvolt {value}\n".encode()) print("Sent command cmd_voltage") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function updates the excitation frequency in the flash. # {"setfreq", cmd_frequency}, def cmd_frequency(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"setfreq {value}\n".encode()) print("Sent command cmd_frequency") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function updates the setup time in the flash. # {"setstm", cmd_setuptime}, def cmd_setuptime(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"setstm {value}\n".encode()) print("Sent command cmd_setuptime") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function updates the hold time in the flash. # {"sethtm", cmd_holdtime}, def cmd_holdtime(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"sethtm {value}\n".encode()) print("Sent command cmd_holdtime") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function updates the temperature coefficient in the flash. # {"setcof", cmd_coefficient}, def cmd_coefficient(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"setcof {value}\n".encode()) print("Sent command cmd_coefficient") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function updates the cell constant in the flash. # {"setk", cmd_cellconstant}, def cmd_cellconstant(cond1, value): cond1.ser.reset_input_buffer() cond1.ser.write(f"setk {value}\n".encode()) print("Sent command cmd_cellconstant") # minimal wait until some data arrives while cond1.ser.in_waiting == 0: pass data = cond1.ser.readline() print(data) ######################################################################################################################## # This function retrieves raw sensor data in ASCII format. # {"getraw", cmd_tx_raw_poll}, def cmd_tx_raw_poll(cond1): cond1.ser.reset_input_buffer() cond1.ser.write(b'getraw\n') print("Sent command getraw") i = 0 poll = "" while i <= 6: # decode by number of lines of data messages current_line_text = str(cond1.ser.readline().decode()) poll = poll + current_line_text i += 1 print(poll) ######################################################################################################################## # This function retrieves raw conductivity and temperature values in binary format. def read_autopoll(cond1, duration_sec=10): fmt = "