LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I load a list of hex numbers into an unsigned 8 array?

Solved!
Go to solution

Hello!

I am developing a VI to write a bunch of CAN messages and then do some other stuff with the results.  The problem I am having is that I have a lot of messages and the list of messages can change periodically.  While I can type these all in by hand, I'd like to be able to load a list from a text file.


I've tried reading data from a text file and converting the strings to hex, but this just converts the actual string into hex and does not read the literal value. 

 

Is there a way to pull hex values from a text list and put those literal strings into a U8?

Thanks!
Crystal

Download All
0 Kudos
Message 1 of 17
(3,082 Views)

Your screenshots don't show anything that's actually reading a file. All I see is a Write to Spreadhseet File. Also, you did not post an example of the text file you're trying to read. If I had to guess, I'd say look at the Hexadecimal String to Number conversion function in the String palette. If you want a more specific answer, please post an example of the file you're trying to read.

0 Kudos
Message 2 of 17
(3,062 Views)

Oof...sorry. I posted the wrong gifs. Those were where it was to be integrated.

 

Attaching the VI as well.

Download All
0 Kudos
Message 3 of 17
(3,053 Views)

If the message in the list is 1C24, for example, ultimately I want:

3 22 1C 24 00 00 00 00

 

I realize that 3 and 22 arent in the list, but that's something I would take care of later. 

 

 

0 Kudos
Message 4 of 17
(3,048 Views)

You cannot put non-numeric characters such as 1C into a U8.  U8 is an unsigned short integer of 8-bits.  It is a number.  1C is a string that represents a hex number.  You need to use a string to have the characters you mentioned.  However, it could be that the device you are communicating with wants hex characters that represent a number.  You need to explain more about what your device expects.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 17
(3,042 Views)

You still haven't posted a text file. However, based on the VI, it seems you're reading ASCII characters. Use the function I mentioned before. A loop will not be necessary with that function.

 

Also, the value you're reading from file is 4 bytes (4 characters), but you said you want an array of U8. Then what should this array of U8 be? Does each 16-bit "value" get converted to 2 8-bit "values"?

0 Kudos
Message 6 of 17
(3,038 Views)

tbob: 1C (0x1C) is a valid hex number for a U8 number. A U8 can be anything fromm 0 to FF.

 

 

OP: Convert your string to a U16 number and split it.

0 Kudos
Message 7 of 17
(3,020 Views)

 


@dkfire wrote:

tbob: 1C (0x1C) is a valid hex number for a U8 number. A U8 can be anything fromm 0 to FF.


He was referring to the character "1" followed by the character "C", not the hex value 1C.

 

0 Kudos
Message 8 of 17
(3,015 Views)

@dkfire wrote:

tbob: 1C (0x1C) is a valid hex number for a U8 number. A U8 can be anything fromm 0 to FF.

 

 

OP: Convert your string to a U16 number and split it.


I know 1C is a valid hex number, but the OP showed a string of characters, not numbers.  I guess I'm not sure what he wants.  It looks like he wants to create a string with two hex characters separated by a space followed by two more hex characters, etc...  "3 22 1C 24 00 00 00 00"

Maybe he wants an array of numbers: [3, 34, 28, 36, 0, 0, 0, 0].

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 17
(3,012 Views)

This might help:

19567iC3FB0C1EE9839ED7

0 Kudos
Message 10 of 17
(3,009 Views)