StateToNumber()

Format

StateToNumber(DigitalStateNames [,Datasource] [,DigitalStateSet])

Returns

Returns the number value of the digital state that corresponds to the provided digital state text value.

Inputs

DigitalStateNames: The name of the digital states which should be converted to their respective values. If you have a tag that returns a collection of digital state names, you can supply the tag name here, using tag syntax (i.e. {tagname}).
Behaviour: Required
Dimensions: Collection, SingleValue, MultiCollection
Valid data types: String

Datasource: Optional. Name of the datasource to which the digital state set belongs. If this parameter is supplied then the DigitalStateSet parameter must also be specified. Use null if the digital state set is not assigned to a datasource. 
Behaviour: Optional
Dimensions: SingleValue
Valid data types: Null, String

Note: The 2nd and 3rd parameters are used to correctly identify the digital state set for the function. They are usually needed because:
- A manually created digital state set might not be imported by an adaptor; in such cases it might not have a datasource.
- It’s possible that multiple datasources/adaptors import different digital state sets with the same name. E.g. “On Off” is quite common.

DigitalStateSet: Optional. Name of the digital state set which should be used for converting digital states to values.
Behaviour: Optional
Dimensions: SingleValue
Valid data types: String

How to format data types

Examples

Expression: StateToNumber('ON', null, 'OnOffStates')
Result: Returns 1 if the assigned value of digital state 'ON' is 1 in the digital state set called 'OnOffStates'.

Expression: StateToNumber({Tag1})
Result: Returns the value of every digital state name that {Tag1} returned during the fetch using the digital state set which is assigned to {Tag1}.

Expression: StateToNumber({Tag1}, '', 'OnOffStates')
Result: Returns the value of every digital state name that {Tag1} returned during the fetch using the 'OnOffStates' digital state set.

Tip: If you have access to the sample data, try running the following examples using the calculation tester

Expression: StateToNumber("On", "Oil and Gas Data", "On Off")
Result: 1 

Expression: StateToNumber("Online", null, "Status")
Result: 0 

Release History

  • StateToNumber() 4.6.5
    • Changed DigitalStateNames parameter to support MultiCollection values.
  • StateToNumber() 4.5.1
    • Initial version

Comments are closed