LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Double word hex string to number format problem

Hi everyone
I need to make a VI that receives 2-byte hexadecimal values as ASCII strings from a CAN-USB interface. I do however 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 is 1000000 in any case.
Does anyone have an idea what algorithm I can use? Thank you!

 

p.s. there is an error: it's double word HEX: 4 bytes HEX not 2 bytes HEX

0 Kudos
Message 1 of 7
(1,195 Views)

@Lucky-Luka wrote:

Hi everyone
I need to make a VI that receives 2-byte hexadecimal values as ASCII strings from a CAN-USB interface. I do however 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 is 1000000 in any case.
Does anyone have an idea what algorithm I can use? Thank you!


This doesn't sound right to me.  Could you upload the documentation that describes the communications?  I mean, how are you supposed to determine if a zero is "missing"?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 7
(1,188 Views)

With two bytes, you can only go up to 64k (2^16), not 100k.

 

Your examples are pure gibberish. Can you attach a VI that contains the exact received strings as e.g. diagram constant. What is the display style of these strings?

0 Kudos
Message 3 of 7
(1,185 Views)

Hi luka,

 


@Lucky-Luka wrote:

Hi everyone
I need to make a VI that receives 2-byte hexadecimal values as ASCII strings from a CAN-USB interface.


Please supply the dbc file that defines that message!

Why are there 10 values for a "2 byte value"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(1,179 Views)

@billko  ha scritto:

I mean, how are you supposed to determine if a zero is "missing"?

If I see just 1 character I have to add a zero at the beginning in order to have two characters.

After that I can remove the spaces and obtain the value of interest as in the attached VI.

0 Kudos
Message 5 of 7
(1,173 Views)

@Lucky-Luka wrote:

@billko  ha scritto:

I mean, how are you supposed to determine if a zero is "missing"?

If I see just 1 character I have to add a zero at the beginning in order to have two characters.

After that I can remove the spaces and obtain the value of interest as in the attached VI.


I don't buy it.  I would be inclined more to think something is wrong with the way you are receiving the messages, and you think sometimes there is only one byte.  If a data type is specified in the output, you can bet that your output will always have the correct amount of bytes to represent that data type.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 7
(1,141 Views)

@Lucky-Luka wrote:

@billko  ha scritto:

I mean, how are you supposed to determine if a zero is "missing"?

If I see just 1 character I have to add a zero at the beginning in order to have two characters.

After that I can remove the spaces and obtain the value of interest as in the attached VI.


Nope! Just treat is as a space separated spreadsheet string of hex numbers “%x” converting it into a 1d array of unsigned 8bit integers!

 

Then Typecast or Unflatten the last 4 bytes into an uint32 number.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 7
(1,113 Views)