Access KMotion displayed position from C

Moderators: TomKerekes, dynomotion

Post Reply
PBandJacob
Posts: 21
Joined: Thu Sep 02, 2021 6:02 pm

Access KMotion displayed position from C

Post by PBandJacob » Tue Feb 01, 2022 9:39 pm

Hello,
Is there an easy way to access the position of an axis from C?
We have an offset for our device so when I check ch0->Position I get "0" when the displayed X position is about 4 inches. That offset is set in our .set file in KMotionCNC. Those offset values also appear in the emc.var file in C:/KMotion435b/KMotion/Data. I've tried using the C commands fscanf() and sscanf() to read in those values but it seems like they either only pass in the first value in a line of text, or they grab the entire line. So I'm wondering if there are either:
1) A supported C command for parsing through files delimited by whitespace OR
2) An easy way to grab those values straight from memory similar to the channel values or the persist array
Note: It would be a hassle for us to just retype in all of these offsets as #define's, but that would be a solution, albeit a time-consuming one.

PBandJacob
Posts: 21
Joined: Thu Sep 02, 2021 6:02 pm

Re: Access KMotion displayed position from C

Post by PBandJacob » Tue Feb 01, 2022 9:52 pm

I figured out a solution, I had forgotten that file streams can grab formatted info from the entire line that they scan so all I needed to do was this:
int dummy;
float value_i_want;
FILE *f = fopen("C:\\KMotion435b\\KMotion\\Data\\emc.var", "rt")
if (!f)
{
//Some error handling
return;
}
int i;
for(i = 0; i < some_line_down_the_file_i_want; i++)
{
fscanf(f, "%d %f", %dummy, %value_i_want);
}
fclose(f);

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

Re: Access KMotion displayed position from C

Post by TomKerekes » Wed Feb 02, 2022 12:11 am

Hi,

There are also commands to request from KMotionCNC the DROs, Fixture Offsets, Tool Offsets, etc. See the ToolTableSetDebug.c example.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply