import parser import struct ######################################################################################################################## # {"poll", cmd_poll}, def cmd_poll(cond1): cond1.ser.write(b'poll\n') print("Sent command cmd_poll") i = 0 poll = "" while i <= 21: # 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) ######################################################################################################################## # {"poll_bin", cmd_poll_bin}, def cmd_poll_bin(cond1): cond1.ser.write(b' poll_bin\n') print("Sent command cmd_poll_bin") data = cond1.ser.read(100) print(data) parsed = parser.parse_cmd_poll_bin(data) parser.print_poll_readout(parsed) ######################################################################################################################## # {"setvolt", cmd_voltage} def cmd_voltage(cond1, value): cond1.ser.write(f"setvolt {value}\n".encode()) print("Sent command cmd_voltage_bin") ######################################################################################################################## # {"setfreq_bin", cmd_frequency_bin}, def cmd_frequency_bin(cond1, value): cond1.ser.write(f"setfreq_bin {value}\n".encode()) print("Sent command cmd_frequency_bin") data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"setk", cmd_cellconstant}, def cmd_cellconstant(cond1, value): cond1.ser.write(f"setk {value}\n".encode()) print("Sent command cmd_cellconstant_bin") ######################################################################################################################## # {"setcof_bin", cmd_coefficient_bin}, def cmd_coefficient_bin(cond1, value): cond1.ser.write(f"setcof_bin {value}\n".encode()) print("Sent command cmd_coefficient_bin") data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"setstm_bin", cmd_setuptime_bin}, def cmd_setuptime_bin(cond1, value): cond1.ser.write(f"setstm_bin {value}\n".encode()) print("Sent command cmd_setuptime_bin") data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"sethtm_bin", cmd_holdtime_bin}, def cmd_holdtime_bin(cond1, value): cond1.ser.write(f"sethtm_bin {value}\n".encode()) print("Sent command cmd_holdtime_bin") data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"setcal_bin", cmd_setCalData_bin}, def cmd_setCalData_bin(cond1): # Prepare coefficients (floats as plain decimals) coeffs = [ 0.016 * 10, -0.010* 10, -0.010 * 10, 0.012 * 10, 35.832 * 10, -28.066 * 10, ] # coeffs = [ # 0.0162777400 / 10, # -0.0108147500 / 10, # -0.0109372700 / 10, # 0.0122156087 / 10, # 35.8320791500 / 10, # -28.0662148100 / 10, # ] # Build: "
setcal_bin v1 v2 v3 v4 v5 v6\n" # Use fixed-point formatting to avoid scientific notation, ensure ASCII payload = " ".join(f"{v:.10f}" for v in coeffs) cmd = f"setcal_bin {payload}\n".encode("ascii") print(cmd) # Send command cond1.ser.write(cmd) print("Sent command cmd_setCalData_bin") data = cond1.ser.readline() # Read one byte status (same pattern as your other function) # data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"getcal_bin", cmd_getCalData_bin} def cmd_getCalData_bin(cond1): cond1.ser.write(b' c\n') print("Sent command cmd_getCalData_bin") data = cond1.ser.read(48) print(data) d = parser.parse_cal_file_bytes(data) parser.print_cal_file(d) ######################################################################################################################## # {"setcal_bin", cmd_setCalData_bin}, def cmd_setSerial_bin(cond1): value = 0.2 # cmd = b'setsn 0x002\n' cmd = f"setsn {value}\n".encode() cond1.ser.write(cmd) print("Sent command cmd_setSerial_bin") data = cond1.ser.read(1) print(data) ######################################################################################################################## # {"getcal_bin", cmd_getSerial_bin} def cmd_getSerial_bin(cond1): cmd =b' n\n' cond1.ser.write(cmd) print("Sent command cmd_getSerial_bin") data = cond1.ser.read(4) print(data) print(struct.unpack('