Studio5000 - swap array value and index into new array

IAmTheCapo

Member
Join Date
May 2020
Location
Toronto
Posts
2
Sorry for the word salad title, I'm having trouble putting my problem into words.

Basically I have two arrays of DINTs, both the same size called array1 and array2 and I want to update the value in array2 to be the related index for that number in array1.

For example if I have:

array1[1] = 3
array1[2] = 1
array1[3] = 2

I want to get

array2[1] = 2
array2[2] = 3
array2[3] = 1

Basically I want the value and index from array1 to be swapped for array2.

I can easily do this in a few lines in structure text, but was wondering if there was a way to do this in ladder (FAL instruction maybe?)

Cheers,
AC
 
Summat like this, maybe?

MOV 1 array1_index
LBL something MOV array1[array1_index] array2_index BST lim 1 array2_index 3 mov array1_index array2[array2_index] NXB ADD array1_index 1 array1_index LES array1_index 4 JMP something BND



FAL would do it in principle, but I think Studio5k will choke when it tries to parse brackets inside brackets.
.
 
Rung1 - Size instruction. Array1[0] Destination = FAL.LEN

Rung 2 - FAL instruction.

Control = FAL
Length = <Array1 Size>
Position = 0
Mode = All
Destination = Array2_Index (new DINT tag)
Expression = Array1[FAL.pos]

Rung 3

MOV instruction - FAL.pos Array2[Array2_Index]
 
Last edited:
Summat like this, maybe?

MOV 1 array1_index
LBL something MOV array1[array1_index] array2_index BST lim 1 array2_index 3 mov array1_index array2[array2_index] NXB ADD array1_index 1 array1_index LES array1_index 4 JMP something BND



FAL would do it in principle, but I think Studio5k will choke when it tries to parse brackets inside brackets.
.

Thanks, this looks solid. When I get my PLC I'll give this a shot and put it through its paces.

Rung1 - Size instruction. Array1[0] Destination = FAL.LEN

Rung 2 - FAL instruction.

Control = FAL
Length = <Array1 Size>
Position = 0
Mode = All
Destination = Array2_Index (new DINT tag)
Expression = Array1[FAL.pos]

Rung 3

MOV instruction - FAL.pos Array2[Array2_Index]

I'll have to try this one out when my PLC comes in as well, but I'm not sure if this will do it. Won't the FAL instruction there just cycle through all the array values in one scan and keep writing over the Array2_Index value so at the end it just gives the value of the last object in the array? Perhaps it would work if I set the MODE to INC, but I want to do this all in one scan.

Thanks again everyone for the input.
Cheers,
 
I have not tested. It may not work as I thought. That suggestion was from memory without access to software.
 
Just tested it on a PLC and it will require INC.


And then it will move one value on each toggle of the input rung (e.g. every other scan with a flip-flop), or every scan if there is a [XIO control.CN OTL control.EN] on a rung after the FAL.
 
If your only using 1-3 then brute force would be the cleanest and most easy to understand.

EQU Array 1[1] 1 Mov 1 Array2[1]
EQU Array 1[1] 2 Mov 1 Array2[2]
EQU Array 1[1] 3 Mov 1 Array2[3]

EQU Array 1[2] 1 Mov 2 Array2[1]
EQU Array 1[2] 2 Mov 2 Array2[2]
EQU Array 1[2] 3 Mov 2 Array2[3]

EQU Array 1[3] 1 Mov 3 Array2[1]
EQU Array 1[3] 2 Mov 3 Array2[2]
EQU Array 1[3] 3 Mov 3 Array2[3]

If the Arrays are larger then you could use a FSC for each Array element. Make a 3rd array equal in length to Array 1&2 and enter a value equal to the Array element number. This would identify the element's position equal to Array1's value.

the FSC expression would be: Array1[1] = Array3[FSC.pos]

When the FSC instruction finds the value of Array1[1] in Array3 then:

XIC FSC.FD MOV FSC.pos Array2[1] OTU FSC.FD

Repeat for every element in the array. Once you've completed your task then (RES) each FSC to be ready for your next sequence. This would complete your task in 1 scan. It's basically a brute force method using the FSC.
 
would it be possible to assign an alias, e.g. a1val_at_POS, to array1[ctl.POS]?

Then FAL with array2[a1val_at_POS] as the target, and ctl.POS as the value to write to that target, might do it.

Can anyone confirm nested brackets are not acceptable to the FAL expression?


P.S. My previous post had a typo: I think I meant to write conrol.DN where I put control.CN.
 

Similar Topics

I have a C-More HMI that changes my PLC String from "Machine Status" to "aMhcni etStasu" . There is an option with other objects that have string...
Replies
15
Views
3,477
I have an array of 55 REAL values. Is there a way to multiply based on the array location ? I have 55 transfer belts that are equally spaced...
Replies
3
Views
154
Hi Hope you all are doing well. Iam working on a project with some AOI. I also hate no online edits... lol. My problem occurs when I use a UDT...
Replies
2
Views
161
I am not sure if this is possible but if there is a way, you guys would be the ones to know. I am currently working on a project where we are...
Replies
7
Views
223
Hi all. I'm having issues adding an ethernet module to my project in Studio500 v34. The device is a Fredericks Televac EthernetIP MX gateway which...
Replies
8
Views
367
Back
Top Bottom