Skip to content

Instantly share code, notes, and snippets.

@aewallin
Created June 18, 2019 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aewallin/cd13121f89b2d4d04dc011113b686d17 to your computer and use it in GitHub Desktop.
Save aewallin/cd13121f89b2d4d04dc011113b686d17 to your computer and use it in GitHub Desktop.
# simple script for reading Keysight 53230A counter
import vxi11 # https://pypi.org/project/python-vxi11/
import time
import datetime
import pytz
instr1 = vxi11.Instrument("194.100.49.155") # lower counter
init_commands = ["*RST",
"SYST:TIM 5.0",
"CONF:TINT (@1), (@2)", # REVERSE!
"SAMP:COUN 1", "TRIG:COUN 1",
#"CONF:FREQ (@1)",
"INP1:SLOP POS", "INP2:SLOP POS",
"INP1:LEV:AUTO OFF", "INP2:LEV:AUTO OFF",
"INP1:LEV1 1.0",
"INP2:LEV1 0.2", # uBlox low amplitude pulse!
"INP1:IMP 50", # 1M
"INP2:IMP 50",
"INP1:COUP DC",
"INP2:COUP DC",
"INIT:IMM"]
# initialization commands
for cmd in init_commands:
instr1.write(cmd)
print cmd
time.sleep(0.3)
# TCPIP::A-53230A-00151::inst0::INSTR
#instr.unlock()
#print(instr.ask(":READ?"))
def query(instr,cmd, sleep=0, length=100):
reply = ""
try:
instr.write(cmd)
time.sleep(sleep)
reply = instr.read()
except:
pass
return reply
def append_datarow(dt, row):
"""
Write a new data-row to the text file.
One file per day
"""
fname = "data/my_data_%04d-%02d-%02d.txt" % (dt.year, dt.month, dt.day)
print fname
with open(fname, 'a+') as f:
f.write(row)
f.flush()
def num_pts(instr):
return int( query(instr, ":DATA:POINTS?") )
while True:
utc_t = time.time()
r1 = " "
try:
r1 = instr1.ask( "READ?")
except:
pass
dt = datetime.datetime.fromtimestamp(utc_t, tz=pytz.UTC)
tstamp = "%04d-%02d-%02d %02d:%02d:%02d" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
datastring = "%s %s " %(tstamp, r1)
datastring += "\n"
print datastring
append_datarow(dt, datastring)
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment