Hello Guest it is April 25, 2024, 12:09:39 AM

Author Topic: How to access "stats" variables  (Read 2663 times)

0 Members and 1 Guest are viewing this topic.

How to access "stats" variables
« on: December 29, 2022, 01:29:15 PM »
I would like to access the varaiables for the below items (that are stored in the machine.ini) from lua script.  I can't find them in any variable list on the internet, or in the registers list, or API manual.  Does anyone know how to get at these?  I would like to be able to read and set some of them for a maintenance section of my screen.
Thanks,
Jim

[Stats]
totalhours=110.356682
spindlehours=90.487351
distancex=102382.373448
distancey=154901.823617
distancez=41623.105568
distancea=598925.996333
distanceb = 0.000000
distancec = 0.000000
m3=446
m4 = 0
m6=66
Re: How to access "stats" variables
« Reply #1 on: December 29, 2022, 03:44:54 PM »
Hi,
I would guess that this data is stored in pound variables. I'm not familiar with which variables they are, but a email to NFS should get you the info you need.
If you do so would you be kind enough to post the results of your search here:

https://www.machsupport.com/forum/index.php?topic=40051.0

So others can replicate your results down the track.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: How to access "stats" variables
« Reply #2 on: January 02, 2023, 03:22:19 PM »
They gave me this from the API.h. 



/*!********************************************
 * Statistical Information functions.         *
 **********************************************/
struct mstats {
   int cannon_buf_depth;
   int la_cannon_buf_depth;
   double totalTime;
   double sessionTime;
   double spindleTime;
   long m3count;
   long m4count;
   long m6count;
   double xDistance;
   double yDistance;
   double zDistance;
   double aDistance;
   double bDistance;
   double cDistance;
};
Re: How to access "stats" variables
« Reply #3 on: January 02, 2023, 09:16:46 PM »
Hi,
well, that describes a data structure in C....but I'm not sure how we can use it.

We have Lua compiler but not a C compiler. I'm not sure how to go about accessing a C structure using the tools we have in Mach4.

I'd still guess that the individual data values that make up the structure are still in pound variable form....but how to work out which ones?.
My first guess  to search for the values would be to write a Lua script which searches through all the pound variables one by one until
you hit a match. For instance, if you know the current state of the accumulated X axis is 1234.56789 then search through all the variable until
you find a match. It would be a fair guess that the variable which has a numeric match is the right one.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: How to access "stats" variables
« Reply #4 on: January 02, 2023, 09:52:34 PM »
Ya, I hadn't spent much time on it yet to figure out exactly how to use it.  I'm a HW guy not SW, so its always takes me a while to work through these things. 

Attached is the whole API.h.  There is a reference below that structure to this API: 
MACHAPI_NS int MACH_APIENTRY mcCntlSetStats(MINSTANCE mInst, mstats_t *stats);

I was assuming that I need to figure out how to use that, but I could be wrong.  This API is not in the API manual that I have.  This is a Lua API, isn't it?

thanks,
jim

Re: How to access "stats" variables
« Reply #5 on: January 02, 2023, 10:45:04 PM »
Hi,

Code: [Select]
mcCntlSetStats
C/C++ Syntax:
int mcCntlSetStats(
MINSTANCE mInst,
mstats_t *stats);

LUA Syntax:
N/A

Description:
Set/reset the machine statistics.

Mach4Hobby/Doc/Mach4CoreAPI.hm is the API I'm familiar with. Note that all the entries have both a C syntax, for those writing in C, say a plugin
developer, and a Lua syntax, which is more appropriate for us users writing scripts. This particular API has no Lua syntax, ie it's implemented in C only.
Given that's the case then I would suggest that as a 'Hardware Guy' that means that you can't do anything about it.

I keep coming back to finding the pound variables that hold the data....that's something you can do.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: How to access "stats" variables
« Reply #6 on: January 03, 2023, 12:26:38 AM »
Thanks for clarifying that.  I will ask them if there is a pound variable list they will give me.
Re: How to access "stats" variables
« Reply #7 on: January 03, 2023, 12:58:43 AM »
Hi,
we should be able to write a script to find them.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: How to access "stats" variables
« Reply #8 on: January 03, 2023, 10:05:32 AM »
Hi Craig,

The response I got back from NFS was:
"The API.h   lists all of the permanent pound variables assigned by FANUC.
If you don't see it in that list, it isn't there. "

The header file that I received from him (the one I previously attached) only has that C API in it, it doesn't have any variables defined in there to go along with it, or any named that would make me think they are related.  I'm new to Mach4 scripting, so maybe I'm trying to read too much between the lines.  Are you saying that is their public header file, but they still have other internal ones for variables they don't want to commit to not changing in the future, so thats what he means by "permantent pound variables" and "if you don't see it, its not there"?

Thanks,
jim
Re: How to access "stats" variables
« Reply #9 on: January 03, 2023, 02:43:02 PM »
Hi,
well I cant find any pound variables to match. I wrote this macro:

Code: [Select]
function m500()
local inst=mc.mcGetInstance()
local varNum=0;
local dataValue=0;
for varNum=0, 19999,1 do
dataValue=mc.mcCntlGetPoundVar(inst,varNum)
if(dataValue>=178.5 and dataValue<=178.6)then
wx.wxMessageBox(tostring(varNum))
end
end
end
if (mc.mcInEditor()==1)then
m500()
end

It purpose is to scan through all the pound variables up to #19999 and give a message should a variable have a numeric match for:

Code: [Select]
[Stats]
TotalHours=746.538345
SpindleHours=0.005496
DistanceX=234.864638
DistanceY=178.509416
DistanceZ=16.935888
DistanceA=0.000000
DistanceB=0.000000
DistanceC=0.000000
M3=1
M4=0
M6=37

which was excerpted from the .ini file (on my regular PC, not the machine PC)
I have tested the macro and am reasonably confident that it works and would find a numeric match if there is one....but nothing???

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'