Jump to content
OMRON Forums

Block allocation of P variables and subroutines


paddax

Recommended Posts

Is it possible to pass an array index to a subroutine e.g.

 

open subprog calculate(PIND, PSIZE)

;PIND is the index to the first "P" element

;PSIZE number of P variables to calculate

close

 

global MY_ARRAY(100)

 

call calculate(&MY_ARRAY(0), 100)

 

doesn't seem to work

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

In your calling program, you have to first store the index in a local variable before passing it to your subprogram, like this:

 

local index = &MY_ARRAY(0);
call calculate(index, 100);

 

Then, you can access your array of globals using the P() array notation, like in the subprogram example below:

 

open subprog mysub(myinarr, len)
local ctr = 0;
P100 = 0.0;
while(ctr < len)
{
P100 += P(myinarr + ctr); // P(myinarr + ctr) is equal to MY_ARRAY(ctr) as you called it above
ctr++;
}
close

 

I just tested this and it works.

Link to comment
Share on other sites

In your calling program, you have to first store the index in a local variable before passing it to your subprogram, like this:

 

local index = &MY_ARRAY(0);
call calculate(index, 100);

 

Then, you can access your array of globals using the P() array notation, like in the subprogram example below:

 

open subprog mysub(myinarr, len)
local ctr = 0;
P100 = 0.0;
while(ctr < len)
{
P100 += P(myinarr + ctr); // P(myinarr + ctr) is equal to MY_ARRAY(ctr) as you called it above
ctr++;
}
close

 

I just tested this and it works.

Link to comment
Share on other sites

Another path since you aren't passing an array of Local variables and are using global variables

:

#define MY_ARRAY_SIZE 100

global MY_ARRAY(MY_ARRAY_SIZE ); // these go in you global definition.pmh file

 

local array_sum;

call mysub(50, &array_sum); // The '&' designates a return variable in a CALL or SUBPROG call_list.

 

open subprog mysub(start_index, &rtn) // The '&' designates a return variable

 

rtn = 0.0;

while(start_index < MY_ARRAY_SIZE )

{

rtn += MY_ARRAY(start_index);

start_index ++;

}

close

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...