CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Jul 27, 2017 1:32 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Dynamic Array's
PostPosted: Thu Mar 17, 2016 10:05 am 
Offline

Joined: Fri Sep 25, 2015 7:22 am
Posts: 11
Firstly, sorry if this has been asked before but I can't find an answer that suits my needs.

Im looking to define an Array, where the length of the Array is a variable. Something like this:

Code:
   Dyn_Array: ARRAY[0..X] OF REAL;


However, the above returns an error of:

Quote:
Error 3750: PLC_PRG (10): Upper Bound 'X' not defined


This also happens even if 'X' is defined and given a value in the declaration section.

Is this possible, or am I missing something? I've got a custom First In First Out FB that i'd like to be able to specify the length of the Array in the block instead of having to import it from the library and edit it each time.

Thanks


Top
   
 Post subject: Re: Dynamic Array's
PostPosted: Thu Mar 17, 2016 11:46 am 
Offline

Joined: Fri Sep 25, 2015 7:22 am
Posts: 11
Ok, I've managed to get a little bit futher. I've used the following to declare a Variable Input Constant:

Code:
VAR_INPUT CONSTANT
   Data_Length:INT:=100;
END_VAR


This in conjuction with:

Code:
FIFO_ARRAY: ARRAY[0..Data_Length] OF REAL;


Compiles correctly! Now this is great, because I can change the Data_Length constant and change the size of the Array.

I assumed the because it was an "Input Variable" that I would be able to programmatically edit this value by passing a parameter to "{FunctionBlock}.Data_Length", but because a constant is exactly just that, no matter what I put for this parameter, it stays at 100.

Is this as far as I can go, or is there still some hope at being able to pass this value to individual instances of a Function Block to vary that function block's array length.

Thanks


Top
   
 Post subject: Re: Dynamic Array's
PostPosted: Sun Mar 20, 2016 3:00 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
YES

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
 Post subject: Re: Dynamic Array's
PostPosted: Sun Mar 20, 2016 4:19 pm 
Offline

Joined: Fri Sep 25, 2015 7:22 am
Posts: 11
shooter wrote:
YES


Thanks, but that doesn't help me very much, if you could expand on that just a little?


Top
   
 Post subject: Re: Dynamic Array's
PostPosted: Sun Mar 20, 2016 4:58 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
no sorry you can not change the size of arrays, as it would mean the memory has to shift a lot.
you will have to design the max size, and maybe use just a little portion of it.
In V3 it is possible on some machines.

and obvious you can use different numbers when defing the function block instance, as long as it is a constant.
the memory is allocated using this constant, and can not be changed.
I never see a reason to change a size in a running program.

please have a look at www.oscat.de (its english) for a big set of functions.

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited