Skip to main content

Signal Delay with Lua

For delaying the response of command execution, Lua runner could be used as one of the solutions. In this example IEC104 and Modbus TCP are used. IEC104 protocol sends the command to Modbus and Lua signals and the results are represented as two separate signals. To create Excel configuration for WCC Lite in this case device sheet should look like this:


In the fields marked red, for Modbus TCP enter IP address of Wi-Fi connected to computer and for IEC104 enter IP address of WCC Lite. Map the signals as shown below:


IEC104 SCADA will send command which will then go to Lua signal. Lua signal will send the response back to IEC104 SCADA and to Modbus TCP result signal. 

For delaying signal response, Lua script could be written in many ways, however the most simple and effective one is to determine a wait time before publishing signal values to result signals. So in this case Lua script will look like this:

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'

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

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 command 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
publish(signals.result, saved.value)--restores saved value to result signals
return 0
if 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 type 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
local sleepTime = 30
sleep(sleepTime) --before publishing values to result signals script waits 30s
publish(signals.result, command.value)--in this row values are being published to result signals

After entering values to empty Excel configuration fields, upload the configuration to WCC Lite (it should upload without any errors):


Upload Lua script to script runner and press start. After this, Status should show Running and script process number will appear.image-1691650520213.png

Open Vinci as IEC104 master, enter IP address of WCC Lite and start communication. Then open another Vinci window and connect Modbus TCP master – select Modbus TCP slave in Vinci and enter the same IP address as set in Excel configuration for Modbus device. With both communications running check Protocol connections on WCC Lite web interface, it should show connected. From IEC104 Vinci window go to System tab. Select command determined in the Excel configuration (50), IOA (1) and value (eg. 2). 


Execute the command and check Imported signals:


After 30s result signals will now have the same value:


Signal delay could be used as a tool to synchronize signals so all the values are received at the same time. It can also be used to schedule commands or tasks when delay is required. Since Lua is one of the faster programming languages, it is the most effective instrument to be used is such matters.

Configuration --> Download

Lua script --> Download