DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

chdx + ChnNovHandle -> only working on the third call?

Hi,
 
I'm trying to reduce the amount of values of a digital channel, recorded with a high sampling rate. Values are either 0 or 20.
 
1. I am setting all Values, where nothing happens, chdx(i,4) = NoValue.  (This part is working - at least it looks like so / even though some Members would probably suggest to use "IsNull")
2. Then delete the rows with ChnNovHandle.
 
Problem:
I have to call "ChnNovHandle" multiple times to make it work ! Why ? (Two times, sometimes three...)
First time nothing happens? Or can't I see it, do I need another page refresh than "call ChnCharacterAll "
Sometimes I do have the impression as if I had to wait some longer to make "ChnNovHandle" work.
 
When changing to chd(i,4) = NoValue instead of "chdx" calculating takes much longer but  "ChnNovHandle"  works on the first go.
 
Can someone show me the point I am missing?
 
Laenge=CL("Zeitkanal DIO")
'Call MsgBoxDisp ("Länge Zeitkanal : "&Laenge)        ' zur Überprüfung
call Schleife
call Schleife ' 3mal aufrufen, da beim ersten Mal "ChnNovHandle" nicht funktioniert  ?????!!!!!!!!
call Schleife ' 3mal aufrufen, da beim ersten Mal "ChnNovHandle" nicht funktioniert  ?????!!!!!!!!

Sub Schleife '--------------------------------------------------------------------------------------------
Check1 = True
Check2 = True
Check3 = True
Check4 = True
i=1
For i=1 to Laenge
    if chdx(i, 5) = chdx(i+1, 5) and (chdx(i, 5) = chdx(i-1, 5) or chdx(i-1, 5) = 9.9E+34) then          ' 9.9E+34 = NoValue
    check1 = True
    else
    check1 = False
    End if
.......
.......
.......
    if (check1 = True) and (check2 = True) and (check3 = True) and (check4 = True) Then
    chdx(i, 4) = NOVALUE                             ' Es reicht hier den Steuerkanal auf "Novalue" zu setzen - Ausgehend davon dann die ganze Zeile löschen !
    else
    End IF
next
call ChnNovHandle(4, "5-8", "Delete", "X", 1)
call ChnCharacterAll                                   ' aktualisieren der Kanal-Eigenschaften?
Laenge=CL("Zeitkanal DIO")
Call MsgBoxDisp ("Fertig : "&Laenge)        ' zur Überprüfung
End Sub 'Schleife --------------------------------------------------------------------------------------------
 
 
Thanks,
Frank
 
Windows XP, Diadem 8.1.1292
Attachment: Full Skrip and sample Data
0 Kudos
Message 1 of 5
(3,426 Views)

Hi Frank,

Your best bet is to use the Formula Calculator to run all these digital transition comparisons efficiently in C code rather than trying to do so in VBScript.  Try the below VBScript, which I got to work correctly with your data set, to see what I mean:

OPTION EXPLICIT

Dim i, DeltaThresh, TimeCh, DigChs, DeltaCh1, DeltaCh2, Length, NewTimeCh, NewDataCh
DeltaThresh = 10
TimeCh = "Zeitkanal DIO"
DigChs = Array("", "DO1", "DO2", "DI1", "DI2")
Call ChnCopy(TimeCh, "Delta")
DeltaCh1 = CNoXGet(GroupDefaultGet, GroupChnCount(GroupDefaultGet))
Call ChnCopy(TimeCh, "Delta")
DeltaCh2 = CNoXGet(GroupDefaultGet, GroupChnCount(GroupDefaultGet))
Length = ChnLength(TimeCh)
FOR i = 1 TO UBound(DigChs)
  Call GroupCreate(DigChs(i) & " Events")
  Call GroupDefaultSet(GroupCount)
  Call ChnDeltaCalc(DigChs(i), DeltaCh1)
  Call ChnAreaInsert0(DeltaCh1, 1, 1)
  ChDX(1, DeltaCh1) = ChDX(2, DeltaCh1)
  Call ChnDeltaCalc(DeltaCh1, DeltaCh2)
  ChnLength(DeltaCh2) = Length
  ChDX(Length, DeltaCh2) = ChDX(Length, DeltaCh2)
  L1 = DeltaCh1
  L2 = DeltaCh2
  L3 = CNo(DigChs(i))
  R1 = DeltaThresh
  Call ChnCopy(TimeCh, "NewTime")
  Call FormulaCalc("Ch('NewData'):= Ch(L3) + NoValue*((abs(Ch(L1))<R1) AND (abs(Ch(L2))<R1))")
  NewTimeCh = CNoXGet(GroupCount, 1) : ChnName(NewTimeCh) = ChnName(TimeCh)
  NewDataCh = CNoXGet(GroupCount, 2) : ChnName(NewDataCh) = ChnName(DigChs(i))
  ChDX(1, NewDataCh) = ChD(1, DigChs(i))
  ChD(Length, NewDataCh) = ChD(Length, DigChs(i))
  Call ChnNoVHandle(NewTimeCh, NewDataCh, "Delete", "XY", 1, 0)
