1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
if msg.modbus.quantity == 2 then -- pour le moment à 2 pour limiter à une lecture de d'un registre (float ou unint32), la finalité msg.modbus.quantity >= 2
local entry = global.modbusmapping[msg.modbus.start] --entry récupère dans ma table les entrées correspondantes
-- entry contien les champs suivants :
-- {encoding = 'float or unint32', datakey = 'nomdevariable'},
if entry then
msg.payload = global.data[entry.datakey] --le payload devient égal à la valeur "datakey" stockée dans ma table modbusmapping
local encoding = entry.encoding --je regarde l'encodage souhaité présent aussi dans ma table modbusmapping
if encoding == 'float' then sendTo(2, msg) --j'envoi le payload sur la sortie appropriée
elseif encoding == 'uint32' then sendTo(1, msg) --j'envoi le payload sur la sortie appropriée
end
else
msg.payload = 0
sendTo(1, msg)
end
end |
Partager