Page 1 of 1

Header File Question

Posted: Tue Sep 17, 2019 3:55 pm
by CNC_Machines
Greetings,

I have many CNC machines that run off 3 identical C programs. I use a header file to define IO differences between the machines. It is a pain to remember to update all of the header files in the C programs.

Is there a way to define the IO file once in the main program and save it as a global variable? Then when the other C programs compile, their header files would be defined off of the global variable. That way I only have to remember to update the header file in one place.

Would this work?

Thanks!

Scott

Re: Header File Question

Posted: Tue Sep 17, 2019 5:37 pm
by TomKerekes
Hi Scott,

It isn't clear to me what your issue is. The whole idea of using a header file is that you only need to change the header file one place and the change will automatically be reflected in all the C Programs that include it.

You would normally do the following:

#1 make a Windows Folder for each machine. ie Machine1 and Machine2
#2 configure Machine#1 to use C Programs in the Machine1 folder and Machine#2 use the programs in Machine2 folder, etc.
#3 create C Programs that will use a header from the same folder (don't specify any path) ie #include "MySpindleDefs.h"
#4 copy the C Programs and header into all the Machine folders

Now for example when you change the header file in the Machine2 folder it will automatically be reflected in all the C Programs for Machine2.

Re: Header File Question

Posted: Tue Sep 17, 2019 6:17 pm
by CNC_Machines
Thanks Tom, really appreciate the reply.

I would like to have one central location for my C programs, when I update one of them all of the machines in my plant will take the update at the same time. Each machine is identical (except for IO locations - burned out ports on the Konnect board). They all share one network folder. My hope was to add 50 header files with the unique IO for each machine. Thinking it would be easier to manage 50 machines from one folder, rather than having to manage 50 folders.

I was reading about header macros and "Computed Includes" but dont fully understand how they work.
https://www.tutorialspoint.com/cprogram ... _files.htm

#if Machine_1
# include "Machine_1_IO.h"
#elif Machine_2
# include "Machine_2_IO.h"
#elif Machine_3
...
#endif

Ideally I have a text file locally on each machine indicating which machine number it is. The pre-processor would identify the correct machine and add the appropriate header files. Maybe I am just wanting to do something that is not possible.

Re: Header File Question

Posted: Tue Sep 17, 2019 6:51 pm
by TomKerekes
Hi Scott,

Using that technique you could have one local file on each machine PC to define which header to use.

So for example on Machine #1 a local file C:\Scott\DefineMachine.h would have:
#define SYSTEM_H "system_1.h"

machine #2 would have the a file with the same name and same relative location C:\Scott\DefineMachine.h but would contain:
#define SYSTEM_H "system_2.h"

All the machines could then reference the same C Programs in the network folder that contains one copy of each C Program and the 50 unique header files : system_1.h, system_2.h, system_3.h, ...

Each C Program would do the following:

#include "KMotionDef.h"
#include "C:\Scott\DefineMachine.h" // get which header this system should use from this PC
#include SYSTEM_H // include the header this system should use
.
.
.

One disadvantage to using a network folder is that it will take slightly longer each time a C Program executes (ie. spindle on/off) for the compiler to go out over the network to get the files. And if the network is down the machines will get an error. One way to address this might be to have each machine have a batch file so that each time it boots up (or KMotionCNC is launched it copies the network directory locally)

Re: Header File Question

Posted: Tue Sep 17, 2019 7:44 pm
by CNC_Machines
Sounds Great! Will give it a try.