can't open emc.var

Moderators: TomKerekes, dynomotion

Post Reply
xdmattz
Posts: 10
Joined: Wed Mar 14, 2018 1:06 pm

can't open emc.var

Post by xdmattz » Wed Aug 05, 2020 1:37 am

Tom,
(or anybody else who might know the answer!)

I'm trying to write a C# (WPF) program with your .net libraries to talk to my KFLOP board. I am using VS2015 and after some fits and starts am able to compile the .net libraries in BuildAllLibs.sln.

I can also build and run all the examples in the PC VCS Examples directory.

I started to build a new application based on the SimpleGCode example and I'm seeing some strange things I'm hoping you can help me out with.

I tried to sandbox the new project and copy all the DLLs to the Debug1 folder as described here https://www.dynomotion.com/forum/archiv ... ncies.html

I am able to connect to the KFLOP board, I can download a C Program to it.
I cannot get KMotion to run at the same time so I can monitor the console output from the KFLOP board like it does with KMotionCNC. This also seens to not work with the SimpleGCode example either. I thought that this might have something to do with the C# application running under the debugger in VS, but I really don't know.

I was able to kind of get around this by adding a callback in my application that writes the console message to a text box.
KM.MessageReceived += new KMotion_dotNet.KMConsoleHandler(Console_Msg_Update);

From this I can tell that I can load a C program into thread 1 and can stop and start it from the application, so I must be getting somethings right.

My biggest problem right now is that when I try to execute a Gcode program I get a message box that says "unable to open file ..... \KMotion
\Data\emc.var
KFlop_Cant_Find_emc.var.PNG
The code I tried to use for opening the Gcode and starting it looks like this:

private void btnGCode_Click(object sender, RoutedEventArgs e)
{
// open a GCode file
var GFile = new OpenFileDialog();
GFile.DefaultExt = ".ngc";
GFile.Filter = "ngc Files (*.ngc)|*.ngc|Text Files (*.txt)|*.txt|Tap Files (*.tap)|*.tap|GCode (*.gcode)|*.gcode|All Files (*.*)|*.*";
if (GFile.ShowDialog() == true)
{
tbGCodeFile.Text = GFile.FileName;
}

}

private void btnCycleStart_Click(object sender, RoutedEventArgs e)
{
if (ExecutionInProgress == true) return; // if already running then ignore
else
{
ExecutionInProgress = true;
KM.CoordMotion.Abort(); // make sure that everything is cleared
KM.CoordMotion.ClearAbort();
try
{
KM.CoordMotion.Interpreter.InitializeInterpreter(); <---- I'm fairly certain that this is the call that is failing
}
catch (Exception ex)
{
MessageBox.Show($"File not found '{ex}'");
}
Set_Fixture_Offset(2, 2, 3, 0); // Set X, Y, Z for G55
KM.CoordMotion.Interpreter.Interpret(tbGCodeFile.Text); // Execute the File!
}
}

I tried to copy this almost verbatim from your SimpleGCode example - which doesn't give me this error.

I've just started learning WPF for this project so it's very possible (and highly likely) I've made some stupid mistake. I have some experience with windows forms and C#, but I'm not a professional programmer (Professional RF/Analog Hardware designer - but that doesn't seem to help here.)
Any help would be greatly appreciated.

I'm running KMotion435b. (since you always ask)

Thanks for your time!

Dan Matthews

User avatar
TomKerekes
Posts: 1082
Joined: Mon Dec 04, 2017 1:49 am

Re: can't open emc.var

Post by TomKerekes » Wed Aug 05, 2020 4:50 pm

Hi Dan,

The KMotion Libraries expect a certain directory structure to be able to find all the executables, libraries, and data files. If you target your executable to be placed into C:\KMotion435b\KMotion\Debug like all our examples then things should work without problems.

Otherwise the Interpreter requires a "var" file to load/save its GCode Variables. A default file called emc.var is located in the C:\KMotion435b\KMotion\Data directory. You can create your own "var" file, place it wherever you want, and tell the Interpreter its name and path using the VarsFile Property.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

xdmattz
Posts: 10
Joined: Wed Mar 14, 2018 1:06 pm

Re: can't open emc.var

Post by xdmattz » Thu Aug 06, 2020 1:54 am

Thanks Tom!

That has gotten me past this hurdle.

I can tell I've still got a lot to learn on this, but at least I'm moving again.

Dan M.

Post Reply