DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

calling a variable inside a channel function

I'm having an issue where I am trying to do the same re sampling on the same channel's in multiple groups, all the naming is the same but I'm having trouble declaring a variable withing the channel re sample function, I believe it is just reading it as text and i'm not sure how to fix it. Also i'm attempting to make a new sheet in the view panel and having one named after each group of data.

my code:

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.

Dim i
For i = 1 to 30
Call Data.Root.ChannelGroups(i).Activate()

Call ChnResampleFreqBased("[i]/NoName","[i]/x final","/resampledX",0.3,"Automatic",0,0)
Call ChnResampleFreqBased("[i]/NoName","[i]/z final","/ResampledZ",0.3,"Automatic",0,0)
'how to change name of sheet based on group # name?
 Call View.Sheets.Add("sheet 1") '... View.Activesheet.Name
 Call View.Sheets("sheet 1").Areas("Area : 1").SplitTop("",-1)
 Call View.Sheets("sheet 1").Areas("Area : 2").SplitTop("",-1)
 View.Sheets("sheet 1").Areas("Area : 1").DisplayObjType = "ChannelTable"
 View.Sheets("sheet 1").Areas("Area : 2").DisplayObjType = "CurveChart2D"
 View.Sheets("sheet 1").Areas("Area : 3").DisplayObjType = "CurveChart2D"

Next

 

0 Kudos
Message 1 of 3
(2,023 Views)

Please try the ChnResampleFreqBased command using the dialog first and then while the dialog is still running, use the keys SHIFT-CTRL--C to copy the dialog settings and then past it into a new script tab.  These settings might help.  My output is shown below:

 

SampleFrequency = 1
ResampleMappingMode= "Automatic"
ResampleAntiAliasingFilter= 0
ResampleInterpolateNovalues= 0
ResampleInterpolationMethod= "Akima"
'------------ Command -------------------
'Call ChnResampleFreqBased("[1]/Time", "[1]/Pressure", "/ResampledY", 1, "Automatic", 0, 0, "Akima")

 

Regarding the View Panel, you should check if a sheet exists before you try to add it.  Also, it is better to assign a new View sheet directly to a variable when you add it.  

 

Below is a complete running example of using command ChnResampleFreqBased() and then plotting the original and resampled channels to the View panel.

 

'-------------------------------------------------------------------------------
'-- VBS script file
'-- Author: Mechatronic Solutions LLC
' Mark W Kiehl
' www.SavvyDiademSolutions.com
'-- Comment: Command ChnResampleFreqBased()
'-------------------------------------------------------------------------------
Option Explicit
Call LogFileDel()

'Call bCreateSampleNumericData()
'Call SUDDlgShow("Main", ResourceDrv & "AnaChnResample")

Call bCreateSampleNumericData()

'Map each channel in every channel group to a new sampling rate
'using the command ChnResampleFreqBased()
Dim oGrp, iGrp, oChnTime, iChn, oChn, oChnResult
For iGrp = 1 To Data.Root.ChannelGroups.Count
Set oGrp = Data.Root.ChannelGroups(iGrp)
Set oChnTime = oGrp.Channels(1)
For iChn = 2 To oGrp.Channels.Count
Set oChn = oGrp.Channels(iChn)
Set oChnResult = oGrp.Channels.Add(oChn.Name & "_ReSampled",DataTypeChnFloat64)
'SampleFrequency = 1
'ResampleMappingMode= "Automatic"
'ResampleAntiAliasingFilter= 0
'ResampleInterpolateNovalues= 0
'ResampleInterpolationMethod= "Akima"
Call ChnResampleFreqBased(oChnTime, oChn, oChnResult, 1, "Automatic", 0, 0, "Akima")
Next
Next

