Skip to content

Instantly share code, notes, and snippets.

@pklaus
Last active August 29, 2015 13:57
Show Gist options
  • Save pklaus/9413980 to your computer and use it in GitHub Desktop.
Save pklaus/9413980 to your computer and use it in GitHub Desktop.
Python script to communicate with the Digital Multimeters Agilent U1253A / U1272A / U1273A originally found on http://goo.gl/Gycv9H
#!/usr/bin/env python
# Python script to communicate with the
# Agilent U1253A / U1272A / U1273A etc.
# found originally on http://goo.gl/Gycv9H
# For more information on the protocol, check
# http://blog.philippklaus.de/2014/02/agilent-u1273a/
# and http://goo.gl/oIJi96
import sys
import time
import serial
def init_meter(com_port):
global meter
print('meter, starting open:')
meter = serial.Serial(com_port, 9600, timeout=.1)
time.sleep(1)
print('meter, done open')
print(meter)
print('meter, reseting meter:')
meter.write("RST\n")
time.sleep(0.25)
response = meter.read(100)
print(response)
print('meter, identifying meter:')
meter.write("*IDN?\n")
time.sleep(0.25)
response = meter.read(100)
print(response)
print('meter, Battery:')
meter.write("SYST:BATT?\n")
time.sleep(0.25)
response = meter.read(100)
print(response)
print('meter, Config:')
meter.write("CONF?\n")
time.sleep(0.25)
response = meter.read(100)
print(response)
return
def read_meter(second='no'):
global meter
if second != 'yes' :
#print ('not in second')
meter.write("FETC?\n")
else :
#print ('yes in second')
meter.write("FETC? @2\n")
#time.sleep(0.05)
responsestr = meter.read(17)
#print ('>' + responsestr + '<', len(responsestr))
response = float(responsestr)
return response
def close_meter():
global meter
print('meter, starting close')
print(meter)
meter.close()
print('meter, closed')
return meter
if __name__=='__main__':
try:
meter = sys.argv[1]
except:
print('Please provide device as first argument. Exiting.')
sys.exit(2)
init_meter(meter)
for i in range(100):
primaryValue = read_meter()
secondaryValue = read_meter(second='yes')
#time.sleep(0.1)
print('count:' , i, "{:10.4f}".format(primaryValue), "{:10.4f}".format(secondaryValue))
close_meter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment