02-02-2006 06:43 PM
02-02-2006 07:07 PM - edited 02-02-2006 07:07 PM
Just yesterday somebody posted another question kinda like this, the solution of which involved a nifty use of the Type Cast function. Turns out that function can help you out too. Check out the attached VI (saved in LabVIEW 8.0). Screenshot is below in case you don't have 8.0.

Hope this helps,
-D
Message Edited by Darren on 02-02-2006 07:08 PM
02-02-2006 08:20 PM
NewMachine a écrit:
why doesn't this vi work? i am receiving 3 hex bytes from a board, and i need to view it as a numerical value. i know that the hex "F9FFFF" is equal to 16,383999 when i look at it on the calculator.
02-02-2006 08:38 PM - edited 02-02-2006 08:38 PM
Yeah yeah, so I sorta skimmed the original post. All I really saw was "F9FFFF" and "16383999" and I started coding. Turns out I love numbers almost as much as I love LabVIEW. 🙂
-D
Message Edited by Darren on 02-02-2006 08:38 PM
02-02-2006 08:50 PM
02-03-2006 05:44 PM
02-03-2006 05:49 PM
You said you received 3 bytes. In your vi, you process an ascii string, recovering the first 3 chars (not bytes !..),-------------------------------------------------------------but i was told when i use a string subset function and the input is hex code it reads two characters at a time, for one byte. i know it is coming back as hex from the board because when i put an indicator down....it is hex that is displayed.i made both of the changes as suggested by you below and then type in F9FFFF and am returned 0. what should i do?thanks.....samantha-------------------------------------------------------------then you convert this substring into a single byte (the constant you wired to the Hex String To Number bottom input is an U8 !..). There are 2 confusions here : one is that the string input of the HSTN function should have been 6 digits long since, as explained in the help, it "interprets the characters 0 through 9, A through F, [...] as a hex integer and returns it in number. The second is that you should have wired an U32 or I32 as numeric input.
02-03-2006 05:50 PM - edited 02-03-2006 05:50 PM
and what if i want to convert more or less than 3 bytes? i have one stupid byte that i try to convert using something like the attached vi...and it it doesn't return anything correct
please help
Message Edited by NewMachine on 02-03-2006 03:55 PM
Message Edited by NewMachine on 02-03-2006 03:55 PM
02-03-2006 07:46 PM
02-03-2006 09:58 PM - edited 02-03-2006 09:58 PM
Hi NewMachine,
You can use a clever trick with the Concatenate Strings function to append a variable number of pad bytes on the beginning of your string, depending on its length. Here is a screenshot of a VI that does this...it will pad the appropriate number of bytes onto the beginning of the string, so you can have 0, 1, 2, 3, or 4 bytes of hex in your string, and the value will always be converted appropriately.

Hope this helps,
-D
Message Edited by Darren on 02-03-2006 09:58 PM