LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert 1 byte hex number to numeric text

Solved!
Go to solution

This should be simple, but the answer so far eludes me.

 

The problem is I am building a string of ASCII characters to send on a serial connection. The manufacturer uses an XOR checksum resulting in a 1 byte number which needs to be concatenated onto the ASCII string. And here's the catch, it needs to be exactly the number so if the checksum = 73 then they expect a string as such: (SVF,10.0)73 (hopefully I put the correct checksum value for the internal string between () ). It cannot be the hex value or ASCII equivelent, must be the number as text. Here's another example: (NUC)58

 

My checksum generates the correct values which I compared against manufacturers example and another person's C++ code who worked with the equipment for another project, but I have not figured out yet how to make the number value end up as text.

 

Any suggestions?

 

-- Bill

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

Assuming your 1 byte number is U8 or I8, all you need is typecast (leave the type input disconnected). The resulting string is what you want to append to your string (use hex display to verify).

0 Kudos
Message 2 of 7
(3,417 Views)
Solution
Accepted by ngc6193

Hello NGC3123,

 

I think what you're looking for is the Format Value function. This should allow you to append your integer to the string according to whatever format requirements you have.

 

Regards,

Tom L.
Message 3 of 7
(3,414 Views)

@0utlaw wrote:

I think what you're looking for is the Format Value function. This should allow you to append your integer to the string according to whatever format requirements you have.


You are probably right. I misread the question.

 

Of course this makes the checksum a variable width field (1..2 characters: 0..FF in case if hexadecimal, or 1..3 characters in decimal (0..255)).

Your example number don't show what format it should be. If hexadecimal, you might have to pad with a leading zero to make it always 2 digits. Check the documentation.

 

"It cannot be the hex value or ASCII equivelent, must be the number as text"

 

not sure what that really means, but does that mean the number should be decimally formatted? (that's the key word we are looking for) 😄

 

0 Kudos
Message 4 of 7
(3,412 Views)

@altenbach wrote:

@0utlaw wrote:

I think what you're looking for is the Format Value function. This should allow you to append your integer to the string according to whatever format requirements you have.


Your example number don't show what format it should be. If hexadecimal, you might have to pad with a leading zero to make it always 2 digits. Check the documentation.

 

 


 

-Edit- For some reason the rest of my post got scrubbed (twice).  Here it is again:

 

Good call- you should be able to use a format specifier string with a leading "0<width>" to pad with zeroes as needed when using the Format Value function.  "%03d" will produce an unsigned decimal integer padded with zeroes to meet a minimum width of three, for example.  "24" becomes "024", etc. Whether or not you need this depends on your format requirements.

 

I think the OP's intent is to append a decimal integer string for serial communication purposes; I agree that clarification would be good.

Tom L.
0 Kudos
Message 5 of 7
(3,397 Views)

So Tom was the closest on what had to happen. I had already gone down the path of type cast, then tried converting the type cast, and it ended being really simple. About 10min after posting my message, I was tired, back in my lab, and it suddenly dawned on me to remove the type cast and try doing a number to string conversion whcih ended up providing exactly what was needed.

 

This company has deviated from what they previously did on cameras we pruchased in the past, that code was very straight forward, but as we have seen in the past, just when you get comfortable with the way things work someone decided to do something different. I discovered another contractor to us who wrote C++ code still doesn't have this working correctly for their equipment platform. If interested, I can drop snippets of both the non-working code and the fixed code here for posterity.

 

Thanks to all for replying, glad to see there's people out there willing to help at a moments notice.

 

-- Bill

0 Kudos
Message 6 of 7
(3,363 Views)

Always glad to help!

 

If you're interested in making your working code available for other LabVIEW programmers, I'd suggest taking a few minutes and posting it as an example on the NI community here:

 

NI Developer Community Home 

https://decibel.ni.com/content/community/zone

 

Regards,

 

Tom L.
0 Kudos
Message 7 of 7
(3,337 Views)