CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Wed Jun 28, 2017 9:44 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Jan 20, 2011 11:17 am 
Offline

Joined: Wed Jan 19, 2011 1:12 pm
Posts: 2
Hello
I'm trying to write a function block (in ST) that shall do some operation on an array.
Preferbly the size of the array should be defined by a VAR_INPUT

Currently the variable declarations are as follows.
VAR_INPUT
Ellements:INT;
NewVal:INT;
END_VAR
VAR_IN_OUT
History: ARRAY [1.. 10] OF INT;
END_VAR

My intention is to replace the fixed size ARRAY[1..10] to [1..Ellements] e.g. a programatically
changeable number of ellements in the array.
Anyone ?


Top
   
PostPosted: Mon Jan 24, 2011 1:24 pm 
Offline

Joined: Mon Feb 04, 2008 2:04 pm
Posts: 15
use a integer pointer as input;

Code:
VAR_INPUT
  Size:INT;
  Value:INT;
  History: POINTER TO INT;
END_VAR

VAR
  Item: POINTER TO INT;
END_VAR
...
Item:= Temp;
FOR I:= 1 to Size do
  Temp^:= Value;
  Temp:= Temp + SIZEOF(Temp^);
END_FOR;



_________________
Andreas
http://www.boschrexroth.com


Top
   
PostPosted: Mon Jan 24, 2011 7:18 pm 
Offline

Joined: Fri Nov 13, 2009 10:20 am
Posts: 9
I've never thought to accomplish an array this way. Would you mind clearing up a few details?

1. What is the purpose of the input variable, History?
2. Where are you defining "temp" and is it another Pointer?
3. If you wouldn't mind briefly explaining what's going on in your example, that'd be very helpful; it'd be great to really understand what's going on here.

Thanks! :)


Top
   
PostPosted: Mon Jan 24, 2011 10:36 pm 
Offline

Joined: Wed Jan 19, 2011 1:12 pm
Posts: 2
Hello
I've not tried the suggestion by Andreas yet, will do when time let me.

The variable History is a set of samples of an input. I want to do some calculation on them
and treat the array as a FIFO. All this is not a problem.

The question is related to how to declear an input as an array of unknown size at compile time.
All I've tried so far is not valid syntax


Top
   
PostPosted: Fri Jan 28, 2011 9:32 am 
Offline

Joined: Mon Feb 04, 2008 2:04 pm
Posts: 15
jason.the.adams wrote:
I've never thought to accomplish an array this way. Would you mind clearing up a few details?

1. What is the purpose of the input variable, History?
2. Where are you defining "temp" and is it another Pointer?
3. If you wouldn't mind briefly explaining what's going on in your example, that'd be very helpful; it'd be great to really understand what's going on here.

Thanks! :)


#1: It's the same as the history in your example, a input array of values, but instead of just writing History as the input you write Adr(History[0])
#2: My bad, all Temp should be Item
#3: Basically my example just fills the input history with the value;

Code:
VAR_INPUT
  Size:INT; (* Size of the array *)
  Value:INT;
  History: POINTER TO INT; (* Same as History: ARRAY[0..Size-1] OF INT; *)
END_VAR

VAR
  Item: POINTER TO INT;
END_VAR
...

(* Just save a local copy of History[0] *)
Item:= History;
FOR I:= 1 to Size do
  (* History[I]:= Value; *)
  Item^:= Value;
  (* Goto the next item in the array *)
  Item:= Item+ SIZEOF(Temp^);
END_FOR;


_________________
Andreas
http://www.boschrexroth.com


Top
   
PostPosted: Mon Jan 31, 2011 5:30 pm 
Offline

Joined: Sat Jun 24, 2006 4:14 pm
Posts: 44
if you are interested you can find many array functions in the open source library OSCAT.
many of the array functions use pointer to operate on unknown size of arrays.
you can use our source code as sample to develop your own functions

_________________
freie sps bibliothek unter www.oscat.de


Top
   
PostPosted: Tue Mar 07, 2017 12:17 pm 
Offline

Joined: Fri Feb 24, 2017 11:26 am
Posts: 1
Code:
VAR_INPUT
   NewVal:INT;
END_VAR
VAR_IN_OUT CONSTANT
   Ellements:INT;
END_VAR
VAR_IN_OUT
   History: ARRAY [1..Ellements] OF INT;
END_VAR


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


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