Compare commits

...

2 commits

Author SHA1 Message Date
Stephan I. Böttcher
ca3ca91991 cvphase.py: script to measure C-V curves 2025-05-08 13:29:01 +02:00
Stephan I. Böttcher
560749a95f agilent3322A: verbosity 2025-05-08 13:28:18 +02:00
3 changed files with 113 additions and 1 deletions

View file

@ -2,6 +2,9 @@
import sys, socket
class pulser:
verbosity = 1
def __init__(self, host=("172.19.71.137", 5025)):
if isinstance(host, str):
hh=host.split(":")
@ -25,6 +28,8 @@ class pulser:
self.resp()
self.write(cmd)
return self.resp(cmd, timeout=timeout).strip()
if self.verbosity >= 1:
print(f"{self.prompt}: {cmd}", file=sys.stderr)
self.write(cmd)
return self.status()
@ -47,7 +52,8 @@ class pulser:
d=repr(e)
if not d:
return ""
sys.stderr.write("\n%s: %s: %s\n" % (self.prompt, cmd, d.strip()))
if self.verbosity >= 2 or not "No error" in d and self.verbosity >= 1:
print(f"{self.prompt}: {cmd}: {d.strip()}", file=sys.stderr)
return d
def status(self):
@ -58,3 +64,7 @@ class pulser:
return self.cmd("VOLTAGE:HIGH?")
return self.cmd("VOLTAGE:HIGH %g" % v)
def set_freq(self, v=None):
if v is None:
return self.cmd("FREQ?")
return self.cmd(f"FREQ {v:g}")

66
cvphase.py Executable file
View file

@ -0,0 +1,66 @@
#! /usr/bin/python3
import sys, time, agilent3322A, tds3034c, getopt
fmin=400
fmax=1500
fres=1.0
i_phi = 3
t_phi = 45.0
t_settle = 10
units = False
verbosity = 1
def usage():
print(f"""{sys.argv[0]} <options>
-f min,max default: {fmin},{fmax} Hz
-r res default: {fres} Hz
""", file=sys.stderr)
options,files = getopt.getopt(sys.argv[1:], "f:r:qvhu:", ["help"])
if files:
raise ValueError("we do not use filenames")
for o, v in options:
if o=="-f":
fmin, fmax = map(float, v.split(","))
if o=="-r":
fres = float(v)
if o=="-q":
verbosity=0
if o=="-v":
verbosity += 1
if v == "-u":
units = True
if o=="-h" or o=="--help":
usage()
sys.exit()
pulser = agilent3322A.pulser()
tek = tds3034c.tek()
pulser.verbosity = verbosity
tek.verbosity = verbosity
while fmin + fres < fmax:
f = (fmin + fmax)/2
pulser.cmd(f"FREQ {f:.1f}")
tek.cmd("ACQ:NUMAVG 512")
t = time.time() + t_settle
phi = tek.cmd(f":MEASU:MEAS{i_phi}:VAL?")[1]
while (time.time() < t):
time.sleep(1)
phi = tek.cmd(f":MEASU:MEAS{i_phi}:VAL?")[1]
if phi > t_phi:
fmax = f
else:
fmin = f
r = []
for i in range(1,5):
r.append(tek.cmd(f":MEASU:MEAS{i}:VAL?")[1])
if units:
r.append(tek.cmd(f":MEASU:MEAS{i}:UNI?")[1])
print(f"{f:.1f}", *r)

36
tds3034c.py Normal file
View file

@ -0,0 +1,36 @@
import sys, http.client
class tek(http.client.HTTPConnection):
verbosity = 1
def __init__(self, host="172.19.71.101"):
super().__init__(host)
self.cmd("*IDN?")
def cmd(self, c):
self.request(method="POST" , url="/Comm.html", body=f"COMMAND={c}")
r = self.getresponse()
try:
data = r.read()
except http.client.IncompleteRead as e:
data = e.args[0]
data = data.split(b'NAME="name">')[1].split(b'</TEXTAREA>')[0].split(b' ')
if self.verbosity >= 1:
print(f"tek.cmd('{c}') = {data}", file=sys.stderr)
s = None
if len(data) > 1:
s = data[1].strip(b'"')
if s == data[1]:
try:
s = int(s)
except:
try:
s = float(s)
except:
pass
else:
s = s.decode()
return data[0].decode(), s