I Know There is a C Programmer in Here Somewhere

The Junk Drawer is for those Off Topical discussions where we can ask questions of the community that we feel might have the ability to help out.

Moderator: Harold_V

User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

I thought I might put this in the CNC area, but I figured the moderators might lay the smackdown on me, so here it is.

Because my CNC controller uses C, I have to learn a bit of C programming. I'm fooling with it now. I got a book and a free compiler, and I write programs.

I wrote a program the other day, and then I modified it and recompiled it. It didn't change. I figured I had made changes that didn't affect the output, so I modified it some more to check. It still didn't change.

It turns out this program will not change, no matter what I do. Even if I delete the exe file and recompile it, nothing changes. It stays the same after the computer shuts down and reboots.

I don't need the program, but I'm wondering: what's going on?
Every hard-fried egg began life sunny-side up.
User avatar
BadDog
Posts: 5131
Joined: Wed May 17, 2006 8:21 pm
Location: Phoenix, AZ

Re: I Know There is a C Programmer in Here Somewhere

Post by BadDog »

I'm surprised you're having to do anything in C for CNC work, and certainly nothing that would be likely to be productive starting from zero knowledge, but that aside...

Since it appears that you can build (compile and link) to produce a new exe, my first guess is that the c file you are editing is not the one being built. How that might have happened depends on a lot of things not evident in your post, and not easily tracked down without a lot more involvement than will easily be accomplished in a forum discussion. But it almost certainly has nothing to do with "C", rather something is scrambled in the build environment.

If that's not it, then it may be that you've managed to arrange things in code such that the code you are modifying isn't actually being executed. Again, various ways that could have happened and not easily sorted in this fashion.

Might be a good time to explore the debugging features available. Hopefully you have an interactive debugger, so you can set a break point in your function and watch it execute. If it doesn't get hit, it's not getting called, so you work your way backward all the way to main if needed. Once you catch it in the debugger, step through to see where it goes. If you're starting down this path, learning the basics of using the debugger early will pay huge dividends as you explore further.
Russ
Master Floor Sweeper
User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

Re: I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

BadDog wrote:I'm surprised you're having to do anything in C for CNC work, and certainly nothing that would be likely to be productive starting from zero knowledge, but that aside...
Since you express amazement...

The controller I bought uses various C programs to tell it what to do. It uses a C program to define a whole bunch of stuff related to the axes. The controller came with lots of sample programs, but as you can guess, it's not all that great for lathe users. I had to take a program intended to initialize 3 axes and fix it so it works for 2. I think there were also problems caused by the fact that a lathe's second axis is z, not y. It was a long time ago, but I believe the program wanted to equate "z" with "2," which is the number of the third axis. Don't quote me on that.

Every time I crank up Mach3 or the CNC program that came with the controller, I have to run a C program.

The guy who makes the controller tells prospective customers they should know C. I no longer recall why I still bought it. I'm sure I raised the obvious question.
If that's not it, then it may be that you've managed to arrange things in code such that the code you are modifying isn't actually being executed.
That's not it. If you take the same code, rename it, and compile it again, the problem disappears. That's how I got around it.

It's like it's stuck in the computer somewhere.
Last edited by SteveHGraham on Sun Jul 24, 2016 9:15 pm, edited 1 time in total.
Every hard-fried egg began life sunny-side up.
User avatar
BadDog
Posts: 5131
Joined: Wed May 17, 2006 8:21 pm
Location: Phoenix, AZ

Re: I Know There is a C Programmer in Here Somewhere

Post by BadDog »

I've heard a lot about Mach3, but don't recall anything about needing to know C. But working with computers all day, I have less than zero interest adding computers to my shop experience, so I actively avoid all those discussions. I suppose it's how users are expected to adapt the main program to different hardware, in which case all I can say is "good luck". Regardless of the exact version/flavor, there is a steep learning curve. But choosing a good supportive environment and learning to use that is can help a lot.

Not sure what to suggest regarding your program beyond what I already said. I'm not even sure quite how to interpret your second to last sentence. But for the various interpretations of what I think I follow of your description I can imagine a multitude of possible explanations for how you might have found yourself in that situation, and might still not hit on the right one. Include files, compiler switches, intermediate output artifacts, link options and order, etc. Again, my best advice is dedicate the time now to learn to use the debugger and use that to figure out what is going on while it is running. Even in my own work, it's not unusual for me to have an instant reaction of "oh, I bet I know what I screwed up", only to run the debugger to investigate and find out it was something else entirely. Have a good debugger and learning to use it will do more to both help keep your sanity AND improve your capabilities (measured in making progress) than anything else I can suggest.
Russ
Master Floor Sweeper
User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

Re: I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

The C programming isn't for Mach3 per se. It's for the controller, which has to be initialized in order for Mach3 to communicate with it.
Every hard-fried egg began life sunny-side up.
User avatar
Gary Armitstead
Posts: 279
Joined: Sat Mar 02, 2013 12:35 am
Location: Burbank, CA

Re: I Know There is a C Programmer in Here Somewhere

