This example shows the functionality of an item value which is limited to a minimum and maximum boundary. The minimum and maximum value can be defined by the user. Additionally it is possible to define an email address where the user is notified when the input value is outside the upper or lower boundary. The value can also be written to an output item, when the value is inside the defined value range.
The functionality of the example is based on the idea to limit the output for a specific server item. The user has to specify the minimum and maximum value which defines the range in which the input values are accepted. The definition of the example provides additionally two optional parameter. First an output item can be defined, where correct values are forwarded too. Second it is possible to specify an email address, to inform the user about values of the item which are outside the defined range. In the following section the example is solved in a step by step tutorial and every single step is described in detail.
To use this tutorial, please do the following steps in advance:
- Install the NETx BMS Server. The setup can be found here at our website.
- Create a new BMS server workspace and integrate some data points that you want to monitor.
Creating a new LUA function
First, we will create a new LUA function which verify the item value and sends an e mail if it is out of limit. Within the toolbar of the NETx BMS Studio, click on the "Edit Script" button.
Afterwards, you can select the LUA file that you want to manipulate. Select "nxaDefinitions.lua" to open the main LUA file.
LUA code can be split into different files to organize it. The "nxaDefinitions.lua" is the main file which is loaded by the NETx BMS Server automatically. All other LUA files must be imported by using the "Require" statement at the beginning of "nxaDefinitions.lua".
Then start to implement a new LUA function called "LimitValue". You can implement it at any location outside other functions. Paste in the following code:
function LimitValue(minValue, maxValue, email) local currentValue = nxa.SourceValue() if (currentValue ~= nil and currentValue >= minValue and currentValue <= maxValue) then nxa.WriteDestinationValue(currentValue) else if (email ~= nil) then xcon.SendEmailTo("wolfgang@granzer.org", "Value out of range", "The input value with ID " .. nxa.SourceItemID() .. " is out of range") end end end
The function takes the following parameters:
- minValue: defines the minimum value of the range for the input item
- maxValue: defines the maximum value of the range for the input item
- email: defines the e mail address where item values outside the boundaries are reported.
Create a task definition to use the LUA function
Related articles