Jump to content

Double word HEX number in ASCII string problem


Recommended Posts

Hi everyone
I need to make a VI that receives 4-byte hexadecimal values as ASCII strings from a CAN-USB interface. I am using an Arduino CAN schield with a firmware that I have not personally written and that I still haven't access to. I do have a problem with the format in which I receive the values. To get the exact value I should add 0 in the middle of the values when missing.
I give an example to explain better.
I get the string:
2 8 D5 0 0 0 0 B 5 70 <CR><LF> (value: 46448)
I'd like to interpret it as:
2 8 D5 0 0 0 0 B 05 70 <CR><LF> (value: 722288)
I'll give another example.
I get the string:
2 8 D5 0 0 0 0 B 4 5 <CR><LF> (value: 2885)
I'd like to interpret it as:
2 8 D5 0 0 0 0 B 04 05 <CR><LF> (value: 721925)
The maximum value I can read in this case is 1000000 in any case.

After I have added the zeros where needed in order to have always groups of two characters I can make something as in the attached VI to get the number that I am looking for.
Does anyone have an idea what algorithm I can use? Thank you!

ASCII-HEX.vi

Link to comment
12 hours ago, Lucky--Luka said:

To get the exact value I should add 0 in the middle of the values when missing

I don't think so.

12 hours ago, Lucky--Luka said:

4-byte hexadecimal values

12 hours ago, Lucky--Luka said:

2 8 D5 0 0 0 0 B 5 70 <CR><LF> (value: 46448)

this should be (byte) grouped as

28 D5 00 00 B5 70

that's 6 bytes. I expect the last 4 bytes are the value so the first two (28 D5) are some sort of header. 00 00 B5 70 = 46448 so that seems reasonable.

So. doing the same for your arbitrary insert...

12 hours ago, Lucky--Luka said:

2 8 D5 0 0 0 0 B 05 70

28 D5 00 00 (but what about the B?) 05 70.

since 722288 = 00 0B 05 70 we have [with our arbitrary insert]

28 D5 00 00 0B 05 70.

But that means we how have 7 bytes and have a 3 byte header instead of 2.

Adding a 0 arbitrarily is not the solution here. You need to look at how you (the human) are understanding the data from the Arduino again.

Link to comment

More information is needed.  Is this a response to an ISO 15765 request?  UDS, KWP2000, etc.  Or is this periodically broadcasted frames?  If it is UDS or something similar you'll need a CDD file to define how it should interpret the response.  If it is a periodic message then a DBC file will define the structure of the data being sent, and what IDs belong to what data.  I cover the Signal API and how bits can be interpreted in Part 5 of my CAN blog, and I talk about multi frame messaging in Part 8.  If you are trying to reverse the CAN bus without this information, then I suspect you will have a very difficult time.  There is an IEEE Float Data Type in the XNet Database editor which uses 4 bytes so it is possible this will do what you want.  I'd make a database using the XNet Database editor specifying where in the frame the bits are and try using the conversion API with it.

EDIT: Also I think Shaun is incorrect. 

2 8 D5 0 0 0 0 B 5 70

I'm unsure what the 2 means but 8 means there are 8 bytes to read and the 8 bytes are D5 00 00 00 00 0B 05 70.  8 bytes is a common payload length for CAN.

Double Edit: What are your expected values? I ran them through the IEEE conversion and tried Big/Little Endian but ended up with really large numbers both negative and positive.

Link to comment
  • 2 weeks later...
On 6/5/2023 at 11:18 PM, Lucky--Luka said:

Hi everyone
I need to make a VI that receives 4-byte hexadecimal values as ASCII strings from a CAN-USB interface. I am using an Arduino CAN schield with a firmware that I have not personally written and that I still haven't access to. I do have a problem with the format in which I receive the values. To get the exact value I should add 0 in the middle of the values when missing.
I give an example to explain better.
I get the string:
2 8 D5 0 0 0 0 B 5 70 <CR><LF> (value: 46448)
I'd like to interpret it as:
2 8 D5 0 0 0 0 B 05 70 <CR><LF> (value: 722288)
I'll give another example.
I get the string:
2 8 D5 0 0 0 0 B 4 5 <CR><LF> (value: 2885)
I'd like to interpret it as:
2 8 D5 0 0 0 0 B 04 05 <CR><LF> (value: 721925)
The maximum value I can read in this case is 1000000 in any case.

After I have added the zeros where needed in order to have always groups of two characters I can make something as in the attached VI to get the number that I am looking for.
Does anyone have an idea what algorithm I can use? Thank you!

ASCII-HEX.vi 6.73 kB · 2 downloads

Posted on the dark side too and answered there quite extensively. https://forums.ni.com/t5/LabVIEW/Double-word-hex-string-to-number-format-problem/m-p/4309006

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.