Mark Clowes (38M 🇬🇧)
Index - Agilent 34401A RS232
2021-02-25I had need to poll data from an Agilent 34401A Digital Multimeter, so I wrote this quick Python3 script to do so. It requires pyserial.
import serial
import time
ser = serial.Serial('COM4', 9600, parity=serial.PARITY_EVEN, bytesize=7, stopbits=2)
print("Sending IDN command")
ser.write(b'*IDN?\n')
print("Response:")
print(ser.readline())
time.sleep(1)
print("Putting DVM in remote mode")
ser.write(b'SYST:REM\n')
print("DC measurements:")
while True:
time.sleep(1)
ser.write(b':meas:volt:dc?\n')
dc = float(ser.readline())
print("%.5f" % dc)
Output:
Sending IDN command
Response:
b'HEWLETT-PACKARD,34401A,0,11-5-2\r\n'
Putting DVM in remote mode
DC measurements:
-0.00002
-0.00002
-0.00004
-0.00003
The '*IDN?' command is an identity request. Then the 'SYST:REM' command puts the device into remote mode. ':meas:volt:dc?' requests the current DC measurement. We poll this once a second and output to the screen formatted to 5 decimal places.
When testing via putty note that you need to use Ctrl-J to send line-feed only after each command.
I'm not sure if the serial settings are the defaults for the device. To connect to a PC you must use a null-modem cable. I used a regular DB9 serial cable, a null-modem adaptor and a gender changer.