'Plot the data to the View panel
Dim oViewSht, oAreaTop, oAreaMid, oAreaBottom
Call View.NewLayout()
For iGrp = 1 To Data.Root.ChannelGroups.Count
Set oGrp = Data.Root.ChannelGroups(iGrp)
'Add a new View sheet with name = channel group name
Set oViewSht = View.Sheets.Add(oGrp.Name)
'Split the sheet active area into top and bottom areas
Call oViewSht.ActiveArea.SplitTop("Bottom",-1)
'Make the bottom area a Channel Table
Set oAreaBottom = oViewSht.Areas(1)
oAreaBottom.DisplayObjType = "ChannelTable"
'Split the top area into two areas of type 2D Chart
'The new area created is assigned to split area with the hightest index by the method .SplitTop()
Set oAreaTop = oViewSht.Areas(oViewSht.Areas.Count).SplitTop("Top",-1)
oAreaTop.DisplayObjType = "CurveChart2D"
Set oAreaMid = oViewSht.Areas(2)
oAreaMid.DisplayObjType = "CurveChart2D"
'Assign the channels to the bottom area Channel Table
For iChn = 1 to oGrp.Channels.Count
Set oChn = oGrp.Channels(iChn)
Call oAreaBottom.DisplayObj.Columns.Add(oChn.GetReference(eRefTypeIndexIndex))
Next
'Assign the channels to the top area 2d Chart area
Set oChnTime = oGrp.Channels(1)
Set oChn = oGrp.Channels(2)
Set oChnResult = oGrp.Channels(oChn.Name & "_ReSampled")
Call oAreaTop.DisplayObj.Curves.Add(oChnTime.GetReference(eRefTypeIndexIndex),oChn.GetReference(eRefTypeIndexIndex))
Call oAreaTop.DisplayObj.Curves.Add("",oChnResult.GetReference(eRefTypeIndexIndex))
'Assign the channels to the bottom area 2d Chart area
Set oChnTime = oGrp.Channels(1)
Set oChn = oGrp.Channels(3)
Set oChnResult = oGrp.Channels(oChn.Name & "_ReSampled")
Call oAreaMid.DisplayObj.Curves.Add(oChnTime.GetReference(eRefTypeIndexIndex),oChn.GetReference(eRefTypeIndexIndex))
Call oAreaMid.DisplayObj.Curves.Add("",oChnResult.GetReference(eRefTypeIndexIndex))
Next
If View.Sheets.Exists("Sheet 1") Then Call View.Sheets.Remove("Sheet 1")
Call WndShow("VIEW")


'-------------------------------------------------------------------------------

'Call bCreateSampleNumericData()

Function bCreateSampleNumericData()
bCreateSampleNumericData = False
Const iSamples = 25
Dim bUIAutoRefreshSet
bUIAutoRefreshSet = UIAutoRefreshSet(False)
Call dCreateSampleNumericChnDataInDataPortal(iSamples)
Data.Root.Name = "numeric_" & Str(Now(),"#yyyymmdd") & "_2x3x" & Str(iSamples)
Call UIAutoRefreshSet(bUIAutoRefreshSet)
bCreateSampleNumericData = True
End Function 'bCreateSampleNumericData()

Function dCreateSampleNumericChnDataInDataPortal(ByVal iSamples)
'Creates simulated data in the Data Portal and returns the amount of
'time in seconds it took to do it.
'
Const iGrps = 2
Call MsgLineDisp("Creating " & Str(iGrps) & " grps with 3 chns with " & iSamples & " samples")
dCreateSampleNumericChnDataInDataPortal = 0.0
Call Data.Root.Clear()
Const dpTimer = 25
Call StopWatchReset(dpTimer)
Dim oGrp, oChn, dValStart, dValEnd, oChnNew, dConst, s
Dim bChnCommentOver
bChnCommentOver = ChnCommentOver
ChnCommentOver = False
Set oGrp = Data.Root.ChannelGroups.Add("ChnGrp1")
Set oChn = oGrp.Channels.Add("Time",DataTypeChnFloat64)
dValStart = 0.0
dValEnd = iSamples / 2
Call ChnLinGen(oChn,dValStart,dValEnd,iSamples,"s")
Call oChn.Properties.Add("description","time",DataTypeString)

Set oChn = oGrp.Channels.Add("Pressure",DataTypeChnFloat64)
oChn.UnitSymbol = "bar"
Call oChn.Properties.Add("description","hydraulic pressure",DataTypeString)

Set oChn = oGrp.Channels.Add("Temperature",DataTypeChnFloat64)
oChn.UnitSymbol = "K"
Call oChn.Properties.Add("description","hydraulic temperature",DataTypeString)

Set oChn = oGrp.Channels.Add("Speed",DataTypeChnFloat64)
oChn.UnitSymbol = "1/min"
dConst = 1500
Call oChn.Properties.Add("description","engine speed",DataTypeString)

Set oChn = oGrp.Channels.Add("Acceleration",DataTypeChnFloat64)
oChn.UnitSymbol = "m/s^2"
dConst = 1500
Call oChn.Properties.Add("description","vehicle acceleration",DataTypeString)

Set oChn = oGrp.Channels.Add("Torque",DataTypeChnFloat64)
oChn.UnitSymbol = "ft-lb"
dConst = 200
Call oChn.Properties.Add("description","engine torque",DataTypeString)

Set oChn = oGrp.Channels.Add("Power",DataTypeChnFloat64)
oChn.UnitSymbol = "kW"
dConst = 20
Call oChn.Properties.Add("description","engine power",DataTypeString)

