5 posts in this topic

I need to know if there is an easy way to convert a hex value to ascii without going through all of the math. In the ContolLogix 5000 software, I can find how to do a string to decimal (STOD), but the problem is the initial value. For example, the hex value for ASCII 3 is 31, ASCII 4 is hex 32, etc... If I do a STOD to create a string from the value of hex 31, I get a string of: '31'. I need to send this value out to hyperterminal and read a 3, not 31.

If it was only reading one source and did a simple subtract and mov commands for the values of 0 through 9, that would not be a problem. However, my problem is that I am continuously reading multiple valuses from several sources and I don't want to have to write the code for each character from each source. I could do and AOI or UDT, but isn't there a simple instruction in the logic?

Edited by randm220
Correcting initial hex values

Share this post


Link to post
Share on other sites

Your post is a little confusing but Hex is ASCII. Are you sure of the data type you are starting with? Try sending it to HyperTerminal without any conversion.

RS_ASCII.jpg.3049ec72e5e12ef89e39ff2e7b2

Share this post


Link to post
Share on other sites

On the monitor screen you are showing only relates to how you are seeing it (to the best of my knowledge), not what the processor sees. The data is coming in as hex and I need to export it as ASCII.

Share this post


Link to post
Share on other sites

From what i have read so far, I think you may be overthinking this, just send the raw hex values with no conversion, like IO_Rack said.

Hyperterminal reads Hex 31 as Ascii '3'

If you're sending a string, just populate the String.Data[x] fields with your hex values using COP, and set the length of the string (String.LEN) manually.

 

 

Share this post


Link to post
Share on other sites
On 3/2/2016 at 5:18 AM, randm220 said:

I need to know if there is an easy way to convert a hex value to ascii without going through all of the math. In the ContolLogix 5000 software, I can find how to do a string to decimal (STOD), but the problem is the initial value. For example, the hex value for ASCII 3 is 31, ASCII 4 is hex 32, etc... If I do a STOD to create a string from the value of hex 31, I get a string of: '31'. I need to send this value out to hyperterminal and read a 3, not 31.

If it was only reading one source and did a simple subtract and mov commands for the values of 0 through 9, that would not be a problem. However, my problem is that I am continuously reading multiple valuses from several sources and I don't want to have to write the code for each character from each source. I could do and AOI or UDT, but isn't there a simple instruction in the logic?

This might be nothing more than a cheap parlor trick but

If you divide 31 by 10 and feed that to a TRN (truncate) it will return a 3...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now