LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending binary bits as an array of unsigned bytes?

Solved!
Go to solution

Hello,

 

A VI provided to me by a host adapter I am using requires an input that is a 1D array of unsigned bytes. I have the necessary 24 bit (3 byte) string I need but I am unsure how to format it as a 1D array of unsigned bytes. Would the array just be three elements with each element consisting of 8 bits? Would it be best to convert the 8 bit string to decimal and then each element of the 1D array would just be the decimal representation of the 8 bit string?

 

Thanks for any help!

0 Kudos
Message 1 of 7
(3,172 Views)

Try using the String to Byte Array function.

0 Kudos
Message 2 of 7
(3,170 Views)

Hi Imcohen2,

 

I have the necessary 24 bit (3 byte) string I need but I am unsure how to format it as a 1D array of unsigned bytes.

Convert the string to an U8 array using StringToByteArray…

Best regards,
GerdW


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

@lmcohen2 wrote:
Would the array just be three elements with each element consisting of 8 bits?

If you use String To Byte Array, this is exactly what you will get.


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
0 Kudos
Message 4 of 7
(3,160 Views)

Thanks for the responses. I have done this, and it doesn't give me what I am hoping for. I am not very knowledgable with data structures so let me explain in more detail the issue:

 

To communicate with my slave device I need to send 24 bits of data. I've created a program to select the correct 24 bits depending on what you'd (the user) like to write to the slave. So I have a string "1010101..." for 24 bits. The write VI provided by my host adapter accepts data as a 1D array of unsigned bytes. If I use string to byte function on the 24 bits above and then input that into the adapter's VI, I see 24 logic highs being sent to the slave device each separated by the setup time in between bytes. I could be wrong, but I believe the 1D array I should send to the slave device should have 3 elements each corresponding to the 3 bytes of the string. But I am unsure how to convert a string of 8 bits ("10101011") to a U8 because when I just use a data conversion VI it doesn't give the correct decimal value. Hopefully this made sense.

0 Kudos
Message 5 of 7
(3,149 Views)
Solution
Accepted by topic author lmcohen2

Attach a VI that has an example of the data in the format you have now.

 

That is the problem when you don't attach actual code so we can see what you are working with.  Three different knights responded all in the same way based on what we thought you were describing based on the way you wrote it.   You said you have a 3 byte string.

 

Apparently you meant something else.  Now it sounds like you have a 24 character string of 1's and 0's you want to convert to 3 bytes.

 

Try this.  The only thing you might need to do is reverse the order of the array depending on if you want most significant or least significant byte first.

Example_VI_BD

Message 6 of 7
(3,137 Views)

That worked! Much thanks!

0 Kudos
Message 7 of 7
(3,130 Views)