Showing results for 
Search instead for 
Did you mean: 

Check condition on a trigger channel and fill channel gaps

Go to solution



I have a channel (BLS) with 1 and 0 values representing ON/OFF of a given phenomenon.

I want to use the information contained in this channel to split other channels that have the same size, but first I need to fill the "0 gaps" that lasted less than 2 seconds.

I wrote the following code, but it is not working (it seems like Diadem enters an infinite loop or something similar), how can I solve the issue?


Index1 = Find("Ch(""[1]/BLS"")>0")

For i = Index1 To Data.Root.ChannelGroups([1]).Channels("BLS").Size

  If Data.Root.ChannelGroups([1]).Channels("BLS").Values(i) = 0 Then

    Index1 = BrIndex1 + 1


    Index2 = Find("Ch(""[1]/BLS"")>0",Index1)

    Time1 = Data.Root.ChannelGroups([1]).Channels(TimeChn).Values(Index1)

    Time2 = Data.Root.ChannelGroups([1]).Channels(TimeChn).Values(Index2)

    if (Time2-Time1) <= 2 Then

       Data.Root.ChannelGroups(oGrName).Channels("BLS").Values(i) = 1

    End If

   End If



Is there a way to do the same operation in a smarter way, not involving the usage of a For cycle?


0 Kudos
Message 1 of 3

try Loggin i in the end of each loop.  I bet Index1 = BrIndex1 + 1is messing it up.  Where did BrIndex come from and what is it for?

0 Kudos
Message 2 of 3
Accepted by topic author mattia_verona
04-16-2019 02:16 AM

Hi, actually I managed it with an other loop, see my code below.


BrIndex1 = Find("Ch(""[1]/BLS"")=0",Find("Ch(""[1]/BLS"")>0"))

BrIndex2 = Find("Ch(""[1]/BLS"")>0",BrIndex1)



Do While (BrIndex1 < Data.Root.ChannelGroups(oGrName).Channels("BLS").Size) And (BrIndex2 < Data.Root.ChannelGroups(oGrName).Channels("BLS").Size) And IsNull(BrIndex1)=FALSE And IsNull(BrIndex2)=FALSE And BrIndex1<>0 And BrIndex2<>0

    Time1 = Data.Root.ChannelGroups(oGrName).Channels(TimeChn).Values(BrIndex1)

    Time2 = Data.Root.ChannelGroups(oGrName).Channels(TimeChn).Values(BrIndex2)

   if (Time2-Time1) <= TimeTolerance Then

      for i = BrIndex1 To BrIndex2

         Data.Root.ChannelGroups(oGrName).Channels("BLS").Values(i) = 1


   End If

    BrIndex1 = Find("Ch(""[1]/BLS"")=0",BrIndex2)

    BrIndex2 = Find("Ch(""[1]/BLS"")>0",BrIndex1)



0 Kudos
Message 3 of 3