'Create an additional channel group with the base data.
Set oGrp = Data.Root.ChannelGroups.Add("TempGroup")
'Create the time channel
dValStart = 0.0
dValEnd = 10
Set oChn = oGrp.Channels.Add("Time",DataTypeChnFloat64)
Call ChnLinGen(oChn,dValStart,dValEnd,iSamples,"s")
'Create the base data channel
Set oChnNew = oGrp.Channels.Add("Data",DataTypeChnFloat64)
dValStart = 1.0
dValEnd = 1000
Call ChnGeoGen(oChnNew,dValStart,dValEnd,iSamples)
Call ChnNormalize(oChn,oChnNew)
'Create a noise channel
Dim sFormula, arrSymbols, arrValues
Set oChn = oGrp.Channels.Add("Noise",DataTypeChnFloat64)
ReDim arrSymbols(1): ReDim arrValues(1)
sFormula = "Noise = Sin(Time)"
arrSymbols(0) = "Time"
arrSymbols(1) = "Noise"
Set arrValues(0) = oGrp.Channels("Time")
Set arrValues(1) = oGrp.Channels("Noise")
Call Calculate(sFormula, arrSymbols, arrValues)
'Combine the Data and Noise channels
Call ChnSub(oGrp.Channels("Data"),oGrp.Channels("Noise"),oGrp.Channels("Data"))
Set oChn = oGrp.Channels("Data")
Call Randomize()
For s = 1 to iSamples
oChn.Values(s) = oChn.Values(s) * Random(1)
Next
'Offset the channel values so that they are all >= 0
Call ChnCharacter(oChn)
Call ChnOffset(oChn, oChn, oChn.Size, "min. value offset")

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Pressure")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)
'0.9653 to 28.0 bar
Call ChnLinScale(oChnNew,oChnNew,20,MaxV(0.9653-oChnNew.Minimum,0.9653))

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Temperature")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)
'273 to 373 K
Call ChnLinScale(oChnNew,oChnNew,10,273)
Call ChnReciprocal(oChnNew, oChnNew)
Call ChnLinScale(oChnNew,oChnNew,100000,0)
Call ChnOffset(oChnNew, oChnNew, 273-oChnNew.Minimum, "free offset")
oChnNew.UnitSymbol = "K"

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Speed")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)
'300 to 2500 rpm
Call ChnLinScale(oChnNew,oChnNew,1000,MaxV(300-oChn.Minimum,300))

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Torque")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)
Call ChnLinScale(oChnNew,oChnNew,250,25)

'Modify the Data channel
Call ChnLinScale(oChn, oChn, 50, 5)
Call ChnReciprocal(oChn, oChn)
Call ChnLinScale(oChn, oChn, 1000, 0)

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Acceleration")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)
Call ChnLinScale(oChnNew,oChnNew,1,0)

'Modify the Noise channel
Set oChn = Data.Root.ChannelGroups("TempGroup").Channels("Noise")
Call ChnReciprocal(oChn, oChn)
Call ChnOffset(oChn, oChn, oChn.Size, "min. value offset")

Set oChnNew = Data.Root.ChannelGroups(1).Channels("Power")
Call DataBlAppend(oChn,1,oChn.Size,oChnNew)
Call ChnCharacter(oChnNew)

Set oChn = Nothing: Set oChnNew = Nothing: Set oGrp = Nothing
Call Data.Root.ChannelGroups("TempGroup").Channels.Remove("Noise")
Call Data.Root.ChannelGroups("TempGroup").Channels.Remove("Data")
Call Data.Root.ChannelGroups("TempGroup").Channels.Remove("Time")
Call Data.Root.ChannelGroups.Remove("TempGroup")

Set oGrp = Data.Root.ChannelGroups.AddChannelGroup(Data.Root.ChannelGroups(1))
oGrp.Name = "ChnGrp2"
oGrp.Channels("Time").Name = "time_sec"
oGrp.Channels("Pressure").Name = "Press"
oGrp.Channels("Temperature").Name = "Temperature"
oGrp.Channels("Speed").Name = "Spd"
oGrp.Channels("Acceleration").Name = "Acceleration"
oGrp.Channels("Torque").Name = "Torq"
oGrp.Channels("Power").Name = "Power"

Call ChnCharacterAll()
ChnCommentOver = bChnCommentOver

Dim iChn
For iChn = Data.Root.ChannelGroups(1).Channels.Count To 4 Step -1
Call Data.Root.ChannelGroups(1).Channels.Remove(iChn)
Next
For iChn = Data.Root.ChannelGroups(2).Channels.Count To 4 Step -1
Call Data.Root.ChannelGroups(2).Channels.Remove(iChn)
Next

Call StopWatchPause(dpTimer)
dCreateSampleNumericChnDataInDataPortal = Round(StopWatch(dpTimer),1)
Call MsgLineDisp(vbTab)
End Function 'dCreateSampleNumericChnDataInDataPortal()

'-------------------------------------------------------------------------------

 

 

 

Message 2 of 3
(1,994 Views)

Awesome, Thanks Mark. BTW your script to copy and paste curve sections has been super helpful too!

0 Kudos
Message 3 of 3
(1,981 Views)