Showing results for 
Search instead for 
Did you mean: 

Script help

I am very new to coding and diadem so I was hoping for some help. I want to create a script that will call out a channel (i.e. motor speed) and create a lap counter. In my screenshot, every other point or flag is the point I want which is one lap. So when motor speed goes from negative to positive every other spot. Then place that in a table that I can copy to excel with the time stamp. Any help in this is appreciated. 

Diadem Script Help.PNG

0 Kudos
Message 1 of 4

Hi cjenks,


To detect the zero crossing, you can use the “Event Search” function





With these parameters




NoValues means that a certain marker – the NoValue – is set where the condition not fullfills.





To delete all NoValues you can use the function “Process NoValues”




With these parameters





The you need a for-loop the select every second value.


In the dialog you can use the short-key CTRL-SHIFT-C in each dialog to copy the necessary script commands into the clipboard and from there into the script editor (or use the “Recording Mode” of script). After that you must complete the script with the for-loop.


Here is the script.

' detect all zero crossings
ChnEventList1 = ChnEventDetectionSlope("[1]/Time", "[1]/Speed", 0, "increasing", 500)
Call ChnEventCreateStatusChn("/EventStatus", ChnEventList1, "[1]/Speed", NOVALUE, 1)

' remove NoValues
NovMeth          = "Delete"
NovCtrlChn       = "XY"
ChnNovIP         = False
NoVChnX          = False
NovReplaceVal    = 0
Call ChnNovHandle("[1]/EventStatus", "'[1]/Time'", "Delete", "XY", False, False, 0)

dim oChn, oResChn, iLoop, iIndex
set oChn    = Data.Root.ChannelGroups(1).Channels("Time1")
set oResChn = Data.Root.ChannelGroups(1).Channels.Add("Result", DataTypeChnFloat64)

' select every second value
iIndex = 0
for iLoop = 1 to oChn.Size step 2
  iIndex  = iIndex + 1
  oResChn(iIndex) = oChn(iLoop)




Message 2 of 4



I cant thank you enough. I really appreciate the thoughtful and helpful response. 

0 Kudos
Message 3 of 4

Wow Walter! That is a great way to get timestamps from an event search. I have a much more complicated way of doing it but this streamlines the process greatly. Thanks

0 Kudos
Message 4 of 4