Settings in config.yaml file

This commit is contained in:
Gertjan 2026-03-12 23:41:59 +01:00
parent 8086e3298e
commit 3b9eae2893
2 changed files with 31 additions and 17 deletions

View file

@ -9,19 +9,11 @@ import time
import pyodbc
import math
from datetime import datetime
import yaml
import os
data_rows = [] # global 2-D list
state = {
"ampl": 1600,
"remaining_receive_lines": 0,
"freq": 10000.0,
"freq_step_multiply": 0.85,
"stop_freq": 0.1,
"interference_freq": 0.052,
"interference_bandwidth": 0.008,
"initializing": 1,
"noise_scan": False
}
state = {}
PATTERN = re.compile(
r"Va=(?P<Va>-?\d+\.?\d*)\s+"
@ -37,6 +29,19 @@ PATTERN = re.compile(
r"(?P<adc_imax>[0-9a-fA-F]+)" # Fourth hex
)
config_path = '/home/bart/python-scanner/config.yaml'
def load_yaml_config(state_dict):
if os.path.exists(config_path):
with open(config_path, 'r') as f:
# Loader=yaml.SafeLoader is the secure way to load YAML
config_data = yaml.load(f, Loader=yaml.SafeLoader)
if config_data:
state_dict.update(config_data)
else:
print(f"Error: {config_path} not found.")
# =============================================
# Database connection parameters
conn_str = (
"DRIVER={FreeTDS};"
@ -293,14 +298,14 @@ if __name__ == "__main__":
reader.connect()
while True:
data_rows.clear()
state["ampl"] = 1600;
load_yaml_config(state) # Load configuration settings
state["freq"] = state["start_freq"];
state["remaining_receive_lines"] = 0;
state["freq"] = 1000;
state["freq_step_multiply"] = 0.95;
state["stop_freq"] = 0.1;
state["initializing"] = 1;
state["interference_freq"] = 0.052;
state["interference_bandwidth"] = 0.008
reader.read_loop()
finally:
reader.disconnect()