Studio 5000: Addressing UDT as array of SINTs

MoraleC2

Member
Join Date
Jan 2016
Location
East Coast
Posts
23
Hello,

I will try to be as succinct as possible, and hopefully this will make some sense. Say, in Logix Designer, I have a generic Ethernet module with a 220-SINT array, and want to copy a UDT with discretely-defined REAL values to a section of the array. The UDT is the same size as the Ethernet module's output page, but obviously it is not the same type, so using COP is out of the question. Also, I try to make my code as modular as possible, so I would like to be able to dynamically select both the starting address and the number of bytes to copy.

I figure I could do this by using a generic array instead of a UDT and then alias the elements to give them the symbols I want (or alias the Ethernet interface directly), but that kind of defeats the purpose of my modular approach. Is there a better way to go about this? I am used to programming with Step7, where you can indirectly address complex data structures and copy the individual bytes or words anywhere, regardless of the type. Can something similar be done in Studio 5000 V21 with an AB1756 processor?

Thank you for your time.
 
In RSLogix5000 COP doesn't care about the types. You can copy directly from the UDT into the Array.

COP Output_UDT_Tag Output_Array[0] 220

Will copy the complete UDT into the array

The number on the end is the number of SINT sized chunks (the type of the destination) of data you are copying.

If you are COPying a subset then it would be

COP Output_UDT_Tag.element Output_Array[index_of_Start_Of_That_Information] size of that information in SINT sized chunks.

I also use a UDT the other way with the input information

COP Input_Array[0] Input_UDT_Tag 1

The '1' is because I am copying 1 of the destination's sized chunk (the size of the UDT tag)
 
Last edited:
If the SINT[220] array is the destination of the COP instruction, you have the most flexibility because the Length argument units are the number of destination elements.

Since a SINT element is one byte, a COP with a source tag that's a REAL and a Length of 4 will copy one 32-bit value from the source to four of the destination elements.

Do remember that I/O is asynchronous in the ControlLogix world. I either use an intermediate SINT[x] array, or use the Copy Synchronous (CPS) instructions to lock the source and destination data so that you don't end up with the I/O object being updated over the network with only some of the necessary bytes copied over.

Sometimes the exercise of making code modular and efficient makes it harder to troubleshoot and understand. I will choose a sheet of structured text with dozens of COP instructions over an elegant indirect loop routine any day.
 
Also: Welcome to the Forum !

This has been one of the best places for programmers who are accustomed to Brand A to learn a little about Brand B from people who know both and can describe them in the appropriate syntax.
 
In RSLogix5000 COP doesn't care about the types. You can copy directly from the UDT into the Array.

COP Output_UDT_Tag Output_Array[0] 220

Will copy the complete UDT into the array

The number on the end is the number of SINT sized chunks (the type of the destination) of data you are copying.

If you are COPying a subset then it would be

COP Output_UDT_Tag.element Output_Array[index_of_Start_Of_That_Information] size of that information in SINT sized chunks.

Thank you for the very detailed response. Is there a way to reference by byte address rather than the tag? For instance, if I wanted to transmit bytes 12 through 16, can I do something like CPS(In_UDT.SINT12, Output_Array[12], 4)?

Sometimes the exercise of making code modular and efficient makes it harder to troubleshoot and understand.

Indubitably. But we're used to technicians not being able (or willing) to troubleshoot our PLC code, since most of it is in German, so we just go for broke nowadays. (y) Also, thanks for the welcome!
 
Is there a way to reference by byte address rather than the tag?

Part of the reason UDTs exist is to enumerate named elements and avoid byte offsets, and I'm unaware of any addressing mechanism that will let you address a byte inside a UDT by its position.

If I need to parse elements out of a UDT by byte, I copy the whole thing into a SINT[x] array first.

A more common example of copying a 4-byte datatype data out of a UDT and into four bytes of a SINT[x] array would be:

CPS(In_UDT.Geschwindigkeit, Output_Array[12], 4)?
 

Similar Topics

In Studio 5000, I'm wanting to be more economical in my addressing to conserve memory. I read somewhere that DINTS are the most efficient data...
Replies
2
Views
589
So I am working on a clock and they are DINT sddresses but when I try to look at it on an bit or word level it won't validate, so I must have the...
Replies
15
Views
2,945
Can someone explain to me the AND-16, and the AND 15 part of this indirect addressing? Thank you for any input. B18[(N57_34 AND -16)/16].[N57_34...
Replies
3
Views
1,787
All, I have a question on Indirect addressing, is it possible to use two bits to indirectly address in Studio5000 or do you have to use multiple...
Replies
10
Views
3,916
🙃 I have been scratching my head for a couple of days on this issue. I am in the process of converting a program from rs500 to Studio 5000...
Replies
7
Views
5,620
Back
Top Bottom