LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ascii versus hex

Solved!
Go to solution

I am trying to send a command to control a piece of hardware via RS 232 and unfortunately it requires hex manipulation.  --- I know nothing about this.

I have an example VI attached to help explain my problem.  The example shows my ASCII command string converted to a hex string.  I need to calc the checksum and then include that back into the ASCII string.  I have been able to calc the checksum (I think) by converting the ASCII string to a numerical array and do the addition. But, I have to send in the hex value via a Normal Display string.  When I try to convert the HEX display to the Normal Display I converts back to the ASCII representation.  The only way to accomplish this is to manually enter the hex representation into a Normal Display string. 

Very frustrated, when doing this research I find there are many descriptions to do this all of which gives me different answers.

Can someone look a my example and tell me how to fix this (I don't want to type in this string each time).

0 Kudos
Message 1 of 7
(2,737 Views)

Please upload the section of the manual that describes the communication and checksum calculation.

 

I had a look at your VI, but I am not clear on what the actual result needs to be.

 

0xDEAD

0 Kudos
Message 2 of 7
(2,707 Views)

I'm going to start with an old joke.

 

Why do programmers wear costumes on Christmas?

 

Because Dec 25 is Oct 31!

 

Changing the representation of the array of U8s that are characters does not change the values the computer sees.  It only changes how the control or indicator displays that exact value


"Should be" isn't "Is" -Jay
Message 3 of 7
(2,701 Views)

This sounds fairly similar to a piece of hardware that I've worked with in the past.

I'm attaching some snippets showing how I set a temperature value, but as deceased mentioned a copy of the manual along with desired inputs and outputs would be best to get useful help here.

For my code, I needed an LRC check.

Set TemperatureSet TemperatureMessage BuilderMessage Builder

LRC CheckLRC Check

I'm not sure if this helps or not, but hopefully if not the manual will allow a better suggestion.

 

Edit: As a side note, if I rewrote this now, I'd probably consider a few more enums and fewer similar VIs specifying different string constants. You might be able to create a nicer API if you plan all of your operations first, and try and eliminate "magic numbers". Further, you can see here that the Message Builder takes a cluster including 'data' as the last element, but then just concatenates them all into a single string - this could be replaced by a concatenate string node in the caller.


GCentral
Download All
Message 4 of 7
(2,673 Views)

Per some of the responses to my original posting I wanted to update my sample VI to help clean up and illustrate my question.  To start I want to be able to calculate the checksum of a HEX string and this is where I get conflicting results depending on the implementation.

 

In my sample I am converting an ASCII string to a hex string simply by changing the display choice - which is giving me a correct representation.  I am also manually typing in a Normal display representation of that same HEX string.  I am then calculating a checksum of both.  The checksum of the Normal display is correct (26)  but the checksum of the Hex Normal display is wrong (33).  So.... how do I get the checksum of 26 using the Hex display version.

0 Kudos
Message 5 of 7
(2,654 Views)
Solution
Accepted by topic author irfocus

Convert your String to a binary Array then do your processing.

 

Snap61.pngSnap60.png

mcduff

 

 

Message 6 of 7
(2,650 Views)

Thank You MCDUFF.  It sounds ridiculous but I have been doing this for 30 years as an ME but this is the first time I have to communicate with a device via RS232 through hex rather than ascii.  Who invented this HEX crap anyway?

0 Kudos
Message 7 of 7
(2,643 Views)