Jump to content
OMRON Forums

global constants for C and script programs...


KEJR

Recommended Posts

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
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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"
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...