UOMGroup.Convert Method
- Last UpdatedNov 18, 2025
- 5 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.UnitsOfMeasure
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public double Convert( Object fromValue, UOM fromUOM )
Public Function Convert ( fromValue As Object, fromUOM As UOM ) As Double Dim instance As UOMGroup Dim fromValue As Object Dim fromUOM As UOM Dim returnValue As Double returnValue = instance.Convert(fromValue, fromUOM)
public: double Convert( Object^ fromValue, UOM^ fromUOM )
member Convert : fromValue : Object * fromUOM : UOM -> float
Parameters
- fromValue
- Type: SystemObject
The value to be converted. Normally, this is sent as a double. - fromUOM
- Type: OSIsoft.AF.UnitsOfMeasureUOM
The unit of measure of the specified value. If this is not specified, or is specified, then the unit of measure should be specified in the fromValue by passing it as a string.
Return Value
Type: DoubleReturns the value converted to the mapped unit of measure as defined by this UOMGroup.
Exceptions
| Exception | Condition |
|---|---|
| InvalidCastException | Thrown when the conversion cannot be performed. |
Remarks
The mappings defined for this UOMGroup are used to determine resulting UOM for the fromValue based upon the specified fromUOM. If the two UOMs share the same reference object, or are a direct reference to each other, then the conversion is done directly using these reference units. This allows fewer mathematical operations and reduces the loss of precision during conversion. Otherwise, the canonical unit-of-measure factors are used to convert.
Optionally, you can specify for the fromUOM parameter and specify the units in the input parameter if it is represented in string notation. For example, "100.0 ft". In this case, the Convert function looks up the UOM from the text name or abbreviation that follows the floating point number.
Examples
// This example will create a UOM Group with mappings, display its information, // and then perform some conversions. // Get the Database PISystems myPISystems = new PISystems(); UOMDatabase myDB = myPISystems.DefaultPISystem.UOMDatabase; // Create a UOM Group UOMGroup MyCustomGroup = myDB.UOMGroups.Add("MyCustomUOMGroup*"); MyCustomGroup.Description = "Custom UOM Group for Length"; // Add mappings to group MyCustomGroup.Mappings[myDB.UOMs["ft"]] = myDB.UOMs["m"]; MyCustomGroup.Mappings[myDB.UOMs["in"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["nmi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mi"]] = myDB.UOMs["km"]; MyCustomGroup.Mappings[myDB.UOMs["mm"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["sxi"]] = myDB.UOMs["cm"]; MyCustomGroup.Mappings[myDB.UOMs["yd"]] = myDB.UOMs["m"]; myDB.CheckIn(); // Display the UOM Groups foreach (UOMGroup group in myDB.UOMGroups) { Console.WriteLine("Name of UOM Group = {0}", group.Name); Console.WriteLine("Description = {0}", group.Description); Console.WriteLine("Mappings:"); foreach (KeyValuePair<UOM, UOM> item in group.Mappings) { Console.WriteLine(" {0} ==> {1}", item.Key, item.Value); } } // Perform some conversions AFValue origAFValue = new AFValue(55.3, AFTime.Now, myDB.UOMs["mi"]); double mappedValue = MyCustomGroup.Convert(100.0, myDB.UOMs["yd"]); Console.WriteLine("Convert 100.0 ft ==> {0}", mappedValue); AFValue mappedAFValue = origAFValue.Convert(MyCustomGroup); Console.WriteLine("Convert {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM); // Display attribute value using Display UOM myDB.DisplayUOMGroup = MyCustomGroup; origAFValue = MyAttr.GetValue(); mappedAFValue = MyAttr.GetValue(MyAttr.DisplayUOM); Console.WriteLine("GetValue {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM);
' This example will create a UOM Group with mappings, display its information, ' and then perform some conversions. ' Get the Database Dim myPISystems As New PISystems() Dim myDB As UOMDatabase = myPISystems.DefaultPISystem.UOMDatabase ' Create a UOM Group Dim MyCustomGroup As UOMGroup = myDB.UOMGroups.Add("MyCustomUOMGroup*") MyCustomGroup.Description = "Custom UOM Group for Length" ' Add mappings to group MyCustomGroup.Mappings(myDB.UOMs("ft")) = myDB.UOMs("m") MyCustomGroup.Mappings(myDB.UOMs("in")) = myDB.UOMs("cm") MyCustomGroup.Mappings(myDB.UOMs("nmi")) = myDB.UOMs("km") MyCustomGroup.Mappings(myDB.UOMs("mi")) = myDB.UOMs("km") MyCustomGroup.Mappings(myDB.UOMs("mm")) = myDB.UOMs("cm") MyCustomGroup.Mappings(myDB.UOMs("sxi")) = myDB.UOMs("cm") MyCustomGroup.Mappings(myDB.UOMs("yd")) = myDB.UOMs("m") myDB.CheckIn() ' Display the UOM Groups For Each group As UOMGroup In myDB.UOMGroups Console.WriteLine("Name of UOM Group = {0}", group.Name) Console.WriteLine("Description = {0}", group.Description) Console.WriteLine("Mappings:") For Each item As KeyValuePair(Of UOM, UOM) In group.Mappings Console.WriteLine(" {0} ==> {1}", item.Key, item.Value) Next Next ' Perform some conversions Dim origAFValue As New AFValue(55.3, AFTime.Now, myDB.UOMs("mi")) Dim mappedValue As Double = MyCustomGroup.Convert(100.0, myDB.UOMs("yd")) Console.WriteLine("Convert 100.0 ft ==> {0}", mappedValue) Dim mappedAFValue As AFValue = origAFValue.Convert(MyCustomGroup) Console.WriteLine("Convert {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM) ' Display attribute value using Display UOM myDB.DisplayUOMGroup = MyCustomGroup origAFValue = MyAttr.GetValue() mappedAFValue = MyAttr.GetValue(MyAttr.DisplayUOM) Console.WriteLine("GetValue {0} {1} ==> {2} {3}", origAFValue.Value, origAFValue.UOM, mappedAFValue.Value, mappedAFValue.UOM)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.