LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Array

Hi all. Need a little help with a project.

 

So I am reading in a string of 8-bit bytes, for example "10101010 11111111 01010101" etc. I need to extract each byte and then display it as a decimal. I tried using String to Byte Array and a few others but coudnt figure it out. Any help would be most grateful!

 

0 Kudos
Message 1 of 11
(4,406 Views)

All bytes are 8 bit, but you need to clarify how they are represented in the string. Is your example a binary formatted string consisting exclusively of the two characters 0 1nd 1? It also looks like ther is a delimiter after each group of eight characters. What is the delimiter (space, tab, etc.)?

 

If you want help, please attach a small VI that contains a typical string as default data so we get a better idea what this is all about. So far the problem is quite ambiguous.

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

There are actually 2 options Im looking at.

 

The first is just like i wrote. Binary formatted string of 8-bit bytes seperated by a space.

 

The other option. the more preferrable one which i haven't had much luck figuring out it is reading in 48 8-bit bytes continously one after the other. and then sorting and displaying each of them

0 Kudos
Message 3 of 11
(4,370 Views)

@sout23 wrote:

The first is just like i wrote. Binary formatted string of 8-bit bytes seperated by a space.

 


Use "Spreadsheet string to array" with space as delimiter, an integer U8 1D array type, and a binray format specification.


@sout23 wrote:

 

The other option. the more preferrable one which i haven't had much luck figuring out it is reading in 48 8-bit bytes continously one after the other. and then sorting and displaying each of them


This sentence makes little sense? A "fixed size" (48) and "continuously" are contradictory. Sorting by what (e.g. alphabetical by binbary formatted text? Numerically by scanned value?) Displaying each or displaying all? Display how?

 

Message 4 of 11
(4,359 Views)

Sorry, "continously" was a poor choice of words. Basically, i am reading data from a serial port. There are 48 bytes (8-bits in binary format) being "dumped" into a serial port and I have to read them. I am using the VISA read function in Labview to read them all, but this function reads the data as a string not an array. so i have been having trouble trying to figure out how to display each byte seperately.

 

Apologies if this is too confusing.

0 Kudos
Message 5 of 11
(4,351 Views)

I had the same problem, and here's how I solved it:

  • Write a VI called Get One Byte.  Inputs are VISA In (the line associated with your VISA device) and Error In.  Do a one-byte VISA Read, use String to Byte Array to convert to an Array of Bytes, then use Index Array and return the (only) first byte as a U8.
  • Put this Get One Byte function inside a For or While loop with an autoindexing Byte Out tunnel and use it to create the array of Bytes you need.  [I wasn't clear if your array is 48 bytes or 48 bits = 6 bytes).
  • In my case, I was getting 12 bytes that represented 6 I16 quantities, so I passed my array of 12 Bytes into another function that combined the bytes pair-wise into an I16 array, and then did some arithmetic to change the numbers into properly-scaled quantites.

Bob Schor 

Message 6 of 11
(4,311 Views)

Thanks, any chance you could attach a picture or the VI itself?

0 Kudos
Message 7 of 11
(4,299 Views)

Or could you perhaps explain in a little more detail how to use autoindexing Byte Out tunnel and use it to create the array of Bytes you need, and also how you passed the array of bytes into another function that combined the bytes and displayed them. Thanks

0 Kudos
Message 8 of 11
(4,244 Views)

@sout23 wrote:

Or could you perhaps explain in a little more detail how to use autoindexing Byte Out tunnel and use it to create the array of Bytes you need, and also how you passed the array of bytes into another function that combined the bytes and displayed them. Thanks


Sounds like LabVIEW tutorials are needed.   http://www.ni.com/getting-started/labview-basics/

0 Kudos
Message 9 of 11
(4,231 Views)

Tried that before i posted in the forum. 

0 Kudos
Message 10 of 11
(4,218 Views)