03-04-2020 03:00 AM
Hi,
Reviewing large quantities of CAN data performing some calculating to get some basic values, so to save time I have used the script record mode to produce a basic script, however I'm assuming as a result of how the CAN decoder works the groups don't always end up in the same order, so it is just stopping because there isn't a channel in that group with the correct name.
Is there a way of ignoring the group number and searching the entire data portal for the channel name?
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Call Data.Root.ChannelGroups.Add("Power Calcs", 1).Activate()
Set ChnResult = ChnMul("/HVBusVoltage", "/TotalHVBatteryCurrent", "/Bus Power")
Set ChnResult = ChnUnitConvert("[1]/Bus Power", "/Bus Power", "kW")
Set ChnResult = ChnLinScale("[1]/Bus Power", "/Bus Power", -1, 0)
Call ChnClpCopy("[55]/Time", True)
Call ChnClpPaste(1295, True)
Call Data.Move(Data.Root.ChannelGroups(1).Channels("Time"),Data.Root.ChannelGroups(1).Channels,1)
Set ChnResult = ChnUnitConvert("[1]/Time", "/UnitConverted", "h")
Set ChnResult = ChnOffset("[1]/UnitConverted", "/UnitConverted", 0, "first value offset")
Data.Root.ChannelGroups(1).Channels("UnitConverted").Name = "Time(h)"
Solved! Go to Solution.
03-04-2020 09:01 AM
Data.GetChannels(ChannelName)
Warning: This will only give you the first occurrence of a channel with that name. If you have multiple channels with the same name in different groups, then you can use:
Data.GetChannels("*/" & ChannelName)
This will create a collection of all channels named "ChannelName" from any number of groups
03-05-2020 05:53 AM
Hi Thanks for the help. I am a novice at this could you give me a little more context as to how I can implement this?
Specifically in this line: Set ChnResult = ChnMul("[55]/HVBusVoltage", "[55]/TotalHVBatteryCurrent", "/Bus Power")
If HVBusVoltage and TotalHVBatteryCurrent aren't in group 55 then it doesn't work. None of my channel names are in more than one group.
Thanks.
03-05-2020 09:11 AM
Something lie this could work:
Dim currentChannel, voltageChannel
Set currentChannel = Data.GetChannel("TotalHVBatteryCurrent")
Set voltageChannel = Data.GetChannel("HVBusVoltage")
Set ChnResult = ChnMul(voltageChannel.GetReference(eReferenceIndexName), currentChannel.GetReference(eReferenceIndexName), "/Bus Power")
03-24-2020 02:38 PM
Hi DEK,
If the channel names you want to reference exist in one and only one Group, then you can ignore the Group part and use that channel name as a string constant:
Set ChnResult = ChnMul("HVBusVoltage", "TotalHVBatteryCurrent", "/Bus Power")
If, alternatively, the Group/Bus name is always the same for these channels, then you can include the Group Name instead of the Group Index:
Set ChnResult = ChnMul("GroupNameABC/HVBusVoltage", "GroupNameABC/TotalHVBatteryCurrent", "/Bus Power")
Brad Turpin
Senior Technical Support Engineer
National Instruments
03-24-2020 02:43 PM
Hi All,
The suggestion from gskylr is also excellent. I prefer using object variables to string constants, but many customers find using string constants more intuitive than object variables. I just wanted to add, that if you're using channel object variables, you don't have to request and pass the reference when using as a parameter of a function or command:
Dim currentChannel, voltageChannel
Set currentChannel = Data.GetChannel("TotalHVBatteryCurrent")
Set voltageChannel = Data.GetChannel("HVBusVoltage")
Set ChnResult = ChnMul(voltageChannel, currentChannel, "/Bus Power")
Brad Turpin
Senior Technical Support Engineer
National Instruments