Jump to content
  • 0

Using FDwfAnalogInStatusData16


Robert White

Question

Hi - I'm using ADP3250 in linux mode with most recent Waveforms SDK and python3.  Things are working great.  I want to write binary data to flash memory quickly.  I had my code working with the FDwfAnalogInStatusData function, but that was writing doubles (8 bytes?) for each sample, I thought it would be a little faster, and make smaller files, with no loss of precision if I had it write only the "raw" uint16 (2 bytes) per sample.  SO I tried the FDwfAnalogInStatusData16 function.

However the binary file contains only "null".  The code worked fine when using FDwfAnalogInStatusData, only changes were to change to FDwfAnalogInStatusData16 and change the type of the buffer array from c_double to c_uint16

Any ideas?? Thanks! 

from ctypes import *
from dwfconstants import *
from subprocess import call
import sys
import time

dwf = cdll.LoadLibrary("libdwf.so")
hdwf = c_int()  # device handle

rg = (c_uint16*nSamples)() #analog measurements

# open device
dwf.FDwfDeviceOpen(c_int(0), byref(hdwf))  # open first device

#I don't know what this does but many examples have it:
# 0 = the device will be configured only when calling FDwf?Configure
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))

#set up acquisition
nSamples = 32768
SampleRate=c_double(5000000)
dwf.FDwfAnalogInFrequencySet(hdwf,SampleRate)
dwf.FDwfAnalogInBufferSizeSet(hdwf, nSamples)
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_int(1)) #channel 1 enable
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(4)) # 4V pk2pk

time.sleep(2)

# wait at least 2 seconds for the offset to stabilize after the first connection
dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1)) #Update config and enable

writefile_binary=open(filename_data,'wb')

dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
while True:
    dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
    if sts.value == DwfStateDone.value :
       break
    time.sleep(0.001)
            
dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), rg, len(rg)) # get channel 1 data
writefile_binary.write(rg)

writefile_binary.close()
        dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), rg, len(rg)) # get channel 1 data
        writefile_binary.write(rg)


 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I found my error - FDwfAnalogInStatusData16 has an extra argument when compared to dwf.FDwfAnalogInStatusData.  Have to specify the starting sample. SO I just needed to add another c_int(0)

dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), c_int(0), rg, len(rg)) # get channel 1 data

Now it works.

Link to comment
Share on other sites

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
×
×
  • Create New...