ARRAY INT to UDT

Vish_shr

Member
Join Date
Aug 2022
Location
CN
Posts
1
Hello, I'm new here and also new to Rockwell words so please be understandable to me! šŸ™ƒ

I'm currently using RSLogix 5000 v. 33.0
I'm trying to move/copy part of an array of 600 INT to and UDT (with other UDT inside) made by myself, so basically it's happening that by using the istruction COP (the only istruction found so far that is giving me some progress) the first part of the UDT fills correctly (INT and DINT) but once the UDT inside my UDT start, it's trasferring one yes and the other not (I know it's because it works 32bits but how to solve?)

Example by using COP istruction:
ARRAY --> UDT
Array.int[0] = 1 --> UDT.int[0] = 1
Array.int[1] = 2 --> UDT.DINT[1] = 2 + 3
Array.int[2] = 3 --> UDT.DINT[1] = 2 + 3

So far I'm fine but how to transfer the INT to DINT of the UDT under UDT?
Array.int[10] = 10 --> UDT.UDT.[10]INT = 10
Array.int[11] = 11 --> Get's lost because UDT.UDT.[10] is 32bit
Array.int[12] = 12 --> UDT.UDT.[11]INT = 12

Can someone help me?
I would not like to write every single COP o_O
 
Welcome to the forum.

The COP instruction moves the bits of the source to the bits of the destination; the data types of the source and destination are irrelevant, the only thing that matters is where they start.

The only way to move the value of an INT to the value of a DINT is with a MOV instruction.

So in your example above, if you want to use COP to copy the bits in the INT Array.int[0..599], and you want the current value of Array.int[12] to end up in INT UDT.UDT.[11], then you will need to insert an INT in between current INTs Array.int[11] and Array.int[12], so the current value in INT Array.int[12] ends up in INT Array.int[13], the INT array Array.int[0..599] becomes INT array Array.int[0..600] with 600 elements.

Depending on the byte order in that PLC, you will need to

  • EITHER shift the current INTs Array.int[11] through Array.int[599] to Array.int[12] through Array.int[600] and insert a 0 at Array.int[11]
  • OR shift the current INTs Array.int[12] through Array.int[599] to Array.int[13] through Array.int[600], and insert a 0 at Array.int[12]
That assumes you want to do this with one COP instruction. If the UDTs are mostly contiguous INTs with only a few DINTs in between, then you could use COP to copy the bits from INTs to INTs, and MOV to move the value from each INT to its corresponding DINT.
 
If you just want to copy the values in an INT array to a DINT array you can use the FAL instruction. But copying values from DINT to INT can cause a problem if the DINT value is greater than 32767. I have not tried it but it might even fault the PLC.
 
Welcome to the forum.

The COP instruction moves the bits of the source to the bits of the destination; the data types of the source and destination are irrelevant, the only thing that matters is where they start.

The only way to move the value of an INT to the value of a DINT is with a MOV instruction.

So in your example above, if you want to use COP to copy the bits in the INT Array.int[0..599], and you want the current value of Array.int[12] to end up in INT UDT.UDT.[11], then you will need to insert an INT in between current INTs Array.int[11] and Array.int[12], so the current value in INT Array.int[12] ends up in INT Array.int[13], the INT array Array.int[0..599] becomes INT array Array.int[0..600] with 600 elements.

Depending on the byte order in that PLC, you will need to

  • EITHER shift the current INTs Array.int[11] through Array.int[599] to Array.int[12] through Array.int[600] and insert a 0 at Array.int[11]
  • OR shift the current INTs Array.int[12] through Array.int[599] to Array.int[13] through Array.int[600], and insert a 0 at Array.int[12]
That assumes you want to do this with one COP instruction. If the UDTs are mostly contiguous INTs with only a few DINTs in between, then you could use COP to copy the bits from INTs to INTs, and MOV to move the value from each INT to its corresponding DINT.

Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.

Signature phrase checks out.
 
Is there not a function to convert an INT to DINT
Difficult if you do it in a loop but brute force should do it.

UDT.png
 

Similar Topics

I have a Structure in my project which has a few nested UDTs. They are ultimately of type DINT. What I would like to do is copy the values out of...
Replies
5
Views
2,250
Hello! I am completely new to PLCs, so I apologize in advance if this is a dumb question. I have a device that sends out its data as a number of...
Replies
5
Views
2,138
Hi All, I cannot seem to find a way to move a Boolean from an Arrays UDT into a DINT. I have an Array of 32 elements with a UDT data type of 4...
Replies
3
Views
1,742
Howdy, I am currently struggling with an array of values that I want to re-arrange in a programmatic way. My program is a mix of ladder and STX...
Replies
6
Views
396
Hello, I have an int variable that updates the value every second. I want to store the 100 values in an array. Array should keep storing the...
Replies
7
Views
1,000
Back
Top Bottom