Sign in to follow this  
Followers 0
waterboy

ST Syntax Error

8 posts in this topic

I am trying an experiment. I have this FLL working in ladder but wanted to try ST because I want things to go in a certain sequence. This is practically verbatim from the example text, yet it returns the error" Assignment to Tag of specified type invalid " SIZE(TimeStamp[0],0,Length); FOR Position2 := 0 TO Length-1 DO TimeStamp[Position2] := 0; END_FOR; Variables are DINTS TimeStamp[x] is a String Array I get the same error when I replace the "0" (Zero) with a string Tag

Share this post


Link to post
Share on other sites
Your goal is to fill all data bytes of each String in the array with null characters, right ? Try using two loops: one to fill each byte in the .Data[x] array, and the other to index through the array of Strings. Where Position2 is the number of Strings to clear, and Char is the byte in the .Data[x] array. A standard ControlLogix STRING is 82 characters in length, so that loop goes from 0 to 81. SIZE(TimeStamp[0],0,Length); FOR Position2 := 0 TO Length-1 DO FOR Char := 0 TO 81 DO TimeStamp[Position2].Data[Char] := 0; TimeStamp[Position2].LEN := 0; End_FOR; END_FOR;

Share this post


Link to post
Share on other sites
The basic problem is that the Assignment Operator in Structured Text (colon equal) can't be used on Strings. Here's another brute-force method that might take fewer processor cycles: SIZE(TimeStamp[0],0,Length); NullString.LEN := 82; NullString.Data[0] := 0; NullString.Data[1] := 0; NullString.Data[2] := 0; NullString.Data[3] := 0; NullString.Data[4] := 0; NullString.Data[5] := 0; NullString.Data[6] := 0; NullString.Data[7] := 0; NullString.Data[8] := 0; NullString.Data[9] := 0; NullString.Data[10] := 0; NullString.Data[11] := 0; NullString.Data[12] := 0; NullString.Data[13] := 0; NullString.Data[14] := 0; NullString.Data[15] := 0; NullString.Data[16] := 0; NullString.Data[17] := 0; NullString.Data[18] := 0; NullString.Data[19] := 0; NullString.Data[20] := 0; NullString.Data[21] := 0; NullString.Data[22] := 0; NullString.Data[23] := 0; NullString.Data[24] := 0; NullString.Data[25] := 0; NullString.Data[26] := 0; NullString.Data[27] := 0; NullString.Data[28] := 0; NullString.Data[29] := 0; NullString.Data[30] := 0; NullString.Data[31] := 0; NullString.Data[32] := 0; NullString.Data[33] := 0; NullString.Data[34] := 0; NullString.Data[35] := 0; NullString.Data[36] := 0; NullString.Data[37] := 0; NullString.Data[38] := 0; NullString.Data[39] := 0; NullString.Data[40] := 0; NullString.Data[41] := 0; NullString.Data[42] := 0; NullString.Data[43] := 0; NullString.Data[44] := 0; NullString.Data[45] := 0; NullString.Data[46] := 0; NullString.Data[47] := 0; NullString.Data[48] := 0; NullString.Data[49] := 0; NullString.Data[50] := 0; NullString.Data[51] := 0; NullString.Data[52] := 0; NullString.Data[53] := 0; NullString.Data[54] := 0; NullString.Data[55] := 0; NullString.Data[56] := 0; NullString.Data[57] := 0; NullString.Data[58] := 0; NullString.Data[59] := 0; NullString.Data[60] := 0; NullString.Data[61] := 0; NullString.Data[62] := 0; NullString.Data[63] := 0; NullString.Data[64] := 0; NullString.Data[65] := 0; NullString.Data[66] := 0; NullString.Data[67] := 0; NullString.Data[68] := 0; NullString.Data[69] := 0; NullString.Data[70] := 0; NullString.Data[71] := 0; NullString.Data[72] := 0; NullString.Data[73] := 0; NullString.Data[74] := 0; NullString.Data[75] := 0; NullString.Data[76] := 0; NullString.Data[77] := 0; NullString.Data[78] := 0; NullString.Data[79] := 0; NullString.Data[80] := 0; NullString.Data[81] := 0; FOR Position2 := 0 TO Length-1 DO COP (NullString.Data[0],TimeStamp[Position2].Data[0], 82); TimeStamp[Position2].LEN := 0 ; END_FOR;

Share this post


Link to post
Share on other sites
Hi, Ken's solution is OK, it should do the trick, you can just set the length out of the inner loop : SIZE(TimeStamp[0],0,Length); FOR Position2 := 0 TO Length-1 DO FOR Char := 0 TO 81 DO TimeStamp[Position2].Data[Char] := 0; END_FOR; TimeStamp[Position2].LEN := 0; END_FOR; Once is enough for every string. Edited by drx

Share this post


Link to post
Share on other sites
That is what I came away thinking, but since (ST docs are sparse and...) the ladder FLL successfully used a 0 with the proper result in the destination, and further reinforced by the the source and destination being the same data type, I assumed that the ST version would work fine also. Silly me. I'll be back into this in about 2 hours. I'll give both solutions a try. Someday I'll stop trying to use ST. :) Thanks

Share this post


Link to post
Share on other sites
Two quick ways to clear a string tag: 1.) Set the .LEN property to zero. This fools the processor into seeing it as an empty tag, though it can be confusing when you look at the data array and see values other than null. 2.) Create a string tag called "NullString" or something like that and make sure it's empty. Then any time you want to clear a string, overwrite it with NullString. I don't know ST very well, but you should be able to use the COP instruction.
1 person likes this

Share this post


Link to post
Share on other sites
I have been bitten by strings that included "old" data, sometimes just one byte more than was expected. So I always makes sure that I explicitly put zeroes into every byte of a STRING as well as set the Length to zero, when I really want a null string.

Share this post


Link to post
Share on other sites
I agree with that. These will likely ONLY be seen by me during development and troubleshooting. I do have an FLL that clears the single array. I just need to first copy that array to a 2 dimesional array for a 20 sequence history. Seems that rather than POPing onto a stack, using a pointer is the cleanest way to accomplish this. I went to ST because I wanted to make sure the "Copy" occurred before the "clear". The serial nature of TS lended itself to that end. IF a COP provided a "done" bit, that would be a great help...

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