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.

int16 on modbus script
#1
Hi everybody,
I've a problem on a script. I'm tring to read a solar inverter ZCSAzzurro. I've problem on negative number.
I've made this request:

if (res9[2] == nil) then
-- Chiamata potenza rete
  res10=nil
res10 = { mb:readregisters(530,dt.int16) }
  grp.update('Potenza_rete',(res10[1]))
log("Grind_power",res10)
  os.sleep(1.1)
  else
  --log("timeout!")
  mb:close()
end


But in the log I find the number 32767. But if try to make a read in the modbus scheduler I get -27 (right value)
Where am I wronging?

Thanks for who will help me.

BR Cristian
Reply
#2
Use this:
Code:
value = mb:readregistervalue(530, 'int16')
Reply
#3
(23.05.2022, 05:30)admin Wrote: Use this:
Code:
value = mb:readregistervalue(530, 'int16')

No, it doesn't work, it gives me an error of 'bad argument #2 ro readregisters (number expect, got string)
Best regards Cristian
Reply
#4
Use mb:readregistervalue not mb:readregisters.
Reply
#5
(23.05.2022, 13:20)admin Wrote: Use mb:readregistervalue not mb:readregisters.

Sorry
Reply
#6
The function for reading data with a set data type is called readregistervalue. Just use this code as is:
Code:
value = mb:readregistervalue(530, 'int16')
Reply
#7
Thanks man, now it works
Reply


Forum Jump: