You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
16 KiB
C#

2 years ago
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{//运动控制模块
public struct TSpeed
{//速度结构
double vel;
double acc;
double dec;
};
public enum EMPosType
{//轴位置类型
EMPos_Encoder = 0, //编码器位置
EMPos_Profile, //规划器位置
};
public enum EIOType
{//IO类型
IOT_COMIN = 0, //通用输入
IOT_COMOUT, //通用输出
IOT_LIMITP, //正限位
IOT_LIMITN, //负限位
IOT_ALARM, //报警
IOT_HOME, //原点
IOT_SEVON, //使能
IOT_CLEARALARM, //清除报警
};
public class gts
{
/*********************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: NULL
*PS:
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void Init();
/*********************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: NULL
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void Deinit();
/*********************************************
*Function:
*Intput: cardIndex 0
*Output: NULL
*Return: 0,<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "init_dev", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int InitCard(ushort cardIndex, IntPtr p = IntPtr.Zero);
/*********************************************
*Function:
*Intput: cardIndex 0
*Output: NULL
*Return: 0,<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "uninit_dev", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int CloseCard(ushort cardIndex);
/*********************************************
*Function:
*Intput: cardIndex 0
msg
stres
*Output: stres
*Return: 0,<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "send_custom_msg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int SendCommand(ushort cardIndex, string msg, StringBuilder stres);
/*********************************************
*Function: (使)
*Intput: cardIndex 0
stres,
key
timeout
*Output: lpMsg
*Return: 0,<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "recv_card_cmd", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int RecvCommand(ushort cardIndex, StringBuilder stres, string key, int timeout = 0);
/*********************************************
*Function: --
*Intput: pszcmddesc
*Output: pszcmddesc
*Return: 0
*PS: NULL
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "get_command_desc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int GetCommandDesc(StringBuilder stres);
/***********************************************
*Function:
*Intput: cardIndex 0
axisIndex 0
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisReset(ushort cardIndex, ushort axisIndex);
/***********************************************
*Function:
*Intput: cardIndex 0
axisIndex 0
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_zero_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisZeroPos(ushort cardIndex, ushort axisIndex);
/***********************************************
*Function: --
*Intput: cardIndex
axisIndex
homeType THomeTypeDesc
* 0-"捕获回原", 1-"伺服捕获回原", 2-"普通回原", 3-"index回原"
pos +
offset
vel
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_home", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisHome(ushort cardIndex, ushort axisIndex, ushort homeType, double pos, double offset, double vel);
/***********************************************
*Function:
*Intput: cindex
axisIndex
*Output: NULL
*Return: 1 0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_is_moving", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisIsMoving(ushort cardIndex, ushort axisIndex);
/***********************************************
*Function: /
*Intput: cindex
axisIndex
vel
acc
dec
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_set_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisSetSpeed(ushort cardIndex, ushort axisIndex, double vel, double acc, double dec);
/***********************************************
*Function: ,
*Intput: cindex
axisIndex
pos
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_set_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisSetPos(ushort cardIndex, ushort axisIndex, double pos);
/***********************************************
*Function:
*Intput: cindex
axisIndex
type 0:
1
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisStop(ushort cardIndex, ushort axisIndex, int type);
/***********************************************
*Function: ()
*Intput: cindex
axisIndex
dir 0 1
pspeed
*Output:
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_move_jog", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisMoveJog(ushort cardIndex, ushort axisIndex, int dir, ref TSpeed pspeed);
/***********************************************
*Function: ()
*Intput: cindex
axisIndex
pos
pspeed
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_move_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisMovePos(ushort cardIndex, ushort axisIndex, double pos, ref TSpeed pspeed);
/***********************************************
*Function: ()
*Intput: cindex
axisIndex
offset
pspeed
*Output:
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_move_offset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisMoveOffset(ushort cardIndex, ushort axisIndex, double offset, ref TSpeed pspeed);
/***********************************************
*Function: IO
*Intput: cindex
axisIndex
dio_type IO
*Output: NULL
*Return: 10
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_read", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisRead(ushort cardIndex, ushort axisIndex, EIOType dio_type);
/***********************************************
*Function: IO
*Intput: cindex
axisIndex
do_type IO
val 1 / 0
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_write", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisWrite(ushort cardIndex, ushort axisIndex, ushort val, EIOType dio_type);
/***********************************************
*Function: ()
*Intput: ardIndex,
axisIndex
postype 0 1
*Output: pval
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "axis_get_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AxisGetPos(ushort cardIndex, ushort axisIndex, EMPosType postype, ref double pval);
/***********************************************
*Function: io
*Intput: cindex
in_index io
*Output: NULL
*Return: 10
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "read_in", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ReadIn(ushort cardIndex, ushort in_index);
/***********************************************
*Function: IO
*Intput: cindex
out_index io
*Output: NULL
*Return: 10EM_ERR_CODE
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "read_out", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ReadOut(ushort cardIndex, ushort out_index);
/***********************************************
*Function: IO
*Intput: cindex
out_index io
val 1 / 0
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "write_out", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int WriteOut(ushort cardIndex, ushort out_index, ushort val);
/***********************************************
*Function:
*Intput: cindex
index
*Output: pVal
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "read_ad", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ReadAD(ushort cardIndex, ushort index, ref double pVal);
/***********************************************
*Function:
*Intput: cindex
index
val
*Output: NULL
*Return: 0<0
*********************************************/
[DllImport(@"motor_gugao.dll", EntryPoint = "read_ad", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int WriteAD(ushort cardIndex, ushort index, double val);
}
}