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.

writing to a bit object
#1
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
Reply
#2
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.
Reply
#3
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
Reply
#4
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?
Reply


Forum Jump: