I’m using Agilent DMM in order to measure.
I communicate with it using Python 2.7 and PySerial module.
The idea: using a FOR loop, I read from the DMM and get data.
It is working fine until some point, each time a different point.
for example: If I set the loop to measure 20k times, it suddenly stops after 1k times, next try it might stop after 5k times….
stops – means that the DMM stops send data and python remains in a kind of waiting state. My scripts gets stuck and I have to terminate it. There is no error and I have no idea why.
I tried adding timeouts (Sleep) between measurements and it sis not solve the problem.
Here are the main commands in my scripts:
# configure the serial connections
ser = serial.Serial(
port='com3',
baudrate=19200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
}
ser.write("CONF:CURRent:DC" + '\r\n')
time.sleep(1)
ser.write("SENS:CURR:DC:RANGe:UPP 0.05" + '\r\n')
time.sleep(1.5)
for m in range (0, 2000):
try:
ser.write('READ?' + '\r\n')
out += ser.read(18)
print "out = ",out
except:
print "error!"
The loop is running, sometimes it “survive” till the end but most of the times it just stops, please advice. Please note that I never get into the “except” part. adding “try” was not helping…
Thank you!
~ Dolphin ~
You can set a timeout when you are creating
serial.Serialobject. There are 2 parameters for specifying read and write timeouts. Here is an example:Here is what documentation says about the values a these parameters can take: