01-09-2023 03:50 AM
Hello everyone,
With a customer requesting last Wednesday to review about 800 hundreds TDMS files for last Friday morning (yes, I'm already late), I decided to take a chance with VBS in DIAdem, although I knew nothing.
I manage to create a script that goes through a selected folder, reads each TDMS file, writes the file name in a txt file, calculate the mean value of a channel, writes this value in the txt file and moves the tdms file after reading.
But, and that's where I'm struggling, I have to calculate the mean value ONLY for the line where an other channel is set at "1".
To be more explicit, the files are created by a braking testbench. I have, to be short, 3 important channels : time, braking_pressure and active_braking.
I need to calculate the mean braking pressure value only when braking is active.
I have the intuition that is could be something like :
"for each line of the file
if active_braking = 1 then
store the braking_pressure in an array
end if
calculate the mean value of the array"
I could use some help with this topic.
You can find attached the script as it is by now.
Thank you !!
JC
Solved! Go to Solution.
01-10-2023 12:58 AM
Hi JCERRO_CETIM,
For such calculation you can use the channel event functions in DIAdem:
You define a window where the active_braking channel is 1 or higher
and calculate the mean at this areas for the braking-preasure channel
With CTRL+SHIFT+C you can copy the script commands to the clipboard. Also the DIAdem help provides more small examples using a command as keyword.
The example is attached.
Greetings
Walter
01-10-2023 02:04 AM
Hi Walter_Rick,
Thank you for your answer !
I did not know (I said I was new at DIAdem and VBS) that you could use built-in tools to create piece of code !
I however managed to find a solution on my own 😉
I used an array to store the data line by line if the condition is fullfilled :
nbr_point = 0
overall_pressure = 0
set voie_pression = data.GetChannel("[1]/FREINAGE_CP1")
set voie_active_freinage = data.GetChannel("[1]/ACTIVE_FREINAGE")
channel_size = voie_pression.Size
do while i <= channel_size
if voie_active_freinage.Values(i) = 1 then
'redim preserve freinage_active(ubound(freinage_active)+1)
'freinage_active(ubound(freinage_active))=voie_pression.Values(i)
overall_pressure = overall_pressure + voie_pression.Values(i)
nbr_point = nbr_point+1
end if
i=i+1
loop
average = overall_pressure/nbr_point
Thank you 🙂
I did not coded since the end of enginering school, it was fun !
01-10-2023 02:28 AM
Hi JCERRO_CETIM,
Of course you can define or develop this by your own. That is always possible. However our experience is that a) own developed script code is typically slower (this is because it is running in VBS) and b) you must maintain this script code yourself.
In anyway, it is important to have a solution.
Greetings
Walter