diff --git a/Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py b/Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py index 09c5d53..437e869 100644 --- a/Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py +++ b/Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py @@ -62,6 +62,22 @@ def SCPICommand(ser, cmd: str) -> str: libreCAL_firmware = idn[3] print("Detected LibreCAL device has serial number "+libreCAL_serial) +# Set the time on the LibreCAL +dt = datetime.now() +now_utc = datetime.utcnow() +utc_offset = dt - now_utc +offset_seconds = int(utc_offset.total_seconds()) +offset_hours = abs(offset_seconds // 3600) +offset_minutes = abs((offset_seconds // 60) % 60) +if offset_seconds < 0: + sign = "-" +else: + sign = "+" +offset_str = f"{sign}{offset_hours:02d}:{offset_minutes:02d}" +dt_str = dt.strftime("%Y/%m/%d %H:%M:%S") +dt_str_with_offset = f"{dt_str} UTC{offset_str}" +SCPICommand(ser, ":DATE_TIME "+dt_str_with_offset) + if not VNA.checkIfReady(): exit("VNA is not ready.") @@ -261,6 +277,7 @@ def takeMeasurements(portmapping : dict): f.write("# GHz S RI R 50.0\n") for data in rCoeffs[r]: f.write(str(data[0] / 1000000000.0) + " " + str(data[1].real) + " " + str(data[1].imag) + "\n") + f.close() for t in tCoeffs: f = open(args.directory + "/" + libreCAL_serial + "/" + t + ".s2p", "w") f.write("! Created by factory calibration script\n") @@ -274,6 +291,7 @@ def takeMeasurements(portmapping : dict): + " " + str(m["S21"][i][1].real) + " " + str(m["S21"][i][1].imag) + " " + str(m["S12"][i][1].real) + " " + str(m["S12"][i][1].imag) + " " + str(m["S22"][i][1].real) + " " + str(m["S22"][i][1].imag) + "\n") + f.close() # zip and delete uncompressed shutil.make_archive(args.directory + "/" + libreCAL_serial, 'zip', args.directory + "/" + libreCAL_serial) shutil.rmtree(args.directory + "/" + libreCAL_serial) diff --git a/Software/Scripts/FactoryCoefficients/limits.json b/Software/Scripts/FactoryCoefficients/limits.json index 4f05ece..57a718b 100644 --- a/Software/Scripts/FactoryCoefficients/limits.json +++ b/Software/Scripts/FactoryCoefficients/limits.json @@ -84,9 +84,9 @@ }, { "x1": 9000, - "y1": 150.0, + "y1": 140.0, "x2": 6000000000, - "y2": 150.0, + "y2": 140.0, "limit": "min", "type": "phase" } diff --git a/Software/Scripts/libreCAL.py b/Software/Scripts/libreCAL.py index 33cf78a..b24fba6 100644 --- a/Software/Scripts/libreCAL.py +++ b/Software/Scripts/libreCAL.py @@ -1,6 +1,7 @@ import serial import serial.tools.list_ports from enum import Enum +import datetime class libreCAL: def __init__(self, serialnum = ''): @@ -77,6 +78,33 @@ def getDateTimeUTC(self): def setDateTimeUTC(self, date_time_utc): return self.SCPICommand(":DATE_TIME "+ date_time_utc) + + def setDateTimeNow(self): + dt = datetime.datetime.now() + # get current time in UTC + now_utc = datetime.datetime.utcnow() + + # get UTC offset + utc_offset = dt - now_utc + + # calculate offset in hours and minutes + offset_seconds = int(utc_offset.total_seconds()) + offset_hours = abs(offset_seconds // 3600) + offset_minutes = abs((offset_seconds // 60) % 60) + + if offset_seconds < 0: + sign = "-" + else: + sign = "+" + + offset_str = f"{sign}{offset_hours:02d}:{offset_minutes:02d}" + + # format datetime as string + dt_str = dt.strftime("%Y/%m/%d %H:%M:%S") + + # add UTC offset to string + dt_str_with_offset = f"{dt_str} UTC{offset_str}" + self.setDateTimeUTC(dr_str_with_offset) def SCPICommand(self, cmd: str) -> str: self.ser.write((cmd+"\r\n").encode())