NEXT ' i
Call ChnDel(DeltaCh2)
Call ChnDel(DeltaCh1)

Regards,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 5
(3,410 Views)
Hi Brad,
 
thanks for the fast response. This gives some interesting ideas to look at the problem.
Unfortunaly I can't  find some explanation for those expressions in the Help-Files. Where are they documented?
 
Now I', stuck with:
 
1. Error: Channel "delta" not defined.
-> Call ChnCopy(TimeCh, "Delta")
when creating some channel "delta", then:
 
2. Error: Variable not defined "GroupDefaultGet"
-> DeltaCh1 = CNoXGet(GroupDefaultGet, GroupChnCount(GroupDefaultGet))
 
Does it require some special feature in DIAdem 8.1? Some that i possibly have not installed?
 
Thanks,
Frank
 
0 Kudos
Message 3 of 5
(3,402 Views)

Hi Frank,

Sorry, I missed the "DIAdem 8.1" reference that you had in the footer of your email.  I had all kinds of functions in there that were added in DIadem 9.x or DIAdem 10.x.  I believe I now have them all rooted out and that the following will run in DIAdem 8.1:

OPTION EXPLICIT

Dim i, DeltaThresh, TimeCh, DigChs, DeltaCh1, DeltaCh2, Length, NewTimeCh, NewDataCh
DeltaThresh = 10
TimeCh = "Zeitkanal DIO"
DigChs = Array("", "DO1", "DO2", "DI1", "DI2")
L4 = CNo(TimeCh)
Call FormulaCalc("Ch('Delta1'):= Ch(L4)")
DeltaCh1 = CNo("Delta1")
Call FormulaCalc("Ch('Delta2'):= Ch(L4)")
DeltaCh2 = CNo("Delta2")
Length = ChnLength(TimeCh)
FOR i = 1 TO UBound(DigChs)
  Call ChnDeltaCalc(DigChs(i), DeltaCh1)
  Call ChnAreaInsert0(DeltaCh1, 1, 1)
  ChDX(1, DeltaCh1) = ChDX(2, DeltaCh1)
  Call ChnDeltaCalc(DeltaCh1, DeltaCh2)
  ChnLength(DeltaCh2) = Length
  ChDX(Length, DeltaCh2) = ChDX(Length, DeltaCh2)
  L1 = DeltaCh1
  L2 = DeltaCh2
  L3 = CNo(DigChs(i))
  R1 = DeltaThresh
  Call FormulaCalc("Ch('NewTime'):= Ch(L4)")
  Call FormulaCalc("Ch('NewData'):= Ch(L3) + NoValue*((abs(Ch(L1))<R1) AND (abs(Ch(L2))<R1))")
  NewTimeCh = CNo("NewTime") : ChnName(NewTimeCh) = ChnName(TimeCh) & " " & ChnName(DigChs(i)) & " Events"
  NewDataCh = CNo("NewData") : ChnName(NewDataCh) = ChnName(DigChs(i)) & " Events"
  ChDX(1, NewDataCh) = ChD(1, DigChs(i))
  ChD(Length, NewDataCh) = ChD(Length, DigChs(i))
  Call ChnNoVHandle(NewTimeCh, NewDataCh, "Delete", "XY", 1, 0)
NEXT ' i
Call ChnDel(DeltaCh2)
Call ChnDel(DeltaCh1)

Let me know if I missed one, I don't have DIAdem 8.1 here handy to test with,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

Message 4 of 5
(3,396 Views)

Thanks Brad, that worked fine with V8.1!

I still don't know why my approach needs two to three calls till it works, but this solution seems to work faster anyway. 🙂

Thanks,

Frank

 

 

 

0 Kudos
Message 5 of 5
(3,315 Views)