Post by Gary Armitstead »

Steven,

I have some experience with CNC in my die sinking trade, although I have been retired for 14 years!

I may be wrong or not understanding you.......but it sounds like you are talking about changing the Post Processor program to communicate with your machine/machines. Is that correct? If so, then I think you need to have a way of opening the processor and do some editing on certain "line numbers" that indicate a command to tell the machine to go to a certain "G" code or whether it is in absolute or incremental. These are all instructions that can be edited. There are special "editors" available for doing this, but they are usually available to the higher-end Fanuc or other controller systems. Usually these are made to be used by ordinary NC programmers without knowing some computer language. Pretty generic stuff.
Gary Armitstead
Burbank, CA
Member LALS since 1980
Member Goleta Valley Railroad Club 1980-1993
User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

Re: I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

No, that's pretty far off. Just wondering why a simple C programming exercise I wrote will not update.
Every hard-fried egg began life sunny-side up.
TomB
Posts: 495
Joined: Mon Jan 14, 2008 7:49 pm
Location: Southern VT

Re: I Know There is a C Programmer in Here Somewhere

Post by TomB »

SteveHGraham wrote:No, that's pretty far off. Just wondering why a simple C programming exercise I wrote will not update.
My programming days are too far back in history to be very useful and they were on IBM or Unix type machines. When I tried converting my skills to Windows operating systems I found the search path for Windows to be totally confusing. While compiling programs you are starting a program executing. That program must then access the source code and the subroutine libraries and store the resulting executable. To do so it must search directories starting at the file directory that (1) the compiler was fetched from or, (2) a directory point specified by the OS, for example MyDocuments, or (3) some directory name in the system variable 'Path'. (I will not guarantee my use of names is accurate as even when it was new knowledge it was confusing. It was based too much on rote learning and not on actual understanding.) I believe from you description that either the compiler is accessing a copy of source and not the copy you are editing or the executable is being store at a point where you are not fetching it during invocation. In the first case you should see compiler error messages that relate to your edited code (leave out a ';' to check that the compile is seeing the same thing you are editing). In the latter case there is likely an old copy of the executable that is registered and not the new copy.

Although C programmers use all this background they may not be the source of information you need. I expect you need a Microsoft System programmer. Microsoft does have a lot of readable verbiage on this topic and I suggest you do a search for 'search paths' on the Microsoft support service.

Tom
User avatar
BadDog
Posts: 5131
Joined: Wed May 17, 2006 8:21 pm
Location: Phoenix, AZ

Re: I Know There is a C Programmer in Here Somewhere

Post by BadDog »

I think you are on the right path, but it's even more complicated than that. Different tools (compiler/linker/make/etc) look for environment variables for clues where things are found. And the make file may configure reconfigure them rather than having static values you could view in the OS. And the command line arguments generally have final say and can override everything else to change things again for any individual tool invocation (compile/link/etc). Some of it is pretty standard, but what is used for configuration and precedence will often depend on not only the producer of the tools, but which version you are using! Most of this is pretty consistent making use of different tools relatively painless most of the time, but all that I said is accurate and possible. But that's a very small piece of the total picture, and why I said that this type of forum help isn't likely to be productive. Someone who knows their way around that kit can likely sort it in a few minutes with access to the computer, but posting on a forum, there is just too much context required.
Russ
Master Floor Sweeper
User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

Re: I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

It doesn't matter. I just thought that since it happened to me, it must happen all the time, so someone would have the answer immediately.
Every hard-fried egg began life sunny-side up.
User avatar
ctwo
Posts: 2996
Joined: Tue Mar 27, 2012 12:37 pm
Location: Silly Cone Valley

Re: I Know There is a C Programmer in Here Somewhere

Post by ctwo »

Steve, C compilers can be very smart and have optimization code. For example, if you write code to perform some simple arithmetic on variables to get a result, and that result is not used anywhere, then the compiler may recognize that and optimize it out of that code.

What IDE are you using (that's the programming environment, the software that you are writing the code in) and what compiler are you using?

Can you post the source code?

Also, I'd just take C programming as a basic requirement only in the context of what you need to do. There is probably not much reason for you to learn all about C to figure out the configurations of your controller. That kflop FAQ is more likely just an ice breaker to let you know there may be some things you'll need to do.
Standards are so important that everyone must have their own...
To measure is to know - Lord Kelvin
Disclaimer: I'm just a guy with a few machines...
User avatar
SteveHGraham
Posts: 7788
Joined: Sat Jan 17, 2009 7:55 pm
Location: Florida

Re: I Know There is a C Programmer in Here Somewhere

Post by SteveHGraham »

Believe me, it's not the code. Save it under a different name, and everything is fine. Maybe my PC hates the name!

The compiler is Devc++. It's like Turbo Pascal; it has an editing window, and it also compiles.

Really, it's not important. If I really cared, I would join a programming forum and endure the endless "THAT HAS ALREADY BEEN ASKED" and "GOOGLE IS YOUR FRIEND" responses.
Every hard-fried egg began life sunny-side up.
Post Reply