Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
global constants for C and script programs...
#1
Hello,

Is there a way to define constants in the global definitions.pmh file? I want to refer to many things by name such as motor numbers, Coordinate systems, and motion/PLC Programs. I want access to these in script programs as well as C programs.

I might be able to get by in my C programs by referring to the motion and PLC programs as strings and using the command interpreter. I'll need constants on the motors and C.S.'s though since I'll be accessing them through the data structures, function parameter passing, etc.

Thanks,
KEJR
Reply
#2
Please refer to the post in the following link:

http://forums.deltatau.com/showthread.php?tid=314

It describes how to define M-Variables for global access, even in C programs.

If that post does not answer your question please let us know what else you would like answered. Thanks.
Reply
#3
Hi Charles,

Thanks for the link. I had contributed to that thread ;) I'm using global *variables* now already.

What I'm after is a way to define global *constants* that get used like C preprocessor statements in both script and C programs. In fact when used in C it [preferably] could just be a "#define" directive.

If I use a global var I have to be careful to both initialize it and then call GetGlobalVar() to return the constant when working in C. While this can be done, it is alot more dangerous and involved than using a preprocessor directive.

I'm open to any ideas.

Thanks,
KEJR

Reply
#4
What you need to do is make a #define file that has your constants for script and C in the same directory as the global definitions.pmh. Then in the C-programs in which you want to use these #defines you add the file to the include list.
Reply
#5
The July release IDE won't let me add a C header file. I just tried it and it barked about the fact that the file must end in .c or .h even though my file did ened in ".h"

Besides, if you do a "#define" in a .h file can you use that from within your script programs (using the same file)?

KEJR
Reply
#6
Update:

I tried just typing in "#define foo 2" into the global definitions.pmh file and it *half* worked.

It made it into the PLC program I used it in. It did not work when I used it in a C program and naturally the compiler rejected the "foo" label.

I'm going to file something with Bugzilla on this because it should either be easy to add this feature to C programs as the script that generates the .h header file from the pmh file jsut has to pass it on unmodified.

KEJR
Reply
#7
It does not sound like you are doing what I tried to describe in the above post. You must either add a new file into the directory containing global definitions.pmh or only put #defines into global definitions.pmh. I prefer making a new file. This is under the script language area as this is the only place that script program will pick up data from.

In every C program that you want to use these #defines you must add an include"" statement to the file containing these #defines. If you made the file called myfile.pmh then the include path is #include "../../../PMAC Script Language/Global Includes/myfile.pmh"

Reply
#8
The problem I was having before is that I was trying to add the file in the IDE with the .h extension and the IDE was not letting me do it. Adding it as a .pmh file and only having #define statements in it works and I just tested it.

Thank you!

KEJR

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)