RSLogix: Copying constant to a string?

FNC

Member
Join Date
May 2010
Location
NJ
Posts
84
Hi,

I would like to hardcode a constant to s string so I can use various compare functions.

I have found how to copy a string (ST) to another string. I have, for now, written the value I want hardcoded, in the data table and then done the copy.

I would feel better if I could hardcode it.

If want ST20:10 to be "ABCD", how can this be hardcoded?
 
I don't believe that can be done. There are no literal strings in A/B plcs as far as I know. You could use a data table with the properties set to Constant to ensure nothing can change the data, but you would have to enter the value manually as you have already done.
 
I have in the past moved the ASCII number equivalent of the characters into a string file. I was using RSLogix 5000 at the time, but the same rules apply to COPY and MOVE instructions in 500 if I remember right.

So if you were hard code an INT move, then copy the INT directly to the String, (maybe?) you could set a string character that way?

I don't have the resources available to test it out myself right now.
 
The memory is hazy but, IIRC, it can be done thusly (RSLogix 5):

  1. Make a new program to be run as a subroutine.
  2. In that program preload some integers with the ASCII equivalent of the required characters - MOV 34 N7:0, etc.
  3. MOV the integers to the string via MOV N7:0 ST20:10.[DATAn], where 'n' is the offset into the string. This is the part that's hazy. I think the syntax is correct but I'm not sure. WARNING! To my knowledge this technique is undocumented by A-B.
  4. When all needed values have been loaded, move a literal into the string LENGTH parameter. If you loaded five characters then - MOV 5 ST10:20.LEN.
  5. At startup, call the routine to initialize your values.
 
This is easily do-able, but you need to be aware that each data element of the string data-type holds two ascii characters.

This is because the memory space is 16 bits wide, and ascii codes are only 8 bits wide, so two characters are stored in each 16-bit word.

I suspect that the first ascii character occupies the lower 8-bits, and the second the upper 8-bits, but can't be certain - I might be able to run a test tomorrow.

The correct syntax for accessing the string data is

STff:ee[ww] - note square brackets

where
ff is the string file number
ee is the element number
ww is the word number

If you look at the posted picture, the instruction addresses words 0 and 1 of a string data file.... It returns 2 characters in each case.

Hopefully this info will get you going.... You can populate an Integer with the ascii code numbers of the characters you want (hint : use BTD to put the upper 8 bits into the Integer), the MOV the Integer to the correct element of the string.

Note: you will also need to set the string length (eg. ST10:0.LEN) to the number of ASCII characters if you are poking data into the string

2012-05-24_015126.jpg
 
Last edited:

Similar Topics

I'm not super familiar with the Micrologix line of processors, but I am pretty familiar with RSLogix 500. I'm trying to simply copy a string to...
Replies
4
Views
303
Hello, looking for a way to capture and display the accumulated time for a retentive timer in rslogix 500 on a microligix 1400 plc example move...
Replies
3
Views
1,649
Is there a way to do a mass copy of comments and tag names from one program to another? They are 100% identical, one goes online (uploaded from...
Replies
1
Views
3,148
A rung is set up that goes something like this: If sysMessage > 46 ONS---> Cop SysDisp_message Destination: DatabaseMessageHold Watching it in...
Replies
4
Views
2,310
Hiya, For a machine im using a recipe that has 20 lines. Each line contains a free enter field for the customer to enter whatever into (String)...
Replies
3
Views
6,584
Back
Top Bottom