PLUS+1 Software > General controls

Bool - True/False - 1/0

(1/1)

Mike:
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.

jashom1:
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.

Mike:
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.

jashom1:
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.

Mike:
Ah perfect, I should have noticed that difference. Thanks!

Navigation

[0] Message Index

Go to full version