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.

Write one bit in register modbus
#1
Hello, I am working with MODBUS  module for TESYS U and LM5, but I need to write one bit individually. For example set 602.1 to 1. Could anyone help me please? Thanks

Attached Files Thumbnail(s)
   
Reply
#2
Are you using profiles or scripts? In any case you will need a script to assemble final register value because profiles do not support writing individual bits.
Reply
#3
(20.12.2017, 13:38)admin Wrote: Are you using profiles or scripts? In any case you will need a script to assemble final register value because profiles do not support writing individual bits.

I am using scripts, have you any sample of this kind of scripts? Thanks
Reply
#4
As far as I understand, only one bit from 0..2 range can be set to 1. For this control I suggest creating 1-byte unsigned integer
object and assign custom values (0 = set bit 0, 1 = set bit 1, 2 = set bit 2) to it so you don't have to create binary objects for each bit.

Code:
mode = grp.getvalue('1/1/1') -- 1-byte unsigned integer
paridad = grp.getvalue('1/1/2') -- boolean
control = grp.getvalue('1/1/2') -- boolean

if mode == 2 then
  value = 4
elseif mode == 1 then
  value = 2
else
  value = 1
end

if paridad then
  value = value + 8
end

if control then
  value = value + 16
end

log(value)
Reply


Forum Jump: