ST to ascii binary

O

Thread Starter

Oguz Kaya

In a SLC 504 PLC we are attempting to convert single string character into the ASCII binary equivalent so that we can perform an error checking calculation. We have tried to copy (COP) the ST character into the A character without success. Any help would be appreciated.
 
Can you tell me the exact details that you have used in the COP instruction, like... in the "Source","Destination" and "Length" of the instruction.
Based on your information, i will try to help..
 
T

Troy Stearns

You do not need to move, or copy, this value to perform your check.
Calculations can be performed upon the individual words of a (ST)ring data
type, the same as the (A)scii data type.

"ST10;0.1" is a 16 bit word that contains the first two characters of the
"ST10;0" string. "ST10;0.1" can be an operand in any math instruction that
will handle an iNteger data type. Similarly, "ST10;0.1/0" is a valid
address for any bit level instruction, such as an XIC.

Beware of how RSLogix500 has muddied this. Since the length word is word 0
of the string element, word 1 is represented DATA[0] (e.g. entering st10;0.1
will be displayed as st10;0.DATA[0]).

If you still want to copy the data from string data type to the ascii data
type, you must ensure that thesource and destinations have similar lengths.
Copying one string element requires 42 consecutive ascii elements to
receive. It may be easier to use the move instruction instead (e.g. mov
st10;0.1 a9;0).

Hope this helps,
Troy Stearns
 
Oguz,

If the length of the ASCII string is always the same and the error checking
character is always at the same position, it's easy to use a MOV
instruction to move one Word of the ASCII string (that's two characters)
then use a MVM masked move instruction to select which character you want.

If the length varies or the position of the error checking character
varies, you need to invent a little more logic. Unfortunately, you can't
use indirect addressing on String data positions, so you'll probably have
to copy the whole string into an integer file then address the calculated
position of the error checking character.

For example, if a string element ST9:0 contains the 9-character string
"ABCD1234^X" where the ninth character is 0x18, also known as control-X.

MOV
Source ST9:0.DATA[4]
Dest N7:0

your result in N7:0 will be the value 0x1800 (hex) = 6144 (dec) = "^X\00"
(ascii). If you need to move that character to the right by 8 bits,
divide your N7:0 result by 256. Your destination could also be a Binary
file like B10:0.

Why is the ninth character addressed as offset "[4]"? Because the length
of the STring is calculated in characters (bytes) but offsets in the SLC
operating systems are always bits or words.

In the example string, the ST data type contains the following subelements:
ST9:0.LEN = 9
ST9:0.DATA[0] = AB
ST9:0.DATA[1] = CD
ST9:0.DATA[2] = 12
ST9:0.DATA[3] = 34
ST9:0.DATA[4] = ^X\00

Good luck on your application,

Ken Roach
A-B Seattle
[email protected]
 
T

Troy Stearns

Ken Roach writes

<clip>
If the length varies or the position of the error checking character
varies, you need to invent a little more logic. Unfortunately, you can't
use indirect addressing on String data positions, so you'll probably have
to copy the whole string into an integer file then address the calculated
position of the error checking character.
<clip>

Indirect addressing of words within a String element may be a problem in the PLC5 (I think) but not the SLC. Indirect and indexed ST addresses are possible with the SLC5/03 /04 and /05. If you want, you should be able to
address the calculated position of the error checking character without first moving or copying the data to another file type.

Troy Stearns
 
Top