LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extract word from string

Hello,

I have quiet an easy thing to do which I don't get working...
I hope you can help!

I read in a string from the com port from a DSP. The string contains e.g. 16 data words, each consisting of 2 bytes. So there I have the 32 byte string in LabView. Now I want to display all the 16 numbers in a xy-chart, so I need to extract the words from the string and convert them to numbers.

I use the string subset function to extract 2 bytes with an incrementing offset in a For Loop a 0000 002 is appended at the beginning of each word.

So I use the string to number conversion with an offset of 4 bytes to cut this off again, but it does not work I get only 0000 out at the end (look at the pictures).

Thanks for any help!

0 Kudos
Message 1 of 7
(4,528 Views)
here are the pictures
Download All
0 Kudos
Message 2 of 7
(4,527 Views)
Would this do what you need?

Unflatten from string data to a 16-bit array, and graph the array.





B-)


Message Edited by LabViewGuruWannabe on 11-19-2007 02:47 PM

Message Edited by LabViewGuruWannabe on 11-19-2007 02:48 PM
Download All
Message 3 of 7
(4,484 Views)
Yyyyyyyyyyyyyyyyyyeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssssssssssssssssssss   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thank you so much, I was new to LabView and working since 2 days on this easy thing, now it finally works !!!!!!!!
0 Kudos
Message 4 of 7
(4,451 Views)
Hi Martin,

there's (atleast Smiley Very Happy) a big flaw in your conversion routine:
first you cut 2 chars from string (and even note that in a comment), then you want to convert those 2 chars but apply an offset of 4 chars! That's why you always get "0000" as result!
When you already cutted the needed chars from a string you don't need to apply an additional offset in the "to number" conversion...



Message Edited by GerdW on 11-20-2007 11:08 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(4,438 Views)
Your right, but the function I use to cut off the 2 characters appends 0000 0002 at the beggining of each word which is cut off, so it spits out 4+2 bytes instead of only the 2 I cut (I think its the standard size information, cause it changes with the number of bytes I cut to 0x3, 0x4, ... ). You can see the appended bytes in the picture of the front panel in String 2. Thats why I used an extra offset. As it did not work I also tried without that offset, but no difference...

Anyway the solution of LabViewGuruWannab works, although I'd like to know why mine does not...

Thanks for the answer!
0 Kudos
Message 6 of 7
(4,434 Views)
Hi Martin,

no, the "string subset" function doesn't add any characters! It's the "flatten" function that adds the additional chars (it's the string length that gets added before the actual string data!).

So may advice is still true: You handle the offsets wrong in your conversion routine!
See the attached vi - it's not as efficient as Guru's but it works with standard "string subset".


Message Edited by GerdW on 11-20-2007 02:22 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 7
(4,414 Views)