PLUS+1 User Forum

PLUS+1™ Software => General controls => Topic started by: Mike on November 25, 2019, 06:34:30 PM

Title: Bool - True/False - 1/0
Post by: Mike on November 25, 2019, 06:34:30 PM
Is there a simpler way than using boolean switches to convert a bool signal into a value?

For example I am sending a Digital In bool through a CAN message. I thus need the bool to be a U8. The retype does not work on boolean inputs and so the only way I can think of is to have the bool switch between 0 and 1. I suppose I find this most frustrating because coming from C/C++, 0 and 1 are the true and false values.
Title: Re: Bool - True/False - 1/0
Post by: jashom1 on November 25, 2019, 09:20:17 PM
Hi Mike,

There is various ways to skin a cat, but I would use the Encode block to convert bool(s) into a byte for transmission, it's much more visual to see what's going on.
Title: Re: Bool - True/False - 1/0
Post by: Mike on November 25, 2019, 09:52:22 PM
Do all of the inputs to the encode have to be the same for it to work? I get an error if I try to mix in one of the True/false constants, the DigIn inputs come in as a True/False which the rest of the software distinguishes as separate from a 1/0.
Title: Re: Bool - True/False - 1/0
Post by: jashom1 on November 26, 2019, 01:19:12 AM
All of the inputs to an Encode block that is set to U8 must be true/false, if you change the encode block to another variable type, eg. Array, each element must be of that variable type.  To get your CAN packet together I would cascade the encode blocks like attached.

Hope that helps.
Title: Re: Bool - True/False - 1/0
Post by: Mike on November 26, 2019, 01:52:26 PM
Ah perfect, I should have noticed that difference. Thanks!