I need help in understanding the code of reading and processing pulse data on python using dll file. I have used march.dll file for hantek 6022be. I do not understand why the samples read from channel 1 are divided by 12 and then the how the trigger value is set to determine if a pulse is found or not.
The code is pasted below. Your help will be appreciated.
def read_hantek():
dll.dsoReadHardData(m_nDevIndex, # index
pCH1Data, # ch1 data
pCH2Data, # ch2 data
nReadLen, # read len
m_nCalData, # cal data
m_nCH1VoltDIV, # ch1 volt div
m_nCH2VoltDIV, # ch2 volt div
0, # trig mode
0, # trig source
20, # trig level
0, # trig slope
m_nTimeDIV, # time div
0, # horizontal trig pos
nReadLen, # draw len
ctypes.byref(nTrigPoint), # trig index
0 # insert mode
)
data = [] #data array
sample1=[] #sample1 array
for sample in pCH1Data:
data.append((sample/12.0))
#print("Data: ", data, "\nLength: ", len(data))
print("\nLengthdata: ", len(data))
#"Data: ", data ,
print("Sample: ",sample)
return data
def process_pulse_data(data):
avg = sum(data) / len(data) # get the averge of data samples from scope
maxv = max(data) # get the maximum peak of data
trig = maxv / 1.5 # set trigger value to be max/1.5
pfound = 0
pidx = round(len(data)/2) # if len of data = 600, then pidx = 300
for idx, sample in enumerate(data): # idx = index, sample is the array value at the index
if sample > trig: # if sample is greater than the set trigger
pavg = sum(data[idx+4:idx+8]) / 4 #1 calculate pavg for 4 points. These will be calculated 4 points after
#2 the current index to avoid glitches. e.g if index (idx) value is at 4
#3 then pavg will be calculated for samples from indices 8 till 12.
if pavg > trig: # if pavg is greater than trigger
print (pavg) # print pavg
pfound = 1 # pulse found
pidx = idx #1 set pidx (pulse index) to current idex value e.g if current index (idx) value is
print("pidx: ",pidx) #2 at 4 then pidx will be 4
break # break the loop
x1 = 0 if pidx - 200 < 0 else pidx - 200 # x1 is zero if pidx -200 is less than 0 otherwise it will be pidx-200 //why 200 ??
x2 = len(data) - 1 if pidx + 200 > len(data) - 1 else pidx + 200 # x2 is len(data) -1 if pidx +200 is greater than the length of data else it will be pidx + 200 // why 200 ??
print("x1: ",x1)
print("x2: ",x2)
pdata = data[x1:x2] # length of data from valid pulse till the end
print("\nlength: ",len(pdata))
#"pdata",pdata,"
pavg = pavg if pfound else 0 # pavg is pavg if pulse was found otherwise it will be zero
return pfound, pdata, pavg