ML1200 Help with HEX in ST9 file

Kyle Grathwol

Member
Join Date
Dec 2005
Location
Sandusky, Ohio
Posts
129
Good Evening Gentlemen,

I am reading in a string into a ST9 file. The string has variable HEX charachters. I am extracting the four digits to another ST9 file. From there I need to convert them to integers. Convert ASCII to integer won't work because it is not ASCII and it skips over the letters of HEX.

The incoming data is HEX because I am pulling it off of a CAN bus and running it through a CAN to RS232 converter. I am filtering the string that I want to read in this converter and sending it in the ML1200 at channel 0. The string comes in just fine but it is hex and I need to read it as an integer.

Any ideas?

Thanks for your help.

Kyle
 
It would be helpful to have an example of the contents of your string file.

I think you're going to have to manually do sixteen "EQU" statements in a subroutine that acts on each byte of the string, once you separate out each byte (character) of the string into it's own Integer register.
 
The string file looks like :s187n0F88000000000000;

I am only concerned with the 8 positions after the "n" which is OF880000.

I thought about the EQU instruction but it would not let me use letters. How do I have it look at an A and move a 10 into a file if it sees an A?

Thank you for your time Ken.
 
Setup 16 strings with 0 to F entered into them, use these constant strings in your compares, then when they are equal, move the correct value to your integer location.

Not elegant, but should work.
 
The characters in a string are packed 2 per word. The first character in the string is stored in its ASCII form in the lower byte of the word while the second is in the upper. So the string ABCDEF would look like:

In ASCII - BA DC FE
In Hex - 4241 4443 4645
In decimal - 16961 17475 17989

So you wonder - how do I get anything from that?

In Kyle's case, the relevant data starts at ST9:??.DATA[3] and continues to DATA[6]. We start with our answer initially equal to zero.

Step 1 - Answer = 0
The next step may seem weird but bear with me

Step 2 - Answer = Answer * 16
In each word we must strip off the lower HexASCII character using the AND function

Step 3 - Lowest character = DATA AND 0HFF
The "0HFF" is the hexadecimal representation. In decimal it would be 255

Now that character will be either the number 0-9 or the letters A-F. A simple conversion from known HexASCII (Ha hex number represented as an ASCII character) to hex is

Step 4a - Hex = HexASCII - 48
Step 4b - If Hex > 9 then Hex = Hex - 6
We add this to our answer

Step 5 - Answer = Answer + Hex
Now the next HexASCII character must be stripped from the top of the word

Step 6 - Higher character = DATA AND 0HFF00
But that leaves the character shifted to the left so we must do

Step 7 - Higher character = DATA / 256
Now perform the HexASCII to Hex conversion on this part.

Step 8 (Do functions from steps 4a,b)
The answer must be shifted up by 16 in preperation for adding this next value.

Step 9 - Answer = Answer * 16

Then add in this newest value

Step 10 - Answer = Answer + Hex

Now do steps 2 through 10 for the other dual character string positions.
 
Hi Bernie,

Thank you for the detailed reply. I am sure that what you wrote will work but I have absolutely no idea on how to pull that off--how to actually write the logic to make happen what you are describing. I am a novice with PLC's and I don't recall seeing anything with the text "ANSWER =". I have attended AB's programming and advanced programming classes for RSLogix and I read anything I can get my hands on but I am lost as to what you are describing.

Can you go into more detail or point me to a book or article that will help me understand? I am having difficulty getting the four numbers/letters out of the ST9 file into a file that I can do anything with them.

Thank you very much for your time.
 
For ascii equivalent of the EQU instruction, try ASR (ASCII String Compare).

Bernie lost me with the rest of his solution...maybe he'll pop back in and help with the translation to RSLogix500.

Good Luck!
Paul
 
I'm preparing an RSS now. Sorry, I assumed an access to the string would be by full words. It's not, so it's actually simpler. But unfortunately the MLX1200 doesn't allow indexing into strings so it has to be a linear sub instead of a loop0-ing one. Program to follow.
 
And here's guess #2. Funny how RSLogix didn't complain about ANDing on string data when I verified the individual rung or file but it did when I verified the whole project.
 
I am looking at the zip file you sent me now. I will have to look it over all weekend to figure it out. Thanks for taking the time to actually write out the logic.
 
Hi Bernie.

This project got resurrected recently and I used your thought process to solve it. I did it a little different but it was your advice that got me started in the right direction.

Thank you again for your time and help.
 

Similar Topics

I am using Modbus to read 36 registers from a ML1200. 2 of those registers are suppose to be L11 data and 2 of the registers are F8 data. Long...
Replies
3
Views
1,373
Hi folks, I am wondering if you guys can help me understand what the intended operation was for some logic that relates to the operation of the...
Replies
3
Views
1,619
Hello everyone, M using micrologix 1200 and it is connected to net-aic using pm02 cable, then net-aic is connected to my laptop using pm02 and a...
Replies
15
Views
3,937
Ok, I have done extensive reading on this website and in AB publications and I cannot figure this one out. I am attending school and expanding my...
Replies
6
Views
4,862
Hey all! Long time reader, first time poster! I have an EA9-T7CL and an MicroLogix 1200 connected via DF1. I'm all good and got everything mostly...
Replies
3
Views
648
Back
Top Bottom