07-16-2018 07:22 AM
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!
Solved! Go to Solution.
07-16-2018 07:28 AM
Try using the String to Byte Array function.
07-16-2018 07:28 AM - edited 07-16-2018 07:28 AM
07-16-2018 07:41 AM
@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.
07-16-2018 07:50 AM
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.
07-16-2018 08:05 AM - edited 07-16-2018 08:13 AM
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.
07-16-2018 08:19 AM
That worked! Much thanks!