Hello Guest it is December 10, 2024, 06:08:57 AM

Author Topic: Mach4IPC.dll interop for C#  (Read 4498 times)

0 Members and 1 Guest are viewing this topic.

Offline wz2b

*
  •  12 12
Mach4IPC.dll interop for C#
« on: December 21, 2021, 08:32:55 AM »
Does anybody have a Mach4IPC interop bindings library for C#?

Offline wz2b

*
  •  12 12
Re: Mach4IPC.dll interop for C#
« Reply #1 on: December 22, 2021, 12:15:07 PM »
I'm still trying to get real time XYZ and machine state out of my older Mach 4 and am taking another path.  I watched a youtube video where somebody was doing some control by attaching to MachIPC.DLL from C#.  I couldn't find any documentation on MachIPC.DLL but I did a dumpbin on it and it has many of the same symbols as MachCore.DLL including things like:

Code: [Select]
    _mcAxisGetMachinePos@12
    _mcAxisIsHoming@12
    _mcAxisIsStill@12
    _mcSpindleGetMotorRPM@8
    _mcAxisGetPos@12

Based on nothing more than the names matching, I copied a few mappings out of one of the samples, hoping it would work the same:

Code: [Select]
[DllImport("Mach4IPC.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int mcAxisGetPos(
[param: MarshalAs(UnmanagedType.I4)] int mInst,
[param: MarshalAs(UnmanagedType.I4)] int axis,
[param: MarshalAs(UnmanagedType.R8), In(), Out()] ref double val);

[DllImport("Mach4IPC.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int mcAxisGetMachinePos(
[param: MarshalAs(UnmanagedType.I4)] int mInst,
[param: MarshalAs(UnmanagedType.I4)] int axis,
[param: MarshalAs(UnmanagedType.R8), In(), Out()] ref double val);


I don't know that is right, and I don't know that MachIPC.DLL is intended to be used this way, but based on the name it seems so.  My goal here would be to create a standalone program that gets the info that I want out of running Mach4 and then sends it out over the network, probably via MQTT.

I do not know how to begin a 'session' either - mInst looks like it's some kind of handle that I need to obtain first.

Am I on the right path here?