Alright, here is some example logging code for use with Kst. There are a few variables at the top - file_name, sample_period, and sample_count - as well as the call to Python IVI to connect to the instrument. Configure these as necessary. This script does not actually configure the instrument for whatever measurement you need; all it does is read samples from a multimeter. So you can either configure the meter manually before starting the script, or you can add code after the ivi call to set up the measurement. The samples (along with a timestamp) are written to a csv file. Before starting, the script also writes out an xml file for Kst. Now, the XML file that it writes is a bit hacked together, I just saved one out of Kst and hen stripped out a bunch of stuff, so it might not be terribly ideal. But it worked for the limited testing I have done so far. To use this thing, start the script in python, then open up the generated .kst file in Kst. As the data is collected, Kst will automatically load and display the new data points. The script will stop automatically after collecting the specified number of samples. It should also stp if there is an error communicating with the instrument, or if the script is interrupted with ctrl c.
The timing loop is set up so that the script attempts to 'make up for lost time' if there is a mis-timed sample somewhere. However, I am not sure if the time calls will have the same resolution on all platforms.
import ivi
import time
dmm = ivi.agilent.agilent34401A("TCPIP::192.168.1.105::gpib,22::INSTR")
file_name = 'log'
sample_period = 2.0
sample_count = 100
fp = open(file_name '.csv', 'w')
kp = open(file_name '.kst', 'w')
kp.write("""<?xml version="1.0" encoding="UTF-8"?>
<kst version="2.0">
<data>
<source reader="ASCII file" file="{0}.csv">
<properties vector="INDEX" interpretation="1" delimiters="#" columntype="2" columndelimiter="," headerstart="1" fields="0" readfields="true" usedot="true" columnwidthisconst="false" readunits="false" units="0" limitFileBuffer="false" limitFileBufferSize="0" useThreads="0" asciiTimeFormat="hh:mm:ss.zzz" dataRate="1" offsetDateTime="false" offsetFileDate="false" offsetRelavive="true" dateTimeOffset="2014-03-24T22:16:59" relativeOffset="0"/>
</source>
</data>
<variables>
<datavector file="{0}.csv" field="time" start="0" count="15985" skip="-1" doAve="false" startUnits="" rangeUnits="" initialVNum="1" initialXNum="25"/>
<datavector file="{0}.csv" field="sample" start="0" count="15985" skip="-1" doAve="false" startUnits="" rangeUnits="" initialVNum="2" initialXNum="37"/>
</variables>
<objects/>
<relations>
<curve xvector="time (V1)" yvector="sample (V2)" color="#0000ff" headcolor="#008000" barfillcolor="#000000" haslines="true" linewidth="0" linestyle="0" haspoints="false" pointtype="3" pointdensity="0" pointsize="12" hasbars="false" ignoreautoscale="false" hashead="false" headtype="0" initialCNum="1"/>
</relations>
<graphics>
<view name="View &1" width="1470" height="633" color="#ffffff" style="1">
<plot tiedxzoom="false" tiedyzoom="false" leftlabelvisible="true" bottomlabelvisible="true" rightlabelvisible="true" toplabelvisible="true" globalfont="Sans,10,-1,5,50,0,0,0,0,0" globalfontscale="16" globalfontcolor="#000000" showlegend="true" hidebottomaxislabel="false" hidetopaxislabel="false" hideleftaxislabel="false" hiderightaxislabel="false" numberaxislabelscale="true" initialPlotNum="1" name="Plot">
<relativesize width="1" height="1" centerx="0.5" centery="0.5" posx="0" posy="0" leftx="0" lefty="1" rightx="1" righty="1" fixaspect="false" lockpostodata="false"/>
<cartesianrender name="Cartesian Plot" type="1">
<relation tag="sample vs time (C1)"/>
</cartesianrender>
</plot>
</view>
</graphics>
</kst>""".format(file_name))
kp.close()
fp.write("time, sample\n")
target_time = time.time() sample_period
for sample in range(sample_count):
last_sample_time = time.time()
sample_value = dmm.measurement.read(1)
print(sample_value)
fp.write("%f, %g\n" % (last_sample_time, sample_value))
fp.flush()
offset = target_time - time.time()
if offset > 0:
time.sleep(offset)
target_time = sample_period