Jump to content
  • 0

Need to pull timestamp info from o-scope


jeason15

Question

I am trying to get time-series data from the scope function on 2 channels at once at 2 MHz for a long period of time (think minutes to hours). Using waveforms, I can only get about 8 seconds of data, so I have taken to writing a python script that will do this for me. I have used the sample scripts in the SDK as a guide, but I am having trouble getting a timestamp. This is necessary as it will allow me to validate that I am capturing the data at the correct frequency. The documentation with the SDK doesn't give a great idea about what is returned and what I have so far is basically from using the samples and doing some serious trial and error. I know that once i find the timestamp info in the sample data I will need to add a value to my csv file, but I am having trouble even getting access to the data I need.  

I have inserted some of the code that I am running below so you can see what I am doing. Can someone please take a look and try to point me in the correct direction? thanks! 

 

#declare ctype variables
hdwf = c_int()
sts = c_byte()
rgSamples1 = (c_double*4000)()
rgSamples2 = (c_double*4000)()

version = create_string_buffer(16)
dwf.FDwfGetVersion(version)

#open device
print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

if hdwf.value == hdwfNone.value:
    szerr = create_string_buffer(512)
    dwf.FDwfGetLastErrorMsg(szerr)
    print(szerr.value)
    print("failed to open device")
    quit()

cBufMax = c_int()
dwf.FDwfAnalogInBufferSizeInfo(hdwf, 0, byref(cBufMax)) 

#set up acquisition
dwf.FDwfAnalogInFrequencySet(hdwf, c_double(2000000.0))
dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(4000)) 
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True))
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5))
dwf.FDwfAnalogInChannelFilterSet(hdwf, c_int(-1), filterDecimate)

#wait at least 2 seconds for the offset to stabilize
time.sleep(2)

print("Starting oscilloscope")
dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1))

created = False

runtime = int(input("how many seconds do you want to capture for? "))
starttime = time.time()
i = 0
while (time.time() - starttime) < runtime:
    while True:
        dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
        if sts.value == DwfStateDone.value :
            break

    dwf.FDwfAnalogInStatusData(hdwf, 0, rgSamples1, 4000) # get channel 1 data
    dwf.FDwfAnalogInStatusData(hdwf, 1, rgSamples2, 4000) # get channel 2 data
    dwf.FDwfDeviceCloseAll()

    if not created:
        f = open("record.csv", "w")
        f.write("hi, lo\n")
        for v in rgSamples1:
            f.write(repr(rgSamples1[i]) + "," + repr(rgSamples2[i]) + "," + "\n")
        f.close()
        created = True
    else:
        f = open("record.csv", "a")
        for v in rgSamples1:
            f.write(repr(rgSamples1[i]) + "," + repr(rgSamples2[i]) + "," + "\n")
        f.close()
    i += 1

dwf.FDwfAnalogOutReset(hdwf, c_int(-1))
dwf.FDwfDeviceCloseAll()
currtime = time.time()
overall = currtime-starttime
print("Device reset and closed")
print("Your capture has completed in " + str(round(overall, 2)) + " seconds")

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

That is where I got the sample code that I provided. From what I can tell from the documentation and looking at the source code for the dwf sdk, the time stamp information is not contained in the object that is returned by the FDwfAnalogInStatusData() method. In my sample above, rgSamples is an array of voltage information.

Link to comment
Share on other sites

Hi @jeason15

There is no time-stamp returned by the library.

The code you posted performs separate captures of 4k samples. Also notice that you are writing in the file the same sample 4k times... "for v in rgSamples1: f.write(repr(rgSamples1) ... i+=1
In case you want longer continuous capture, at up to ~1MHz, see the record examples.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...