LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert ASCII string to data array

Solved!
Go to solution

Dear ,

 

I am getting from slave device a ASCII string as below representing hex values

ascii string.PNG

I would like to use the scan from string vi to extract the hex value and group them by word and build a 16 bit arrays.

like Data1= 0817 Data2=0000 ...and last Data= 0040.

I have no idea which attribute to use for the scan for from string vi.

I have tried this but no success.

ascii string2.PNG

Any help?

0 Kudos
Message 1 of 8
(4,776 Views)

Here is some code that converts hex strings to its binary form. A little bit of modifications and you would have what you need.Convert Hex String to Byte Array.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 8
(4,764 Views)

Hi Mark,

 

Thanks for this idea, the problem I would to get rid of the 9 ASCII character SPI1DATA= which %9.s and just group by 16 bits word rather than byte. sO I would like to have U16 bit array with 0817,0000,0000,...,0040 .

Any idea how to get this?

0 Kudos
Message 3 of 8
(4,742 Views)

Typecast the U8 array to a U16 array. Done.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 8
(4,734 Views)

It would be so much more helpful if you could attach a simplified VI (containing correct default data in the control) instead of pictures.

 

Is the value of the string before the equal sign fixed or variable?

Is the hex formatted string after the equal sign of constant length?

Are there any delimiters that are not shown (e.g. a LF at the end?)?

 

Message 5 of 8
(4,729 Views)
Solution
Accepted by topic author malkowki

I would use Match Pattern to detect the '=' and then use a FOR loop to convert the rest of the data into the 16-bit numbers.


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 6 of 8
(4,725 Views)

Hi,

 

>>>>Is the value of the string before the equal sign fixed or variable?

it is an ASCII text protocol which is fixed

>>>>Is the hex formatted string after the equal sign of constant length?

The lenght may vary

>>>>Are there any delimiters that are not shown (e.g. a LF at the end?)?

No delimiter

 

I will post the vi that I have made

 

thanks for your answer!

0 Kudos
Message 7 of 8
(4,695 Views)

Hi,

 

This is what exactly I want. I have also used the typecast plus a delete element array.vi to ignore the first byte of data which are fixed values.

In attachement my working vi.

 

Thanks for your help!

Message 8 of 8
(4,694 Views)