Skip to main content

Configuration Example With Default and Saved Values (Modbus TCP, IEC104)

Excel configuration

In order to control signals with Lua script an excel configuration for WCC Lite is needed. In this case three devices are required: one for Modbus TCP Master, one for IEC104-slave and one for Lua runner. Configuration example:


In order to connect slave and master devices, master's IP address and slave's host addresses has to be specified. Modbus IP address will be the address of Wi-Fi to which the computer is connected (this can be checked on terminal window with command ipconfig) and host address for IEC104 slave protocol will be the IP address to which WCC Lite is connected. To reach the device via these addressed WCC Lite has to be connected to the internet.

When creating Excel configuration with Lua, there is an option default value for signal. This value will be set to the signal right after uploading configuration or if the script does not return any saved values.

Signals sheet:


As it is seen from example values such as min_value and max_value can be added to determine limits of a signal. This way command signal will only return results which are within this range. Otherwise command value will have negative cot with invalid, non topical or overflow attributes and new value will not be sent to result signals. As configured, until command value is sent default value will be represented for Lua command signal. For saved values to be represented a Lua script is needed. 

Lua script 

Lua script example for this configuration is shown below:

local saved = get(signals.result) --getting result signal which is equated to new variable 'saved'
local command = get(signals.command) --getting command signal which is equated to new variable 'command'

--get() function returns nill if there is no valid value

if not command then --if command is not nill
    if saved then --if signal is not nill
        publish(signals.result, saved.value) --this value is published to result signals and saved value
    return 0

local time_diff = time_ms() - tonumber(command.time) --compares command time and real time
local is_command = time_diff < 30000 and time_diff > -30000 --if command time differs from
--real time more than 30s it will not be executed 

if string.find(command.attributes, "nt") or string.find(command.attributes,
"iv") or string.find(command.attributes, "ov") then
--searching if signal has negative attributes 
    if is_command then --if command execution time is not exceeding the limits then
        command.attributes = "cot=7,cotn" --equates negative cot values to response signal attributes
        publish(signals.command, command) -- and publishes value to command signals and value
        if saved then --if there is saved value then
            publish(signals.result, saved.value) --restores saved value to result signals
        return 0
    if is_command then
        command.attributes = "cot=7"
        publish(signals.command, command)   --in this cycle command value is being returned as well as
--cot7 and cot10 values in case given signal is command and has no negative attributes
        command.attributes = "cot=10"
        publish(signals.command, command) --publishes response to the command
        save(signals.result, command.value) --command value is being saved to result signal
    publish(signals.result, command.value) --in this row command value is being published to result signals

Uploading configuration and Lua script to WCC Lite

First Excel configuration needs to be uploaded to WCC Lite:


After uploading configuration default value will be shown:


After uploading configuration no errors should appear and all signal should be represented on the web. To upload Lua script go to Script-Runner, select upload script and then start:


Connecting master and slave via Vinci software

Connecting IEC104 slave 

In order to connect to WCC Lite via IEC104 protocol, select Master(Client) mode on Vinci:


Check Settings tab to match excel configuration:


Specify IP address which should match the one in Excel configuration.

Connecting ModbusTCP master:

To connect ModbusTCP Master, select Slave (Server) mode on Vinci:


Check address to match id in Excel configuration:


Match the IP address given in Excel configuration as well.

Executing commands

Start both master and slave simulations on Vinci. Check if both protocols are connected to WCC Lite on the web tab Protocol Connections:


To execute commands, open Vinci program with IEC104 master running. Here, go to System tab and fill in required fields such as IOA and select data type indicated in Excel configuration. First, try sending value that is outside the set range:


After selecting execute this value will not be showed on the web and positive cot6 and negative cot7 values will be seen on Vinci IEC104 simulation window. Positive cot6 indicates command activation and negative cot7 means that command activation confirmation was denied. The command signal value will not be represented as result signals, because it is determined in the script, that signals with negative attributes will not be published. 


Now specify value which will be sent as a result and is within the given range.  


Positive cot7 and cot10 values will be seen on the Vinci IEC104 simulation window:


This value will also be represented on Modbus TCP master Vinci simulation window:


To show what happens if the value is not within determined range after the correct value has been sent before, try executing command with smaller or larger value specified:


Again, positive cot6 and negative cot7 values is seen on Vinci window.


As seen on WCC Lite web window, command signals have negative attributes and result signals have the same value as before, because it was saved by Lua script. This example shows that Lua runner can be used to save certain values to signal. For example after the restart saved value could be seen on command signal to determine minimum or maximum value, last value or typical value. This solution could be useful for protecting important data even after reboot or connection faults. 

Configuration --> Download

Lua script --> Download