This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

mb:setregisters() and LM values
#1
Hi all,

I think I have figured out the method to read a register and write its value to an LM object

-------------------------------------------------- ---------------------------
result_5, result_6, result_7, result_8 = mb:readregisters(3203, 4)

if result_5 then
  value5 = bit.lshift(result_5, 48) + bit.lshift(result_6, 32) + bit.lshift(result_7, 16) + result_8
  ../..
end
-------------------------------------------------- ---------------------------

But could you explain to me how to do the opposite with the method "mbConfusedetregisters(register,value)"
from values of LM objects like Uint8, Float32 and Int64?

Thank you in advance for your assistance and have a good week.
Reply
#2
See this: https://forum.logicmachine.net/showthrea...833#pid833
Reply
#3
So, is this correct to write an INT64 into 4 registers?

value = event.getvalue()
raw = knxdatatype.encode(value, dt.float32).dataraw

r1 = raw:byte(1) 
r2 = raw:byte(2)
r3 = raw:byte(3) 
r4 = raw:byte(4)

register = 3204
mbConfusedetregisters(register, r4)
mbConfusedetregisters(register+1, r3)
mbConfusedetregisters(register+2, r2)
mbConfusedetregisters(register+3, r1)
Reply
#4
You won't have event.getvalue() in a resident script. encode call should have correct data type set as the second argument.
Code:
value = grp.getvalue('32/1/1')

raw = knxdatatype.encode(value, dt.int64).dataraw

r1 = raw:byte(1) * 0x100 + raw:byte(2)
r2 = raw:byte(3) * 0x100 + raw:byte(4)
r3 = raw:byte(5) * 0x100 + raw:byte(6)
r4 = raw:byte(7) * 0x100 + raw:byte(8)

register = 3204
mb:setregisters(register, r4)
mb:setregisters(register+1, r3)
mb:setregisters(register+2, r2)
mb:setregisters(register+3, r1)
Reply
#5
Thank's !
Trying your code with à 12.4 LM object (value = 12345678) I obtain this (writed in log)

string: r4 : 24910 | r3 : 188 | r2 : 0 | r1 : 0
string: Value : 12345678

Readed as 106987647664.13 by the Modbus master !!!
Reply
#6
Modbus does not define word/byte order so there are 4 different ways of encoding an int64 value.

Try this:
Code:
value = grp.getvalue('32/1/1')

raw = knxdatatype.encode(value, dt.int64).dataraw

r1 = raw:byte(1) * 0x100 + raw:byte(2)
r2 = raw:byte(3) * 0x100 + raw:byte(4)
r3 = raw:byte(5) * 0x100 + raw:byte(6)
r4 = raw:byte(7) * 0x100 + raw:byte(8)

register = 3204
mb:setregisters(register, r1)
mb:setregisters(register+1, r2)
mb:setregisters(register+2, r3)
mb:setregisters(register+3, r4)

And this:
Code:
value = grp.getvalue('32/1/1')

raw = knxdatatype.encode(value, dt.int64).dataraw

r1 = raw:byte(2) * 0x100 + raw:byte(1)
r2 = raw:byte(4) * 0x100 + raw:byte(3)
r3 = raw:byte(6) * 0x100 + raw:byte(5)
r4 = raw:byte(8) * 0x100 + raw:byte(7)

register = 3204
mb:setregisters(register, r4)
mb:setregisters(register+1, r3)
mb:setregisters(register+2, r2)
mb:setregisters(register+3, r1)
Reply
#7
Perfect Admin, the second was the good one !

Thank you for your help, the speed of your answers and your professionalism.
Reply


Forum Jump: