JSR to ST routine - What datatype for tagname parm?

TheWaterboy

Lifetime Supporting Member + Moderator
Join Date
May 2006
Location
-27.9679796,153.419016
Posts
1,927
I intend to pass a BOOL array to an ST routine (for loop) to count the true bits. (should never have used a Bool array, lesson learned)

The ST works fine with a hardcoded tagname but when passing the tagname as a parameter via JSR I can't seem to figure out what datatype to use for it.

I would have assumed String but that comes with its own issues of .Data and .Len to have to count and assign. Is that the only option?
 
Assuming Logix5000, simply create an InOut BOOL[1] tag. Then pass your array of bools to that tag (your array can be any size). Then in the AOI, use the SIZE instruction to get the length of the array, it will return the actual length, not 1. Arrays in Logix5000 are just pointers, so when passing them around the size is irrelevant and should always be checked in logic.
 
I'm not yet making an AOI, just a JSR/SBR pair so I need to pass a tagname as the parameter.

At this moment I have 2 older data structures and one that is the most common.

First 2 have 2 arrays of bools, one for alarms and one for status (and last for values)
Bool[64] Tagname.ALM
Bool[64] Tagname.STAT
DINT[64] Tagname.DATA

The third uses DINTs for the alm bits and those are easier to deal with
DINT[4] Tagname.ALM
DINT[4] Tagname.STAT
DINT[64] Tagname.DATA

So I need to pass the .ALM bits of that tag to the ST routing that counts the active bits.

I hardcode the name and it works just fine, just can't figure out how to pass it as a parameter using JSR/SBR.

AOI is forthcoming, just want to understand this JSR parameter syntax before moving on. Seems like it would be worth understanding.
 
Ah sorry, I read the JSR, and my brain must have retranslated to AOI (No coffee yet this morning).

I've never passed anything as a parameter to a subroutine, although I have seen it done by others before. When I get off the plane this morning I'll test it.
 
As an example...

Code:
// Doesn't Work
SBR([B]TagVar[/B]);
BitCount :=0;
For J :=0 to 3 DO
	For I := 0 to 31 DO
		IF [B]TagVar[/B][J].[I] then	
			BitCount := BitCount +1;
		end_if;
	End_for;
End_For;

Code:
//Works
BitCount :=0;
For J :=0 to 3 DO
	For I := 0 to 31 DO
		IF [B]ActualTagName.Alm[/B][J].[I] then	
			BitCount := BitCount +1;
		end_if;
	End_for;
End_For
 
Last edited:
As an example...

Code:
// Doesn't Work
SBR([B]TagVar[/B]);
BitCount :=0;
For J :=0 to 3 DO
	For I := 0 to 31 DO
		IF [B]TagVar[/B][J].[I] then	
			BitCount := BitCount +1;
		end_if;
	End_for;
End_For;

Code:
//Works
BitCount :=0;
For J :=0 to 3 DO
	For I := 0 to 31 DO
		IF [B]ActualTagName.Alm[/B][J].[I] then	
			BitCount := BitCount +1;
		end_if;
	End_for;
End_For

I think what you are doing is impossible because there is no way to access a tag indirectly using a different tag containing a string with the original tags name as its value. So using a string tag of value 'myTagName' to access a tag named myTagName does not work.But if someone knows of a way to I would like to know.

If you pass a string with value 'myTagName' in the JSR I would expect TagVar to be a string with value 'myTagName'.

In the first example TagVar is either a string of a tag name or an empty udt. The second example works because it is referencing the original tag with that name and correct type.

Convert the BOOL[64] into dints?
 
On the JSR you need an input parameter to pass a tag into the subroutine e.g. bool_array of type bool[64]

In the subroutine you need an SBR, with a tag of the same datatype as you're passing into the subroutine e.g. local_bool_array of type bool[64]

And then in the subroutine you use local_bool_array...

Side Note for counting bits set: https://www.reddit.com/r/PLC/comments/12rnddx/comment/jgv15go/
 
So, I learned something interesting while attempting to test this. The SIZE instruction does not support BOOL arrays. Blew my mind. I could have sworn that I have used it with BOOLs before but I guess not.
 

Similar Topics

Good Morning , I'm merging another RS Logix 5000 PLC program ( CompactLogix ) into another . Everything is working great except this one...
Replies
9
Views
3,725
does anyone know how to use the jump to subroutine jsr function
Replies
5
Views
2,221
Hello, I have a simple JSR problem which confuses me. The software is RSLogix 5000. In the main routine, I have a rung like this A ------|...
Replies
9
Views
3,485
Hi fellas, I've just learned of an upcoming project that I'm going to be asked to do the programming on. Details are very sketchy at this point...
Replies
19
Views
6,148
Jsr
We have a motor control JSR with Input and Output parameters, There are 36 motors that are controlled by the same JSR. What or how can I view...
Replies
8
Views
530
Back
Top Bottom