Jump to content
OMRON Forums

redefinable ptr to a global


ibisjoe
 Share

Recommended Posts

I have a '.pmh' file where I am declaring some 'global' variables with changeable 'ptr's to them. I am using the IDE to declare these and what I's like to be able to do is:

 

global a;

global b;

 

ptr var->a;

'ptr' definitions such as these seem to end up having either self-referenced ("->*") definitions or, at times, pointers to some Motor[n]. definition when you report them from the terminal window.

 

I think that part of the problem is that in the Script world, 'a' == P[nnnn] where the IDE sets 'nnnn' and so when I set "ptr var->a" it hasn't yet assigned the 'nnnn' and is confused when it downloads/uploads to/from the PPMAC. I know that a definition such as "ptr var->Sys.P[nnnn]" works fine, but I don't know what the IDE is going to assign 'nnnn' as. What's the solution?

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

I'm not sure I understand why you want to do what you are trying to do, but you can do it easily with the other supported method of variable declaration, i.e.:

 

#define a P1

#define b P2

 

ptr var->Sys.P[1]

 

The declarations like "global a" are for users who have no need to know which underlying variable is being used.

Link to comment
Share on other sites

I'm not sure I understand why you want to do what you are trying to do, but you can do it easily with the other supported method of variable declaration, i.e.:

 

#define a P1

#define b P2

 

ptr var->Sys.P[1]

 

The declarations like "global a" are for users who have no need to know which underlying variable is being used.

 

The point is that I want to be able to SET the pointer definition using symbolic names assigned by the IDE (I don't want to have to know that 'a' refers to P[1]); this also means that I can refer to 'a' in the terminal window by just typing "a" and it will respond with the current value of 'a', and also, I can have an entirely independent C program (running outside the IDE) lookup the value of 'a' by name and it will give me the definition/value assigned via the IDE.

Link to comment
Share on other sites

The only difference between the two methods of declaring variable names is who decides which underlying variable is assigned to your symbolic name -- you, or the project manager. In both cases, the matchup is stored in the symbol table inside Power PMAC and so is available to any task that can access the table -- typically through "gpascii -2" (The -2 gives it access to the table.)

 

I still haven't figured out what advantage you get from assigning a pointer variable to a global variable.

Link to comment
Share on other sites

The only difference between the two methods of declaring variable names is who decides which underlying variable is assigned to your symbolic name -- you, or the project manager. In both cases, the matchup is stored in the symbol table inside Power PMAC and so is available to any task that can access the table -- typically through "gpascii -2" (The -2 gives it access to the table.)

 

I still haven't figured out what advantage you get from assigning a pointer variable to a global variable.

 

As I stated previously, The point is that I want to be able to SET the pointer definition using symbolic names assigned by the IDE (I don't want to have to know that 'a' refers to P[1]); this also means that I can refer to 'a' in the terminal window by just typing "a" and it will respond with the current value of 'a', and also, I can have an entirely independent C program (running outside the IDE) lookup the value of 'a' by name and it will give me the definition/value assigned via the IDE.

 

This allows me to make the source of the 'ptr' data(what it points to) changeable/selectable and it can point to any hardware or software(perhaps the result of a calculated quantity like a P-Variable) value, as desired.

Link to comment
Share on other sites

You have the ability right now to use your symbolic name for a variable in the ide terminal/watch windows and OTHER C applications with either method of variable declaration:

 

global a

 

or

 

#define a P1

 

You do not need to assign a pointer variable to do this.

Link to comment
Share on other sites

You have the ability right now to use your symbolic name for a variable in the ide terminal/watch windows and OTHER C applications with either method of variable declaration:

 

global a

 

or

 

#define a P1

 

You do not need to assign a pointer variable to do this.

 

I do if I want to be able to change it without recompiling...on the fly.

Link to comment
Share on other sites

I see what you are saying. Indeed when you try for example:

 

global MyGlobal1,MyGlobal2;

ptr MyPtr->MyGlobal1;

 

then MyPtr ends up being self-referenced (MyPtr->*) which is not what you want.

 

I'm not sure why this doesn't work -- let me forward this post to our Software Engineering manager.

 

However since most of the useful memory locations in Power PMAC have already been mapped, I'm not sure why you would need to reproduce the "Indirect Addressing" method from Turbo PMAC.

 

Keep in mind you could do this easily in a C program also, e.g. in a Background C Application:

 

double *MyPtr;

 

MyPtr=pshm->P[MyGlobal1]; // now MyPtr points to global variable "MyGlobal1" which you need to have previously defined somewhere in your project

 

*MyPtr=5.0; // sets MyGlobal1=5.0

 

MyPtr=pshm->P[MyGlobal2]; // now MyPtr points to global variable "MyGlobal2"

Link to comment
Share on other sites

I see what you are saying. Indeed when you try for example:

 

global MyGlobal1,MyGlobal2;

ptr MyPtr->MyGlobal1;

 

then MyPtr ends up being self-referenced (MyPtr->*) which is not what you want.

 

I'm not sure why this doesn't work -- let me forward this post to our Software Engineering manager.

 

However since most of the useful memory locations in Power PMAC have already been mapped, I'm not sure why you would need to reproduce the "Indirect Addressing" method from Turbo PMAC.

 

Keep in mind you could do this easily in a C program also, e.g. in a Background C Application:

 

double *MyPtr;

 

MyPtr=pshm->P[MyGlobal1]; // now MyPtr points to global variable "MyGlobal1" which you need to have previously defined somewhere in your project

 

*MyPtr=5.0; // sets MyGlobal1=5.0

 

MyPtr=pshm->P[MyGlobal2]; // now MyPtr points to global variable "MyGlobal2"

Charles:

Everything you stated is true. And I ended up using "C" code to perform the initialization, just as you described. The fact remains, however, that from the terminal window or the 'GPASCII -2' command, I must know the P-Variable INDEX in order to perform a dynamic re-assignment; since they both act like 'script' programs, that won't work there as well because when you reference "MyGlobal2" you will get "Pnnnn" substituted. So the only recourse is to do the substitution of the index by hand (since to re-define the ptr you need to enter "MyPtr->Sys.P[nnnn]").

 

I understand how the Script vs. C enumerations conflict in this case so I'm not sure how to do what I want without some sort of smart PPMAC function.

- Joe

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share


×
×
  • Create New...