Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Description

This example shows the how to write or read to any XCON(TCP/UDP) connection. The connection can be handled with LUA function. The write value can be written from any selected item, and the read value also be written to an output item.
The Read function should handle the incoming values and convert them to their HEX values. 
This tutorial has two functions: 

  • Send_TcpHex()
  • MyTCP_OnReceiveEvent(data, size, sourceip, sourceport)
LUA
function Send_TcpHex()
local var = nxa.GetValue('NETx\\VAR\\String\\Item001')
xcon.CreateTCP("MyTCP","0",0,"127.0.0.1",23)
xcon.SendHex("MyTCP", var)
end




function MyTCP_OnReceiveEvent(data, size, sourceip, sourceport)
local val= string.tohex(data)
nxa.SetValue('NETx\\VAR\\String\\Item002',val)
end


function string.tohex(str)
    return (str:gsub('.', function (c)
        return string.format('%02X', string.byte(c))
    end))
end


  • No labels