• 0

Implementin Record in Python




I am implementing an application to continuously streaming samples from the Digilent2 oscilloscope to the hard drive. I have missing samples at each buffer read. See image in the attachment. Buffer size is 4000.

In the Wavefrom SDK the needed mode is working fine.

My signal has max. Frequency of 1200Hz. Therefore, a sample rate of 12k/s would be sufficient. 

Can you please give some hints, how to configure this use case?

dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(config["buffer"]["sample rate"])))
    dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(config["buffer"]["sample rate"])))
    dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(bufferSize)) 
    if rgdCh1 is not None:
        dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) # Enable channel
        dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(int(config["discovery2"]["oscilloscope"]["ch1"]["range"]))) 
        dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(0), c_double(float(config["discovery2"]["oscilloscope"]["ch1"]["offset"])))
        dwf.FDwfAnalogInChannelFilterSet(hdwf, c_int(0), config["discovery2"]["oscilloscope"]["ch1"]["filter"]) 
    if rgdCh2 is not None:
        dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_bool(True)) # Enable channel
        dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(int(config["discovery2"]["oscilloscope"]["ch2"]["range"]))) 
        dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(1), c_double(float(config["discovery2"]["oscilloscope"]["ch2"]["offset"])))
        dwf.FDwfAnalogInChannelFilterSet(hdwf, c_int(1), config["discovery2"]["oscilloscope"]["ch2"]["filter"]) 
    #wait at least 2 seconds for the offset to stabilize
    dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1))
    dataLost = c_int(0)
    dataCorrupted = c_int(0)
    dataAviable = c_int(0)
    screenTime = datetime.datetime.now()
    startTime = 0
    duration = 0

    newDataCh1 = False
    newDataCh2 = False
    while True:
            # This block must be as fast as possible
            dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
            if sts.value == DwfStateDone.value :
                if rgdCh1 is not None:
                    dwf.FDwfAnalogInStatusData(hdwf, 0, rgdCh1.ctypes.data_as(c_void_p), bufferSize) # get channel 1 data
                    newDataCh1 = True
                if rgdCh2 is not None:     
                    dwf.FDwfAnalogInStatusData(hdwf, 0, rgdCh2.ctypes.data_as(c_void_p), bufferSize) # get channel 1 data
                    newDataCh2 = True 
                d = None
                if newDataCh1 and newDataCh2:
                    d = np.vstack([rgdCh1, rgdCh2]).T
                elif newDataCh1:
                    d = rgdCh1.T
                elif newDataCh2:
                    d = rgdCh2.T

                if newDataCh1 or newDataCh2:
                    newDataCh1 = False
                    newDataCh2 = False
                        newData = False
                    except Exception as e: 
                        print("ERROR: buffer.append " + str(e))
                        logging.error(str(e), exc_info=True)
                elif (datetime.datetime.now() - screenTime).total_seconds() > 1:
                    statistics = buffer.getStatistics()
                    status = "--- DIGILENT Oscilloscope ---"  + "\n"
                    status = status + "save in: ", buffer.getStoragePath() + "\n"
                    status = buffer.getTimestamp()[:19] + "\n"
                    status = status + "total files: " + str(statistics["total files"]) + "\n"
                    status = status + "total samples: " + str(statistics["total_samples"]) + "\n"
                    status = status + "samples lost: " + str(statistics["samples_lost"]) + "\n"
                    status = status + "Max. write time: " + "{:.0f}".format(statistics["Max. write time"]) + "ms\n"
                    status = status + "Avg. write rate: " + "{:.0f}".format(statistics["Avg. data rate"]/(1024.0 ** 2)*3600) + "Mbyte/hour\n\n" 

                    status = status + "Terminate with Ctrl. C"
                    print(status, flush=True)
                    #print("dataLost={}, dataCorrupted={}".format(dataLost, dataLost))
                    screenTime = datetime.datetime.now()
        except KeyboardInterrupt: # Hit Control-C
        except Exception as e: 
            print("Application crashed: " + str(e))
            logging.critical("Application crashed: " + str(e), exc_info=True)



Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now