LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting hex string to number (not working)

Solved!
Go to solution

Hi prhs,

 

the error is due to your failure! 😄

 

You did not follow ALL of my suggestions as you used an I32 constant to define the datatype at the Deserialize function! In my snippet above I used a U16 and in the message I clearly mentioned to use U16 or I16

 

Why didn't you just used my snippet?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 11 of 14
(891 Views)

@GerdW wrote:

Hi prhs,

 

the error is due to your failure! 😄

 

You did not follow ALL of my suggestions as you used an I32 constant to define the datatype at the Deserialize function! In my snippet above I used a U16 and in the message I clearly mentioned to use U16 or I16

 

Why didn't you just used my snippet?


you're right!!!  i just changed it and it worked fine.  i didn't use the snippet because my computer, somehow, doesn't deal with them properly.  i am using chrome but i tried explorer and when i drag it in explorer, it just gives me the name and place of the snippet whereas in chrome, i drag  it onto the desktop and then into labview and it just gives me non-working picture of the thing.  thanks!!!

 

by the way, why does the length of the number make such a difference?  shouldn't it just add a bunch of zeros?  probably a dumb question; but, hey, i may as well ask someone who clearly knows!

thanks!

0 Kudos
Message 12 of 14
(877 Views)

@prhs wrote:
 

by the way, why does the length of the number make such a difference?  shouldn't it just add a bunch of zeros?  probably a dumb question; but, hey, i may as well ask someone who clearly knows!

thanks!


If you would do proper error handling you would see that the Unflatten from String function returns an error because the passed in byte stream (string) is to small to satisfy the requirement of the passed in datatype. The Unflatten from String (unlike the Typecast) has error terminals and therefore uses them to properly handle just about any possible error that you can cause.

 

A function returning an error will usually not perform any other operation and all the other terminals will normally simply return the default value for the datatype and not some intermediate wrong value.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 13 of 14
(854 Views)

@prhs wrote:

@GerdWby the way, why does the length of the number make such a difference?  shouldn't it just add a bunch of zeros?  probably a dumb question; but, hey, i may as well ask someone who clearly knows!

Rolf basically answered your question, but for the answer to "stick" with you, I recommend you "play scientist" (or "Test Engineer") and do a little experiment:

Unflatten Error.png

I suggest you put the number 1234 in the U16 Control, and before running the code, "predict" what the String should be.  As you already know from doing the Unflatten first "incorrectly" and then "correctly", the (correct) U16 Out will show the input number, and the U32 Out will show 0 (always).

 

Go and Use Those Error Lines (they are there for good reasons)!

 

Bob Schor

0 Kudos
Message 14 of 14
(836 Views)