07-21-2010 02:06 PM - edited 07-21-2010 02:07 PM
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
Solved! Go to Solution.
07-21-2010 03:09 PM
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.
07-21-2010 03:50 PM
Oof...sorry. I posted the wrong gifs. Those were where it was to be integrated.
Attaching the VI as well.
07-21-2010 03:54 PM
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.
07-21-2010 03:58 PM
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.
07-21-2010 03:59 PM - edited 07-21-2010 04:03 PM
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"?
07-21-2010 04:10 PM
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.
07-21-2010 04:15 PM
@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.
07-21-2010 04:23 PM
@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].
07-21-2010 04:26 PM
This might help: