Modified for new integrated readouts (Q command) - untested

This commit is contained in:
Gertjan Koolen 2026-03-21 23:57:29 +01:00
parent 06f35acc4e
commit f73dcd0a22

View file

@ -25,7 +25,9 @@ PATTERN = re.compile(
r"(?P<adc_vmin>[0-9a-fA-F]+)-(?P<adc_vmax>[0-9a-fA-F]+)\s+" r"(?P<adc_vmin>[0-9a-fA-F]+)-(?P<adc_vmax>[0-9a-fA-F]+)\s+"
r"(?P<adc_imin>[0-9a-fA-F]+)-(?P<adc_imax>[0-9a-fA-F]+).*?\|\s+" r"(?P<adc_imin>[0-9a-fA-F]+)-(?P<adc_imax>[0-9a-fA-F]+).*?\|\s+"
r"nv=(?P<nv>[\d.-]+)\s+ni=(?P<ni>[\d.-]+)" r"nv=(?P<nv>[\d.-]+)\s+ni=(?P<ni>[\d.-]+)"
r"QZR=(?P<QZR>[\d.-]+)\s+QZX=(?P<QZX>[\d.-]+)"
) )
Va=16.376152 Vp=5.82 | Ia=30.656820 Ip=5.84 | ZR=0.534176 ZX=-0.000190 R=516.000 | freq=1000.0 ampl=100.0 | BW=0.500| irq=59 0c-7b 18-83 | nv=4.494 ni=8.487 | QZR=0.654321 QZX=12.123456
config_path = '/home/bart/python-scanner/config.yaml' # XXXDB config_path = '/home/bart/python-scanner/config.yaml' # XXXDB
#config_path = 'config.yaml' #config_path = 'config.yaml'
@ -146,10 +148,9 @@ def extract_to_dataframe(line):
int(match.group("adc_imax"), 16), # row 10 int(match.group("adc_imax"), 16), # row 10
float(match.group("nv")), # row 11 float(match.group("nv")), # row 11
float(match.group("ni")), # row 12 float(match.group("ni")), # row 12
float(match.group("QZR")), # row 13
float(match.group("QZX")), # row 14
] ]
row[1] = row[1]/(2*3.14159*row[0]*0.00005 + 1) # compensate Va for pole at 20kHz
row[5] = row[1]/row[3] * math.cos(0.01745*(row[2]-row[4]))
row[6] = row[1]/row[3] * math.sin(0.01745*(row[2]-row[4]))
data_rows.append(row) data_rows.append(row)
def process_line(line): def process_line(line):
@ -161,7 +162,7 @@ def process_line(line):
def get_dataframe(): def get_dataframe():
return pd.DataFrame( return pd.DataFrame(
data_rows, data_rows,
columns=["Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"] columns=["Va", "Vp", "Ia", "Ip", "QZR", "QZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"]
) )
class TelnetReader: class TelnetReader:
@ -218,12 +219,9 @@ class TelnetReader:
def process_line(self, line): def process_line(self, line):
global state global state
global Inoise_baseline global Inoise_baseline
# print(f"RAW: {line}") print(line)
if not line.startswith("Va="): # skip lines that are not to be analyzed if not line.startswith("Va="): # skip lines that are not to be analyzed
return return
if state["remaining_receive_lines"] > 0 :
state["remaining_receive_lines"] -= 1 # we are waiting for settling - just skip the line
else:
# prepare new frequency measurement # prepare new frequency measurement
if state["initializing"] == 1: if state["initializing"] == 1:
# since we just start a frequency scan, let's set the R, Max and Amplitude # since we just start a frequency scan, let's set the R, Max and Amplitude
@ -260,10 +258,6 @@ class TelnetReader:
else: else:
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
state["freq"] *= freq_multiplier state["freq"] *= freq_multiplier
# if (state["freq"]>40) and (state["freq"]<660) and ((state["freq"]%50<2.5) or (-state["freq"]%50<2.5)):
# state["freq"] *= freq_multiplier # if near a 50Hz harmonic, skip to the next frequency
# while (state["freq"]<0.6) and ((state["freq"]%state["interference_freq"]<state["interference_bandwidth"]) or (-state["freq"]<state["interference_freq"]<state["interference_bandwidth"])):
# state["freq"] *= freq_multiplier # if near a 0.052Hz harmonic, skip to the next frequency
while (any(item["Freq"] == state["freq"] for item in blacklist)): while (any(item["Freq"] == state["freq"] for item in blacklist)):
print("skipping freq") print("skipping freq")
state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted
@ -271,18 +265,8 @@ class TelnetReader:
print("Reached stop frequency") print("Reached stop frequency")
else: else:
# program the health monitor to go to the next frequency: # program the health monitor to go to the next frequency:
if state["freq"] > 0.01: response = f"\rQ{state["freq"]:.3f}\r" # new freq
response = f"\rf{state["freq"]:.1f}\r" # new freq
else:
response = f"\rf{state["freq"]:.3f}\r" # new freq
self.tn.write(response.encode("utf-8")) self.tn.write(response.encode("utf-8"))
bandwidth = state["freq"]/20
if bandwidth > 0.5 :
bandwidth = 0.5
response = f"b{bandwidth:.3f}\r" # new freq
self.tn.write(response.encode("utf-8"))
state["remaining_receive_lines"] = 2 + 4/bandwidth
print(line)
# print(state) # print(state)
state["initializing"] = 0 state["initializing"] = 0
@ -311,7 +295,6 @@ if __name__ == "__main__":
load_yaml_config(state) # Load configuration settings load_yaml_config(state) # Load configuration settings
state["freq"] = state["start_freq"]; state["freq"] = state["start_freq"];
state["remaining_receive_lines"] = 0;
state["initializing"] = 1; state["initializing"] = 1;
reader.read_loop() reader.read_loop()