## Using a TopView Logic Function to alarm based on a lookup table

### Question

We would like to generate an alarm if the tag value is above the alarm level according to temperature based on the following table:

```°C alarm level
0 to 4.99 -> 0.6
5 to 9.99 -> 0.8
10 to 14.99 -> 0.9
15 to 19.99 -> 1.0
20 to 24.99 -> 1.1
25 to 29.99 -> 1.3
30 to 34.99 -> 1.4
35 to 39.99 -> 1.5
40 to 44.99 -> 1.7
45 to 49.99 -> 1.8```

How can I do this in TopView?

### Response

You can do this with TopView Logic Functions.

If you have not used these before, please watch the online video “TopView Logic functions” so you are familiar with how they work:

Once you understand how to use them, you can create a user tag to execute the logic function.

Create a user tag to execute the function. The user tag should have the following properties:

1. Operation of user tag: “FCN LookupTable <%tagvalue||server||temperature%>, <%tagvalue||server||monitortag%>”
where server is your Server name, temperature is the temperature tag name, and “monitortag” is the tag name whose value you are alarming on.
2. Alarm condition of the user tag: “= 1”
The logic function returns 1 if the tag value value is above the high limit.

Create a logic function with the following properties:

• Name: “LookupTable”
• Arguments: LookupValue and TestValue
(LookupValue is the temperature, TestValue is the monitored tag value)

Insert the following code into the logic function:

```'return value of function will be:
'-1 Lookup value failed
' 0 TestValue <= high alarm limit
' 1 TestValue > alarm limit (In alarm)

'Lookup table
Dim highAlarmLimit As Single = 0
If LookupValue >= 0 And LookupValue < 5 Then
highAlarmLimit = 0.6
ElseIf LookupValue >= 5 And LookupValue < 10 Then
highAlarmLimit = 0.8
ElseIf LookupValue >= 10 And LookupValue < 15 Then
highAlarmLimit = 0.9
ElseIf LookupValue >= 15 And LookupValue < 20 Then
highAlarmLimit = 1.0
ElseIf LookupValue >= 20 And LookupValue < 25 Then
highAlarmLimit = 1.1
ElseIf LookupValue >= 25 And LookupValue < 30 Then
highAlarmLimit = 1.3
ElseIf LookupValue >= 30 And LookupValue < 35 Then
highAlarmLimit = 1.4
ElseIf LookupValue >= 35 And LookupValue < 40 Then
highAlarmLimit = 1.5
ElseIf LookupValue >= 40 And LookupValue < 45 Then
highAlarmLimit = 1.7
ElseIf LookupValue >= 45 And LookupValue < 50 Then
highAlarmLimit = 1.8
Else
'Could not perform lookup
Return -1
End If

Compare TestValue to high alarm limit
If TestValue > highAlarmLimit Then
'return 1 if test value exceeds high alarm limit
Return 1
Else
'test value not above high alarm limit
Return 0
End If```

If desired, the above code could also interpolate the high alarm limit within the range instead of having a single lookup value. It will add some additional logic but it can be done.