Logic Machine Forum
writing to a bit object - 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: writing to a bit object (/showthread.php?tid=874)



writing to a bit object - rocfusion - 29.06.2017

Hi,

 If I do grp.response('1/1/1',1,dt.bool)  the value is not always written to the bus,  unlike when I write grp.response('1/1/1',true,dt.bool) it is always written. Specifying the data type makes no difference.

As a workaround I have to do this

Code:
function tobool( val )
    if ( val == nil || val == false || val == 0 || val == "0" || val == "false" ) then return false end
    return true
end       
local receivedcommand = string.split(response[2],' ')
       local sw= tobool(dim[1])
       grp.response('11/1/14',sw,dt.bool)

That way I get the string into a number which is then converted to an boolean,  which seems a lot.

Note I have noticed this behavior in all firmware releases and is the same for grp.write.

Thanks,

Roger


RE: writing to a bit object - admin - 30.06.2017

The value is already converted using toboolean function (http://openrb.com/docs/lua.htm#toboolean). I suspect the problem is somewhere else in your code, have you tried logging the value that you're passing to grp.write/grp.reponse? Also, your example is not correct Lua code.


RE: writing to a bit object - rocfusion - 30.06.2017

Hi Admin,

Am sure. My point it's a pain to convert to boolean, would be simpler when grp.write, response etc could consistently accept a number 0 or 1.

Thanks,

Roger


RE: writing to a bit object - admin - 01.07.2017

It's already converted to boolean internally. It will write false if passed value is either boolean false, zero (number) or an empty string or a string '0'. Otherwise it will write true, unless you pass nil, then nothing will happen. Have you tried logging the result of grp.write?