LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I scan a unsigned 32 bit integer from a string?

Solved!
Go to solution

I am trying to scan an unsigned 32 bit integer value from a string.  I have tried changing the format string from %d to %u with no luck.  The function keeps returning 0x7FFFFFFF (2147483647) when the hi bit is set.

 

Can the format string be defined such that LabView will read an unsigned 32 bit integer value?

 

Thanks for your help,

Phil

Message Edited by VTPhil on 12-11-2009 10:36 AM
Download All
0 Kudos
Message 1 of 8
(5,446 Views)

Hi Phil,

 

have you opened the context help and read the help for format codes? Then you would have picked %x instead of %u Smiley Wink

 

And you would have read too about the default data input of the ScanFromString function...

And why do you use that local variable when you have an unwired indicator for free???

And you can connect the error cluster directly to the while loop stop terminal...

Message Edited by GerdW on 12-11-2009 05:43 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(5,431 Views)

Gerd,

Thanks for your reply.  Doesn't %X scan hexadecimal values?  My values are actually decimal formatted.  I'm scanning from a file and the values look like:

 

3343385820,
3343385850,
3343385879,

 

Phil

0 Kudos
Message 3 of 8
(5,416 Views)
Solution
Accepted by VTPhil

No, use %d. If you read these numbers as %x, they will overflow. In addition, you need to wire a U32 diagram constant to the "default value" input of "scan from string", else you get I32, which is inusfficient for your data.

 

 

0 Kudos
Message 4 of 8
(5,410 Views)
If you connect a U32 indicator directly to the output of the scan from string, the output of it also changes to a U32 and the conversion is correct. When I convert arrays, I tend to use the Decimal String to Number where there is an input to specify data type.
0 Kudos
Message 5 of 8
(5,406 Views)

Added notes:

 

Overall, your code is overly complicated.

 

  • Why are you writing to a local variable while keeping the indicator disconnected elsewhere? Eliminate the middle man and write to the indicator directly! 🙂
  • Reading a file line-by-line is tedious. Read it once and then parse the resulting string. Here's roughly equivalent code.

 

 

Message Edited by altenbach on 12-11-2009 09:01 AM
Download All
0 Kudos
Message 6 of 8
(5,399 Views)
Thanks altenbach.  The part I was missing was the U32 datagram constant wired into the default value.
0 Kudos
Message 7 of 8
(5,389 Views)

Dennis Knutson wrote:
If you connect a U32 indicator directly to the output of the scan from string, the output of it also changes to a U32 and the conversion is correct.

Unfortunately, it does not propagate back across tunnels as in the code at hand, thus we need to wire the a diagram constant of the correct datatype (e.g. U32) to the default value input anyway.

 

Still, as I said earlier, there are better ways to do all that... 😉

 

Message Edited by altenbach on 12-11-2009 09:10 AM
0 Kudos
Message 8 of 8
(5,385 Views)