07-18-2023 05:16 PM
Hello:
I have a dataset where most of the channels are unit-less. There is one channel that I want to define it's Unit properties as meters (m) in vbscript. Sounds simple, but not having much luck.
Tried this:
Call ChnPropSet("[4]/DTC", "/DTC", "m") '...Set Units
...And this
Call ChnPropValSet("[4]/DTC", "unit_string", "m") '...Set Unit
...Also
Call RootPropValSet("Unit", "m") '...Don't see where a channel is defined
I can manually set the unit to meters in the Data Portal with no trouble.
Thanks!
Steve
07-19-2023 02:51 AM
Hello Steve,
At the channel the unit can be set by using the property "unit_string".
Therefore your second expression should be OK.
Here are some variants for the channel also with using the data API (uses the Channel "Geschwindigkeit" of the example file):
Call ChnPropValSet("[1]/Geschwindigkeit", "unit_string", "km/h")
Call ChnPropSet("[1]/Geschwindigkeit", "unit_string", "m/s")
Dim oChn : Set oChn = Data.Root.ChannelGroups(1).Channels("Geschwindigkeit")
oChn.UnitSymbol="km/h"
oChn.Properties("unit_string").Value="m/s"
The older commands like ChnPropValSet() are obsolete. Please use the object-oriented interface of the internal data instead like oChn.Properties().Value etc.
RootPropValSet("Unit", "m") modifies properties only at the root (top level) and does not affect the unit at the channel. There is no channel reference here.
The methods mentioned above only modify the value of the unit property "unit_string".
To convert the channel values from one unit into another unit (m/s -> km/h) use this:
Set ChnResult = ChnConvertUnit("[1]/Geschwindigkeit", "[1]/Geschwindigkeit", "km/h")
Hope the explanations help.
Greetings
Thomas
07-19-2023 09:05 AM
Thank you Thomas, I will give it a try. I am using an old version of Diadem, 2010.
Best Regards,
Steve
Houston, TX
07-19-2023 09:58 AM
To set, simply:
Data.Root.ChannelGroups(4).Channels("DTC").UnitSymbol = "m"
To convert:
ChnUnitConvert("[4]/DTC", "[4]/DTC", "m")
07-19-2023 11:09 AM
Thanks for the reply, gskylr.
Tried this:
Data.Root.ChannelGroups(4).Channels("DTC").UnitSymbol="m"
Call ChnUnitConvert("[4]/DTC","[4]/DTC","m") '... Y,E,TargetUnit
I still get the error "The input channel does not have a unit"
Is there a way that I can assign the unit when I create the channel? Here is where the channel is created:
Call Data.Root.ChannelGroups(4).Channels.Add("DTC",DataTypeFloat64,5)
The only property that I have been successful in changing is with this:
'Call ChnPropValSet("[4]/DTC", "unit", "km/h") ' Adds Property called Unit
But it will not put a value in that property.
Best Regards,
Steve
07-19-2023 08:32 PM
Which line of code errors out?
Can I see the error message?
What type of channel is that?
I just don't know how to reproduce the error, maybe attach example data and script that makes the error?