nikitab900

Working with arrays

5 posts in this topic

Hi! I can not understend how to work with array from functional blocks. For example, I want to create some functional block (on ST lang.), send to it some array and recive from it some new array (FB make some monipulations with input array). FB code: FOR i:=0 TO 4 DOinputLoadArray:= outputLoadArray*2;END_FOR; How does look my main program (only on ST language) for send input and recive output arrays?
1 person likes this

Share this post


Link to post
Share on other sites
Hi Arrays need to be IN_OUT and you need a CJ2 or a v4 CJ1. An alternative if you're using CP1 is define the arrays as INTERNALS and use AT addressing. Pp

Share this post


Link to post
Share on other sites
I'm sorry, I have CJ2M PLC with CPU32. Of cource, I add array variable to In-Out var into my FB. But how can I do simple thing like thise (c++ for example) in cx-programmer? ************************************* Main() { myFB(int someArray[5]) { int outArray[5]; for (int i=0, i<5, i++) { outArray = someArray*2; } return outArray; } int inputArray[5] = {1,2,3,4,5}; int result[5] = myFB(inputArray); } ******************************************** cx-programmer drives me crazy(((
1 person likes this

Share this post


Link to post
Share on other sites
PLC's are very different to c++ They do support structured text, supposedly to the IEC61xxx standard (I forget the exact number), but not all of them implement them the same (IMO). Perhaps if you describe in more plain text what you are trying to achieve? It looks like you are wanting to multiply each input element by 2? There would be a far more efficient way of doing this using ladder..
1 person likes this

Share this post


Link to post
Share on other sites
Here is an example of how you can implement your array operation: 1) Create 2 INT arrays in your Symbols table as: MyArray at D100 with size INT[100] OutputArray at D1000 with size INT[100] 2) Create your FB as: FOR i:=0 TO 99 BY 1 DOInputArray:=InputArray*2;END_FOR;Here InputArray is defined as In-Out variable with 100 size.3) In your main ladder logic, create rung with a single shot contact and XFER &100 D100 D1000. This rung will transfer the 100 elements from your MyArray to OutputArray.4) In your second rung, insert a single shot contact and a call to your FB. Enter OutputArray as your input. To run this: Insert some dummy values at D100 to D103. Force the single-shot contact in your first rung and then force the single-shot contact in the second rung. You'll see that OutputArray elements at D1000 will be multiplied by 2. The key here is to use single-shot contact to trigger your FB to be able to execute your for loop one time only.

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