DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing calculated results always in the same file (.tdms, .xls or .csv file)

Hello,

 

i struggle with the following problem.

I use a script, were i can open numerous files, calculating the peak values of a certain channel and saves the evaluated file again:

 

Option Explicit
Dim i
If FileDlgShow(DataReadPath,"TDM Files,*.tdm","DataSelection",True) = "IDOk" Then
For i = 0 to UBound(FileDlgNameList)
Call Data.Root.Clear()
Call DataFileLoad(FileDlgNameList(i),"TDM","Load")
Set ChnResult = ChnPeakDetect("[1]/valve_current_filt", "[1]/hysteresis", "/Position", "/Amplitude", "Peaks", 0, 3)
Call DataFileSave("Serie_"&str(i),"TDM")
Next
End If

 

Is there a chance to write the results (X- and Y-Values) in always the same file?

Thank you very much

 

best regards,

Udo 

0 Kudos
Message 1 of 2
(1,200 Views)

My understand of your question is that after you execute ChnPeakDetect() and the two new channels are created, you want to update the same file with the new channel data (not create a new file).  The example below is a solution to that problem.

 

Spoiler

Dim oChnX, oChnY, oChnPeakX, oChnPeakY
'Get some data and save it to a new file
Call Data.Root.Clear()
'DataReadPath = C:\Users\Public\Documents\National Instruments\DIAdem 2021\Data\
If FileExist(DataReadPath & "ChnPeakDetect_SourceData.tdm") Then Call FileDelete(DataReadPath & "ChnPeakDetect_SourceData.tdm")
Call DataFileLoadSel(DataReadPath & "Example.tdms", "TDMS", "[1]/Time|[1]/Speed")
Call DataFileSave(DataReadPath & "ChnPeakDetect_SourceData.tdm", "TDM")
Call Data.Root.Clear()

'Load the new data file, assign channel variables, execute ChnPeakDetect(), save the file
Call DataFileLoad(DataReadPath & "ChnPeakDetect_SourceData.tdm", "TDM", "Load")
'Call ChnPeakDetect("[1]/Time", "[1]/Speed", "/SpeedPeakX", "/SpeedPeakY", "Peaks", 0, 3)
Set oChnX = Data.Root.ChannelGroups(1).Channels("Time")
Set oChnY = Data.Root.ChannelGroups(1).Channels("Speed")
Set oChnPeakX = Data.Root.ChannelGroups(1).Channels.Add("SpeedPeakX",DataTypeChnFloat64)
Set oChnPeakY = Data.Root.ChannelGroups(1).Channels.Add("SpeedPeakY",DataTypeChnFloat64)
Call ChnPeakDetect(oChnX, oChnY, oChnPeakX, oChnPeakY, "Peaks", 0, 3)
Call DataFileSave(DataReadPath & "ChnPeakDetect_SourceData.tdm", "TDM")

So the modification to your original code would be:

 

Spoiler
Dim i
If FileDlgShow(DataReadPath,"TDM Files,*.tdm","DataSelection",True) = "IDOk" Then
For i = 0 to UBound(FileDlgNameList)
Call Data.Root.Clear()
Call DataFileLoad(FileDlgNameList(i),"TDM","Load")
Set ChnResult = ChnPeakDetect("[1]/valve_current_filt", "[1]/hysteresis", "/Position", "/Amplitude", "Peaks", 0, 3)
Call DataFileSave(FileDlgNameList(i),"TDM")
Next
End If
0 Kudos
Message 2 of 2
(1,143 Views)