@attila Yea my scripts essentially redo the acquisition if samples are lost or corrupted, so the data that is saved and plotted is only when no error messages are produced. I have pasted in snippets from my code which includes the parts needed to understand the acquisition I perform. I want to re-state that the issues only occur on linux machines :)
Also I guess the acquisition is not triggered as I may have said earlier. Recording is initiated when configured in the script, and it triggers the AWG to transmit (no issues here). In the images I attached previously, I just set it to do the acquisition like this and record 10000-16000 samples based on changing the fs and range parameter.
Here is the main loop snippet which calls the record function and only plots data if the acquisition is without any error codes:
### Echosounder acquisition ###
fs = 2.5e6
Range = 5 ## Meter range
c = 1500 # Speed of sound
SampleTime = Range*2.0/c # How long should we sample for to cover range
nSamples = int(fs*SampleTime) # Number og samples to acquire/record per ping
tVec = np.linspace(0, SampleTime, nSamples) ## For plotting samples vs time of returned echo
### Enable both scope channels and set voltage range ##
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True))
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5))
### Set AD2 to record mode, unsure about buffer size ###
dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(50000))
### Set sampling frequency ###
dwf.FDwfAnalogInFrequencySet(hdwf, c_double(fs))
set_fs = c_double()
dwf.FDwfAnalogInFrequencyGet(hdwf, byref(set_fs))
print("Set fs:", set_fs.value)
# Wait at least 2 seconds for offset to stabilize
time.sleep(2)
sLost = 1
sCorrupted = 1
while sLost or sCorrupted == 1:
''' Sampling data (removed some communication-parts here for simplicity'''
CH1_Samples, CH2_Samples, sLost, sCorrupted = sampleData(dwf, hdwf, nSamples)
print("sLost = ", sLost, "sCorrupted = ", sCorrupted)
szerr = create_string_buffer(512)
err = create_string_buffer(512)
dwf.FDwfGetLastError(err)
dwf.FDwfGetLastErrorMsg(szerr)
print("Error:", str(szerr.value))
print("Errorcode:", str(err.value))
#Signal processing and plotting raw data only if no errors have happened during acquisition
Here is the recording loop:
def sampleData(dwf, hdwf, nSamples):
''' Samples N samples from the two scope channels
on the AD2. Returns arrays with samples
and error messages (sLost / sCorrupted).
'''
CH1_Samples = (c_double*nSamples)()
CH2_Samples = (c_double*nSamples)()
# Variables
cAvailable = c_int()
cCorrupted = c_int()
cSamples = 0
fLost = 0
fCorrupted = 0
# Configure scope chanels (Starts acquisition)
dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1)) ## Begins data acquisition and initiates the Analog Out to transmit 1 pulse
sts = c_int()
while cSamples < nSamples:
dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) ## Check state, read data
if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
print("Acquisition not started")
continue
dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted)) ## Read status
cSamples += cLost.value
if cLost.value :
fLost = 1
if cCorrupted.value :
fCorrupted = 1
if cAvailable.value==0 :
continue
if cSamples+cAvailable.value > nSamples :
cAvailable = c_int(nSamples-cSamples)
# Get samples from AD2 and store in array
dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(CH1_Samples, sizeof(c_double)*cSamples), cAvailable) # Get Channel 1 data
dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(CH2_Samples, sizeof(c_double)*cSamples), cAvailable) # Get Channel 2 data
cSamples += cAvailable.value
if fLost:
print("Samples were lost! Reduce sampling frequency or optimize loop.")
if fCorrupted:
print("Samples could be corrupted! Reduce sampling frequency or optimize loop.")
return np.array(CH1_Samples), np.array(CH2_Samples), fLost, fCorrupted