Hi ,
I would like to share the way I found to reverse the upper / lower word of 2 word modbus register.
Around the line from 570 to 610 of the modbus.lua in "microserver/etc/thingworx/lua" folder,
I inserted the following 3-line of code.
function modbus:processResponse(code, pkt, formats)
--**** omit ****
if type(v) ~= "table" then
--**** omit ****
elseif mbFormatFunctions[v[1]] and pkt:len() > 0 then
local temp = {}
if v[2] then temp[1] = v[2] end
if v[3] then temp[2] = v[3] end
if v[4] then temp[3] = v[4] end
--*** added code, from here ****
if string.len(pkt) == 4 then
pkt=string.sub(pkt,3,4)..string.sub(pkt,1,2)
end
--*** added code , to here ****
local res, bytesUsed = mbFormatFunctions[v[1]](pkt, unpack(temp))
--**** omit ****
Note:
Any type of 2-word register such as float and integer will be reversed.
Caution:
All node of modbus slave are affected this modification.
So, if you want to reverse the register of only specific slave node, but not all slave node, then you cannot use this solution.
Test condition:
Linux ARM (no HFPU) version of ThingWorx EMS + Modbus package.
I hope this helps.
Kunio