Author Topic: Bool - True/False - 1/0  (Read 1343 times)

Offline Mike

  • PLUS+1 Developer
  • ***
  • Posts: 35
  • Karma: +1/-0
Bool - True/False - 1/0
« 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.

Offline jashom1

  • PLUS+1 Expert
  • ****
  • Posts: 78
  • Karma: +6/-0
Re: Bool - True/False - 1/0
« Reply #1 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.

Offline Mike

  • PLUS+1 Developer
  • ***
  • Posts: 35
  • Karma: +1/-0
Re: Bool - True/False - 1/0
« Reply #2 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.

Offline jashom1

  • PLUS+1 Expert
  • ****
  • Posts: 78
  • Karma: +6/-0
Re: Bool - True/False - 1/0
« Reply #3 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.

Offline Mike

  • PLUS+1 Developer
  • ***
  • Posts: 35
  • Karma: +1/-0
Re: Bool - True/False - 1/0
« Reply #4 on: November 26, 2019, 01:52:26 PM »
Ah perfect, I should have noticed that difference. Thanks!