06-05-2023 03:32 PM - edited 06-05-2023 03:53 PM
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
06-05-2023 03:44 PM
@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"?
06-05-2023 03:44 PM
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?
06-05-2023 03:46 PM
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"?
06-05-2023 03:50 PM
@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.
06-05-2023 04:10 PM - edited 06-05-2023 04:11 PM
@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.
06-05-2023 06:13 PM - edited 06-05-2023 06:18 PM
@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.