Sign in to follow this  
Followers 0
RFurey

Copying A String Tag

11 posts in this topic

What would be the preferred way to copy the ASCII contents on one string tag address to a second string tag address in Contrologix? I want to overwrite the contents of the second string tag. I’ve tried the COP instruction but there are some odd results when one of the tags is in an array. example: tag name is RECIPE_NOTES[3]

Share this post


Link to post
Share on other sites
Are you specifying RECIPE_NOTES[3] or RECIPE_NOTES[0].Data[0] You should specify RECIPE_NOTES[0] and a length of 1 This is assuming the we are talking about String data types and not Ascii strings in other types of data files Edit - What type of odd results are you getting? Edited by TWControls

Share this post


Link to post
Share on other sites
I have an array I call RECIPE_NOTES[20] In this array there are 20 individual addresses where I can store misc info on each recipe, each address is 82 characters long. I have another string tag called RECIPE_NOTES_HOLD. I wish to copy the contents of RECIPE_NOTES_HOLD into one of the array addresses, say RECIPE_NOTES[sELECTED_RECIPE]. In this case SELECTED_RECIPE would be 3. When I toggle ON the rung with the COP instruction, RECIPE_NOTES[3] changes to what is in RECIPE_NOTES_HOLD as would be expected. However the contents of about half of the following tags in the array get erased (I pre-enter numbers into them to see what would happen), the other half get changed to a string that looks something like this - $07$00$00$80...etc, filling the 82 characters with what looks like ASCII gibberish. I’ve trial and error-ized this to death, so I’m fishing for some help at this point.

Share this post


Link to post
Share on other sites
Aha! I bet you used the COP without specifying the .DATA[x] and without MOVing the .LEN! (I suffered my own trial and error on this one.) So you should have something like this: COP {RECIPE_NOTES_HOLD.DATA[0] RECIPE_NOTES[sELECTED_RECIPE].DATA[0] length: 82} ALSO MOV {RECIPE_NOTES_HOLD.LEN RECIPE_NOTES[sELECTED_RECIPE].LEN} SIDE NOTE: if you are displaying string tags on panelview, make sure you FLL the display tag with zeros (null characters) as a step before the COPy, because the panelview does not look at the .LEN to determine string display size! So any garbage left over in the string tag is displayed if your overwrite data is smaller than the previously displayed data. (for cases where .LEN is less than 82) As an alternative, you can simply use the UPPER instruction to do a direct string to string copy, but of course everything goes uppercase ((That graphic for TWControls freaks me out!)) Edited by pseudoquas

Share this post


Link to post
Share on other sites
Can't believe you don't like my graphic

Share this post


Link to post
Share on other sites
That did it. Thankyou! It's funny, but I don't have to use the .DATA or .LEN when COP from the array string tag back to the individual string tag. I'm not sure why or how, but it's working so that's half the battle.....

Share this post


Link to post
Share on other sites
I'm a little confused. I copy String tags out of arrays into indiviual string tags all the time without specifying the .Data[0] and putting a length of 1 in. Is the array and individual tags both actually a string data type? What length were you putting in?

Share this post


Link to post
Share on other sites
I have a tag array called RECIPE_NOTES. The data type is STRING[20]. I also have an individual tag called RECIPE_NOTES_HOLD. It’s data type is STRING. I had no problem using the COP instruction to copy a string from one of the array elements (example: RECIPE_NOTES[SELECTED_RECIPE]) to the individual tag, RECIPE_NOTES_HOLD. COP Source RECIPE_NOTES[SELECTED_RECIPE] Dest RECIPE_NOTES_HOLD Length 82 However reversing things like this did not work. COP Source RECIPE_NOTES_HOLD Dest RECIPE_NOTES[SELECTED_RECIPE] Length 82 The 82 was the default length of a string in the string browser. I’m assuming it came from the Read/Write Buffer Size in User Protocol, Controller Properties. The following does work, (via pseudoquas) COP Source RECIPE_NOTES_HOLD.DATA[0] Dest RECIPE_NOTES[SELECTED_RECIPE].DATA[0] Length 82 MOV Source RECIPE_NOTES_HOLD.LEN Dest RECIPE_NOTES[SELECTED_RECIPE].LEN I don’t know why. I can’t find anything in the Help Contents to explain this. I’d be interested in hearing an explanation, if anyone has one.

Share this post


Link to post
Share on other sites
Your first method should work with a length on 1 instead of 82. A copy instruction in RsLogix 5000 requires you to specify the number of ELEMENTS to copy. This is actually something that is commonly misunderstood about RsLogix 5000. If you specify RECIPE_NOTES_HOLD then your element type is a string so a length of one will copy the whole string. If you specify RECIPE_NOTES_HOLD.Data[0] then your element type is a SINT and you must specify 82 to copy all of the SINTs. Either way will work but the first method will copy your length which you may find you need later. There are many times you will find you need the length The reason you were getting unpredicable values when copying your single string to your array string is because your length was greater than your source. In the help section under copy it states the following A string is 88 bytes so by specifying 82 for your length your byte count was 7216. Pretty much it was looking to copy 82 strings. To show you what I am talking about 1. Create 2 strings, STRING1 type STRING[20] and STRING2 type STRING[20]. 2. Now do a copy with a Source of "STRING1[0]", a Destination of "STRING2[0]", and a length of 5. 3. Then put a value into STRING1[4]. This is the last element that is copied. 4. Look at STRING2[4] and you will see the value that you put in STRING1[4]. 5. Now put a value into STRING1[5]. This element will not be copied 6. Look in STRING2[5]. You will not see the value that is in STRING1[5] The big thing to remember when using a copy command is that the length is not the number of SINT, DINT, etc. It is the number of Elements of the Data Type specifed by your source element that you wish to copy

Share this post


Link to post
Share on other sites
Thanks, TWControls. Now I know the how and why. This battle is over. On to the next one...

Share this post


Link to post
Share on other sites
Glad to help. I was copying multiple strings out of one array to another array. Thats when I discovered it and I know it drove me crazy

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
Sign in to follow this  
Followers 0