Jump to content
OMRON Forums

Pass reference to ptr


jtaseff

Recommended Posts

We're trying to figure out how to deal with ptr variables in script like an actual pointer.

 

Basically, we would like to pass a pointer by reference to a subprogram. However, the system of "arguments" in PPMAC just copies by value back and forth between R and L variables, so the function can't manipulate the address being pointed to.

 

 

Ideal case - a generic function for actuators that could get passed the pointer to IO locations, like the following:

 

// generic actuator function:
open subprog extend(solenoid, limitswitch)
   solenoid = 1;     // turn on solenoid
   while (limitswitch == 0) {}     // wait for full extension
close

 

// component that uses it:
ptr GripperOpenSolenoid -> ECAT[0].IO[15].data
ptr GripperOpenLimitSwitch -> ECAT[0].IO[16].data

open subprog OpenGripper(void)
   call extend(GripperOpenSolenoid, GripperOpenLimitSwitch);
close

 

 

Is there a way to do this by reference in the subprog argument? Or is there a way to retrieve and pass the M variable number so that the generic function could access Sys.M[12324]? Open to any other suggestions. Thanks!

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

If I recall correctly, just put an ampersand on the desired argument. I'll modify your example below:

 

// generic actuator function:

open subprog extend(&solenoid, limitswitch)

solenoid = 1;

while (limitswitch == 0) {}

close

 

Code:

// component that uses it:

ptr GripperOpenSolenoid -> ECAT[0].IO[15].data

ptr GripperOpenLimitSwitch -> ECAT[0].IO[16].data

 

open subprog OpenGripper(void)

call extend(&GripperOpenSolenoid, GripperOpenLimitSwitch);

close

Link to comment
Share on other sites

The ampersand makes the argument into a "return value" where you can get a value back from the function. This still passes by value, not by reference. When you look at the compiled version of this code, it is dealing with a local copy stored in L and R variables, not with the pointed-to location. Thus the desired address held by the ptr (e.g. my ECAT address) never gets changed.
Link to comment
Share on other sites

That capability is not currently a feature of the “IDE Program Enhancements”. As you have surmised, you would need to identify the M-variable numeric assignment used and pass that manually the in the subroutine and use the Sys.M[] reference. You can find these assignments one way by query of the “ptr” name in the terminal window. It will respond with the M-variable number. It is also listed in the generated header file in the project’s root directory.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...