Sign in to follow this  
Followers 0
dutoitj3

Solved - Cx-Programmer Ladder Array Index

1 post in this topic

Array A INT[32]
Array Index B INT
Destination C INT

Symbols.PNG.df972ca3b1cb70fbc9aebfae0c30

I am trying to move an Array (A) Element (A[2]) using a symbol (B) in ladder into a destination symbol (C)

C = A [ B ]

Ladder.thumb.PNG.65fa05c9f0fc8af6843959c

Result:

ERROR: Array Index of Operand 1 out of range at rung 1 ( 6, 0 ). 

Error.PNG.7d9cd8c269fb2dd45fa60d548a5599

The documentation suggests that it is possible, but I am unsure if there is something I am doing incorrectly.

6362fbcb6bbb4_OmronArray.PNG.3210ae641f5

Note* Fixed indexing works with no errors

6362ffb8bcd1c_noerrorrung.thumb.PNG.a250

Is there another method to accomplish this?

 

PLC : CJ2M CPU31
CX- Programmer: Verion 9.74

Update 1:

If I go online to the PLC It does look like the array look up is working. Is the issue with the mov block?

Online.thumb.PNG.33a461f6771060d1acc9bdc

Update 2:

I changed the memory locations which has caused a different error to appear. This error is clearer but does not explain the manual excerpt I posted further up

ERROR: Only the constant can be specified for the index of the array.  at rung 5 ( 6, 0 ). 

636315878d52a_Changememory.thumb.PNG.4c4

Update 3: Solution 1

I managed to hack together a proof of concept using pointers and indirect offsets 
pointers.thumb.PNG.e46f5cce4901fedb425f3

Update 4: Solution 2

For some strange reason things work as expected inside of the function blocks so I made one where the array is In-Out and with an input and output respectively.

Note* External reference to pointers inside of the function block produced an error.

func.thumb.PNG.6537ebf0c4cf33a231cb8bc18

Function block Logic

 6363285f9617b_funcblock.thumb.PNG.b8eed1

 

Update 5: Solution 3

Now I feel like I am going crazy, I tried just the original code again and it works... I have no idea why and if it was not for all the documentation I would be lost as to why it works now...

working.thumb.PNG.023c4f90548fbdbf086c3d

Update 6: Conclusion

It seems to have array indexing work the array index must exist in the D Memory Block. The reason it did not work above is because I somehow had a MOVR block when I tested after moving all the variables to the D Memory Block. I hope this journey helps someone else :)

Edited by dutoitj3
Further investigation
1 person likes this

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