Iterate through string array

hpupo

Member
Join Date
Aug 2016
Location
MArlboro
Posts
2
Hello

Just a little background on the question(s) i am about to ask. I have a basic to intermediate knowledge of ladder logic, but i am not so intimate to the programming techniques used on PLCs. I come from a Structured programming environment (think c++ and the sort). I am working on a prototype project (the final phase of this project will be done by a true PLC programmer).
To make a long story short, i need to move the contents of STRING.DATA array to an array of DINT. Like this:

STRING.DATA[0] = ARRAY[0]
STRING.DATA[1] = ARRAY[1]
STRING.DATA[2] = ARRAY[2]
STRING.DATA[3] = ARRAY[3]
...ETC

I understand i could use a MOV instruction for each element in the array, but:

- If i have 20 elements in the array, i'd need 20 MOVs which increases the rung amount...
- is the above the best way to handle this in ladder logic? what if the array varies in size?
- can use a FOR instruction? If so, how do i implement it?
- is there a better approach for this? If so, how?

Thanks so much in advance for all the help.
 
An awful lot depends on which PLC you're using. Some PLC vendors have special instructions to do this sort of things while others (CodeSys) support pointers in the same way that c does. Can you be specific regarding the PLC vendor?

Good luck,

Yosi
 
... i need to move the contents of STRING.DATA array to an array of DINT. Like this:

STRING.DATA[0] = ARRAY[0]
STRING.DATA[1] = ARRAY[1]
STRING.DATA[2] = ARRAY[2]
STRING.DATA[3] = ARRAY[3]
...ETC

You are moving data to STRING.DATA with this snippet, not from.
 
My apologies, i forgot to add i am using a AB CompactLogix 1769-L30ER.
And, i made a mistake, i really meant to say

ARRAY[0] = STRING.DATA[0]

etc, but at end of the day, even the way i wrote first still exemplifies my question.
Let's say my controller DOES NOT have any direct support, what is the best (and most generic) way to accomplish this?

Thanks
 
You could use structured text in the 1769-L30ER if your license allows it, then use a simple FOR instruction. Otherwise if you need to use ladder you need to make a subroutine that does the STRING.DATA[X] = ARRAY[X] and then increment X with the FOR subroutine call.
 
It does have a FAL instruction. It's essentially a combination of a FOR/NEXT loop with a CPT instruction. And it does work with the SINT data type.
 
If you are coming from a programming background try programming in structured text instead of working around the limitations of Ladder instructions.

Anything algorithmic is going to be way easier in ST. It will however confuse any electrician trying to troubleshoot it.
 
This is pretty sketchy, but it will accomplish what you are trying to do. Rungs 0-3 are housekeeping, and rung 4 does the work.

Rung0-3.jpg Rung4.jpg
 

Attachments

  • CopyStuff.zip
    1.3 KB · Views: 3
Last edited:

Similar Topics

I haven't encountered problems connecting to a PLC through VM Ware but I am with this particular machine. I'm running Windows 7 on a Windows 10...
Replies
8
Views
229
I'm upgrading an existing machine with a Honeywell HC900 controller, and I'm trying to do some data processing in the controller. I have variables...
Replies
0
Views
56
Hello, I have an automation direct d2 262 plc and C-more HMI EA9T6CL-R. I need to prepare a program, scheduled to be performed on a future date. I...
Replies
1
Views
119
6FX5002-2CD24-1GR0 Via Siemens Sinamics SINAMICS S120 are cuted. I got 1 project that they relocating old Machine to install to new location. Mut...
Replies
1
Views
57
I have a program that I've used 100 times. SQO settings: File N7:0, Mask 0FFFFh, Dest B3:1, Control R6:0, Length 8, Pos 2. Length & Position...
Replies
48
Views
957
Back
Top Bottom