Skip to content

Commit

Permalink
factory calibration script improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Nov 1, 2024
1 parent 2b0e889 commit de654e8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Software/Scripts/FactoryCoefficients/limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
},
{
"x1": 9000,
"y1": 150.0,
"y1": 140.0,
"x2": 6000000000,
"y2": 150.0,
"y2": 140.0,
"limit": "min",
"type": "phase"
}
Expand Down
28 changes: 28 additions & 0 deletions Software/Scripts/libreCAL.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import serial
import serial.tools.list_ports
from enum import Enum
import datetime

class libreCAL:
def __init__(self, serialnum = ''):
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit de654e8

Please sign in to comment.