Here is My structure:
public struct _LineMove_TypeDef
{
public int _mIpn;
public int _ObjAcc;
public int _ObjDec;
public int _ObjSpeed;
public int[] _AxisDist;
public int[] _axisPos;
}
Here is my DllImport:
[DllImport(DriveLibrary.dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = _GoToPosInLine)]
public static extern bool _GoToPosInLine(ref LineMoveStruct._LineMove_TypeDef _lm, bool dr = true, bool p = false, bool sync = false, bool IntPol = false);
public bool GoToPosInLine(ref LineMoveStruct._LineMove_TypeDef _lm, bool dr = true, bool p = false, bool sync = false, bool IntPol = false)
{
return _GoToPosInLine(ref _lm, dr, p, sync, IntPol);
}
What I have tried:
public LineMoveStruct._LineMove_TypeDef _lmp;
int pos = 200;
_lmp = new LineMoveStruct._LineMove_TypeDef();
_lmp._axisPos = new int[8];
_lmp._AxisDist = new int[8];
_lmp._axisPos[0] = pos*2;
_lmp._axisPos[1] = _lmp._axisPos[0];
_lmp._axisPos[2] = _lmp._axisPos[1];
_lmp._AxisDist[0] = 30;
_lmp._AxisDist[1] = 30;
_lmp._AxisDist[2] = 30;
_lmp._mIpn = 1;
_lmp._ObjAcc = 10;
_lmp._ObjDec = 20;
_lmp._ObjSpeed =2000;
IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(_lmp));
Marshal.StructureToPtr(_lmp, pnt, false);
LineMoveStruct._LineMove_TypeDef _lmp1;
_lmp1 = (LineMoveStruct._LineMove_TypeDef)Marshal.PtrToStructure(pnt, typeof(LineMoveStruct._LineMove_TypeDef));
Marshal.FreeHGlobal(pnt);
Motor._Mo.GoToPosInLine(ref _lmp);