cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot handle returned data from tw_script.executeCallback function

Highlighted
Visitor

Cannot handle returned data from tw_script.executeCallback function

Hi all,

I am having trouble with using the tw_script executeCallback function (TWX libraries written to interface with LSR) in my main LUA template file to call and return the data of the read_multiple_registers function contained within modbus_handler.lua. The data returned by the first function allegedly (according to its LUADOC file) includes the response data as a string but the read_multiple registers returns data formatted as a JSON table, returned in a different order as well. Does the executeCallback function process the data fetched by the function that it calls in any way and what are its detailed return parameters?

In terms of code in my LUA template file, here is something outlining what I am trying to do but the LSR hangs and it's something to do with strdata / jsondata.

properties.AlarmRegister01 = { baseType="INTEGER", pushType = "NEVER", value=""} --and so on until

properties.AlarmRegister12 = { baseType="INTEGER", pushType = "NEVER", value=""}

local postdata = {content='{"slave":10,"address":"42050","count":12, "formats":["Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16", "Uint16"]}'}

local code, headers, strdata

code, headers, strdata = tw_script.executeCallback("modbus_handler", "POST", "read_multiple_registers", nil, nil, postdata)

local jsondata = json.decode(postdata.content or {})

properties.AlarmRegister01.value = jsondata.value[1] --and so on until

properties.AlarmRegister12.value = jsondata.value[12]