Logic Machine Forum
Write one bit in register modbus - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Write one bit in register modbus (/showthread.php?tid=1140)



Write one bit in register modbus - ajgarcia.reyse - 20.12.2017

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


RE: Write one bit in register modbus - admin - 20.12.2017

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.


RE: Write one bit in register modbus - ajgarcia.reyse - 20.12.2017

(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


RE: Write one bit in register modbus - admin - 21.12.2017

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)