How do I return an Integer from several Bools in a UDT

PLC_Shaggy

Member
Join Date
Aug 2010
Location
Indiana
Posts
12
I am using RSLogix 5000 and have a User Defined Type roughly it looks like this:


Ready BOOL
Trigger BOOL
Error0 BOOL
Error1 BOOL
Error2 BOOL
Complete BOOL
Result INT

What is the easiest/best method for getting those three Error BOOLs into an Integer?

Also how would I take it the other way?

Right now I am using a XIC to an OTE on each one. I assume there is a much clear way to copy these back and forth.

Thanks for all your advice!
 
I would change the Error Bools - to 1 DINT - Then your errors could be used as bools ERROR.0 ERROR.1 ERROR.2 or be used as an Interger ERROR
 
Search the forum for "bit overlay" using the search tool on the blue bar at the top of the thread.

An overlay is a type of UDT structure that allows you to name the individual bits in an integer, just like a .DN or .EN bit is a named bit in word 0 of a timer.
 
I do not have control of the UDT. It's structure must remain the same.

I have never seen the Bit Overlay before. But from what I read, it still seems like I would need to modify my current UDT. I will try to do more research on it.

Thanks for the replies so far.
 
Agreed. If you can't change the structure then brute force xic to ote is the best way to go. If you have a large number of tags that are of the UDT type then consider using a subroutine where the tag is passed in as a parameter, then the bools are mapped to the integer bits, and then the tag is passed back out. If you only have one or three or four tags of the udt type then a subroutine with passed parameters is probably not worth the effort.
 
Thanks for the replies. Luckily I only have 3 bools in the 1 UDT, so I'll just map them manually. I like the idea of using a subroutine to save time on a large project.
 
If you create this UDT, you will see that it 'occupies' 4 bytes of memory (See Pic.1)

So that means the BOOLs reside in the first 2 bytes, and the INT Result resides in the second 2 bytes.

So, MichaelG is correct, if you COP the udt tag into an INT[2] array tag, your bits will appear as follows...

Ready INT[0].0
Trigger INT[0].1
Error0 INT[0].2
Error1 INT[0].3
Error2 INT[0].4
Complete INT[0].5
Result INT[1]



See Pic2

Pic1.jpg Pic2.jpg
 
thanks daba (y)

There may be a warning though as I thought that UDT's used SINTs to do the byte packing - depends on your UDT alignment i guess
 
thanks daba (y)

There may be a warning though as I thought that UDT's used SINTs to do the byte packing - depends on your UDT alignment i guess

If that were true, the UDT as posted would only have needed 3 bytes. I believe that an INT has to "start" on an even number byte, 0 or 2.

Anyway the pics were from a running program, although I didn't show it, and there are no warnings given, it's up to the programmer to get it right !

New Pic added....

Pic1.jpg
 
Last edited:
He can copy the UDT tag to an EXTERNAL integer array. However, if he wants the bit status in the udtTag.Result integer that is embedded within the same udt then its not as simple. The OP hasn't provided any detail but that was my assumption (you know what they say about assumptions:beer:). He could still use an array that is external to the UDT and copy out to the array and then copy the relevant element back into the UDT - but since there are just three bits that is not going to save any code, nor does it do anything for program readability and it certainly won't execute any faster.
 

Similar Topics

I have a Type C to RS485 adapter connect to my Siemens RWF55. I use modscan to scan it to get a value from the Siemens controller. In the...
Replies
4
Views
100
This is for editing HMI texts en masse in Excel. My problem is that in my HMI texts, some are in multiple lines, even if they are single texts...
Replies
26
Views
9,112
Hello, I have been tasked to create routines that has a JSR with zero return parameters to go to a routine with a RET with zero parameters. Is...
Replies
2
Views
1,403
Hi all, I have a PIDE block (Logix5000) where I am introducing interlocks. I am using the ProgOverrideReq to set the CV to 0% (shut a control...
Replies
3
Views
1,633
I am using Indusoft Version 8.1, and trying to use the VBScript button command to find a string in a column in a MySql database, and return all...
Replies
36
Views
8,724
Back
Top Bottom