Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on January 13, 2020, 07:08:27 PM

Title: how use mcToolGetData with api
Post by: KatzYaakov on January 13, 2020, 07:08:27 PM
i use the mctoolgetdata from the lua
but when i try from api cant get any respone
i need the tool hight from the tool table

i use:
 [DllImport(@"C:\Mach4Hobby\Mach4IPC.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int mcToolGetData(
        [param: MarshalAs(UnmanagedType.I4)]  int mInst,
        [param: MarshalAs(UnmanagedType.LPStr)] string path,
         [param: MarshalAs(UnmanagedType.I4)]  int tollNum,
        [param: MarshalAs(UnmanagedType.R8), In(), Out()] ref double ret);

and the function:
double hreg = 0;
            int debug = mcToolGetData(0, "mc.MTOOL_MILL_HEIGHT", toolNum , ref  hreg);


i also try the type as int and i try all numbers from 0-20 same no any logical return
thanks
Title: Re: how use mcToolGetData with api
Post by: smurph on January 13, 2020, 08:01:14 PM
The second argument isn't a string.  It is an integer.  Also, you will get a response from the API in the return code.  Either that or it will crash from a bad API call.  Here is the proper description of the API call:

[DllImport("Mach4Core.dll", CallingConvention = CallingConvention.StdCall)]
   [return: MarshalAs(UnmanagedType.I4)]
   public static extern int mcToolGetData(
      [param: MarshalAs(UnmanagedType.I4)]  int mInst,
      [param: MarshalAs(UnmanagedType.I4)]  int Type,
      [param: MarshalAs(UnmanagedType.I4)]  int toolnum,
      [param: MarshalAs(UnmanagedType.R8), In(), Out()] ref double value);

double height = 0.0;
int toolnum = 1;
int debug = mcToolGetData(0, MTOOL_MILL_HEIGHT, toolNum, height);

MTOOL_MILL_HEIGHT is a constant that resolves to 11000.

All of this is in our SDK and this is FAR beyond the scope of this forum.  Unfortunately, you need to sign a nondisclosure agreement to gain access to the SDK.  Contact Todd Monto at our office to get that started. 

Steve
Title: Re: how use mcToolGetData with api
Post by: KatzYaakov on January 13, 2020, 10:42:13 PM
Thks alot
Do you mean i need put 11000 in the type ?
Ill contact tod tomarow thsnks alot
Title: Re: how use mcToolGetData with api
Post by: smurph on January 13, 2020, 11:28:30 PM
Yes.  11000 is the base number for the system variables where the tool information is stored.  We use a Funuc tool offset memory type C layout.  11000 + tool is the location in the system variables.  You could also use:

mcCntlGetPoundVar(inst, 11000 + tool, val);  // This really should be called mcCntlGetSystemVar()

This means that tool height information is also available to G code.  :)

Here is a handy dandy system variable memory layout chart for future reference:  http://www.machinetoolhelp.com/Applications/macro/system_variables.html (http://www.machinetoolhelp.com/Applications/macro/system_variables.html)

Steve