LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accomodating 2 byte information into one

Solved!
Go to solution

Dear Experts,

 

Assume, I am sending the value of 2 boolean buttons,

 

                                   1st boolean value being 0, It would occupy 1 byte

                                   2nd boolean value being 1, It would occupy 1 byte

 

Hence, I will be sending 2 bytes of information. Kindly someone let me know how I can accommodate the value of both boolean buttons into 1 byte of data. Thank you in advance

 

0 Kudos
Message 1 of 11
(2,794 Views)
Solution
Accepted by topic author Diaspora

Hi Diaspora,

 


@Diaspora wrote:

Kindly someone let me know how I can accommodate the value of both boolean buttons into 1 byte of data.


Build an array from your two boolean values.

Then convert this boolean array to number, then convert the number to U8:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(2,786 Views)

Wow! Thank you for the solution, dear GerdW. I will try implementing the same.

0 Kudos
Message 3 of 11
(2,765 Views)

Using one byte, you can send information of up to 8 booleans, of course.

What is on the receiving end? Do you have control over that? How does the other side expect the information?

 

0 Kudos
Message 4 of 11
(2,764 Views)

Dear GerdW, I am able to implement the same. Thank you.

 

0 Kudos
Message 5 of 11
(2,674 Views)

Dear Experts and GerdW,

I tried implementing the same, but my output is differing a bit. As you can see, your output is displayed as follows

Diaspora_0-1593496013068.png

But, my output is displayed as follows.

Diaspora_1-1593496094504.png

Kindly let me know why this difference is and how to achieve the output representation as yours. Herewith, I attach my vi here. Thank you in advance.

0 Kudos
Message 6 of 11
(2,613 Views)

Hi Diaspora,

 


@Diaspora wrote:

Kindly let me know why this difference is and how to achieve the output representation as yours.


While I used one TRUE and one FALSE boolean your two booleans are both TRUE…

(Did you take some time to learn about those different display/radix options of numerics? Do you understand how to read numbers formatted and displayed with binary radix?)

 

On your VI:

Why do you need the local variable? Why do you introduce a race condition?

Why is there no wait function in the loop, so polling for user input as fast as possible?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(2,608 Views)


While I used one TRUE and one FALSE boolean your two booleans are both TRUE…

 


When I do the same, this is the ouput.

 
 
 
 

ni.png

 
 

(Did you take some time to learn about those different display/radix options of numerics? Do you understand how to read numbers formatted and displayed with binary radix?)


As you can, the radix for binary is chosen.

 
0 Kudos
Message 8 of 11
(2,588 Views)
Solution
Accepted by topic author Diaspora

@Diaspora wrote:

Dear Experts and GerdW,


So you don't think GerdW is an expert? 😋

 

For the numeric, go into the display settings and change the display format to "%08b".  This will set the minimum length to 8 characters and pad 0s on the the left in a binary format.

 

For the string, I am not sure what %u will do as that is supposed to be fractional seconds for a timestamp.  Set the format to %08b.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 11
(2,580 Views)

Hi crossrulz,

 

as an expert I can say %u formats an unsigned integer… 😄

Spoiler
I had to look up the LabVIEW help, too, to learn about this format code.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 11
(2,558 Views)