|
|
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: 有信号为1,无信号为0
|
|
|
*********************************************/
|
|
|
[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: 有信号为1,无信号为0
|
|
|
*********************************************/
|
|
|
[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: 有信号为1,无信号为0,失败返回EM_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);
|
|
|
|
|
|
}
|
|
|
}
|