|
|
using System;
|
|
|
using System.Text;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
namespace ocean
|
|
|
{//运动控制模块
|
|
|
|
|
|
public enum EDevStatus
|
|
|
{//对象状态
|
|
|
EDev_NOINIT = 0, //未初始化
|
|
|
EDev_ERROR, //异常
|
|
|
EDev_IDLE, //就绪
|
|
|
EMove_NOHOME = 3, //未回原
|
|
|
EMove_STOP, //停止状态 -- 异常停止,限位停止
|
|
|
EMove_ISMOVING, //运动中
|
|
|
EMove_ISHOME, //回原中
|
|
|
EMove_PAUSE, //暂停
|
|
|
EMove_PAUSING, //正在暂停
|
|
|
EMove_STOPING, //正在停止
|
|
|
};
|
|
|
|
|
|
public enum EIOType
|
|
|
{//IO类型
|
|
|
IOT_COMIN = 0, //通用输入
|
|
|
IOT_COMOUT, //通用输出
|
|
|
IOT_LIMITP, //正限位
|
|
|
IOT_LIMITN, //负限位
|
|
|
IOT_ALARM, //报警
|
|
|
IOT_HOME, //原点
|
|
|
IOT_SEVON, //使能
|
|
|
IOT_CLEARALARM, //清除报警
|
|
|
};
|
|
|
|
|
|
public enum EMPosType
|
|
|
{//轴位置类型
|
|
|
EMPos_Default = -1, //默认位置 伺服-编码器 步进-规划器
|
|
|
EMPos_Encoder, //编码器位置
|
|
|
EMPos_Profile, //规划器位置
|
|
|
};
|
|
|
|
|
|
public enum EMIOSYSType
|
|
|
{//系统IO类型
|
|
|
IOS_Normal = 0, //普通IO
|
|
|
IOS_START, //启动
|
|
|
IOS_RESET, //复位
|
|
|
IOS_ESTOP, //急停
|
|
|
IOS_PAUSE, //暂停
|
|
|
IOS_STOP, //停止
|
|
|
IOS_BRAKE, //刹车
|
|
|
};
|
|
|
|
|
|
public enum EMAxisType
|
|
|
{//轴类型
|
|
|
EAXIS_SERVO = 0, //伺服
|
|
|
EAXIS_STEPPER, //步进电机
|
|
|
EAXIS_FLOW, //旋转电机,每次运动清零位置 - 不需要回原
|
|
|
EAXIS_ABSSERVO, //绝对值编码器 - 可以不回原
|
|
|
};
|
|
|
|
|
|
public enum EMAxisDir
|
|
|
{//轴方向
|
|
|
EAXIS_X = 0, //横向
|
|
|
EAXIS_Y, //纵向
|
|
|
EAXIS_Z, //上下
|
|
|
EAXIS_U, //平面旋转
|
|
|
EAXIS_V, //横向旋转
|
|
|
EAXIS_W, //纵向旋转
|
|
|
};
|
|
|
|
|
|
public enum EMHomeType
|
|
|
{//回原方式
|
|
|
EHOME_LIMITN = 0, //先回负限位
|
|
|
EHOME_LIMITP, //先回正限位
|
|
|
EHOME_HOMEP, //找原点再精确回原
|
|
|
EHOME_IOHOME, //IO控制回原
|
|
|
EHOME_GOHOME, //直接精确回原
|
|
|
EHOME_NOHOME, //不回原,直接以当前位置为原点
|
|
|
};
|
|
|
|
|
|
public enum EMIOVAL
|
|
|
{//IO操作
|
|
|
IOFF = 0, //关闭
|
|
|
ION, //打开
|
|
|
};
|
|
|
|
|
|
public enum EMDir
|
|
|
{//运动方向
|
|
|
DirN = 0, //负方向
|
|
|
DirP, //正方向
|
|
|
};
|
|
|
|
|
|
public struct TPoint
|
|
|
{//点位
|
|
|
public int index; //点索引
|
|
|
public int reserved; //保留字符,保证按8位对齐
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string name; //点名称
|
|
|
public double x; //分别为x,y,z,u,v,w的坐标值
|
|
|
public double y;
|
|
|
public double z;
|
|
|
public double u;
|
|
|
public double v;
|
|
|
public double w;
|
|
|
};
|
|
|
|
|
|
public struct TLicenseInfo
|
|
|
{//许可信息
|
|
|
public int dyn; //8位动态机器码
|
|
|
public int perdate; //有效期 20181212 0标识无效
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string hd;
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string cpu;
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string mac;
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
|
|
public string sn; //机器码
|
|
|
};
|
|
|
|
|
|
public struct TVisionResult
|
|
|
{//视觉结果结构体
|
|
|
public int res; //结果 0 - ok
|
|
|
public int resCnt; //结果个数
|
|
|
public double v1; //结果
|
|
|
public double v2;
|
|
|
public double v3;
|
|
|
public double v4;
|
|
|
public double v5;
|
|
|
public double v6;
|
|
|
public double v7;
|
|
|
public double v8;
|
|
|
public double v9;
|
|
|
public double v10;
|
|
|
public double v11;
|
|
|
public double v12;
|
|
|
public double v13;
|
|
|
public double v14;
|
|
|
public double v15;
|
|
|
public double v16;
|
|
|
};
|
|
|
|
|
|
#region nouse
|
|
|
|
|
|
public struct TCard
|
|
|
{//卡数据结构
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string name;
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
|
|
|
public string dev;
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
|
|
public byte[] param; //初始化参数
|
|
|
public int cid; //卡ID
|
|
|
public UInt16 axisCnt; //轴数量 motor-轴/专用IO数量
|
|
|
public UInt16 ioCnt; //io-通用IO位数
|
|
|
public UInt16 adCnt; //ad-通道数量
|
|
|
public UInt16 reserved1; //备用1
|
|
|
public UInt16 reserved2; //备用2
|
|
|
public UInt16 reserved3; //备用3
|
|
|
};
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//底层插件注册接口
|
|
|
#region register_dll
|
|
|
|
|
|
//初始化 index 卡序号 ctx字符串参数 函数指针委托说明
|
|
|
public delegate int fun_init(ushort index, string ctx);
|
|
|
public delegate int fun_deinit(ushort index);
|
|
|
public delegate int fun_get_status(ushort index);
|
|
|
public delegate int fun_get_cmd_info(IntPtr pszcmddesc);
|
|
|
public delegate int fun_send_msg(ushort index, string msg, IntPtr res);
|
|
|
public delegate int fun_recv_msg(ushort index, string msg, IntPtr res, int timeout);
|
|
|
|
|
|
//控制卡底层继承类接口声明 -- 轴接口
|
|
|
public delegate int fun_axis_reset(ushort index, ushort axisIndex);
|
|
|
public delegate int fun_axis_home(ushort index, ushort axisIndex, ushort homeType, double pos, double offset, double vel);
|
|
|
public delegate int fun_axis_zero_pos(ushort index, ushort axisIndex);
|
|
|
public delegate int fun_axis_is_moving(ushort index, ushort axisIndex);
|
|
|
public delegate int fun_axis_set_speed(ushort index, ushort axisIndex, double vel, double acc, double dec);
|
|
|
public delegate int fun_axis_set_pos(ushort index, ushort axisIndex, double pos);
|
|
|
public delegate int fun_axis_stop(ushort index, ushort axisIndex, int type); //1急停 0平滑停止
|
|
|
|
|
|
//点位运动
|
|
|
public delegate int fun_axis_move_pos(ushort index, ushort axisIndex, double pos, double vel, double acc, double dec);
|
|
|
public delegate int fun_axis_move_offset(ushort index, ushort axisIndex, double offset, double vel, double acc, double dec);
|
|
|
public delegate int fun_axis_move_jog(ushort index, ushort axisIndex, int dir, double vel, double acc, double dec);
|
|
|
|
|
|
//轴输入输出
|
|
|
public delegate int fun_axis_read(ushort index, ushort axisIndex, int dio_type);
|
|
|
public delegate int fun_axis_write(ushort index, ushort axisIndex, ushort val, int do_type);
|
|
|
public delegate int fun_axis_get_pos(ushort index, ushort axisIndex, int postype, ref double pval);
|
|
|
|
|
|
//插补
|
|
|
//创建坐标系,成功返回坐标系ID>0 失败返回错误代码
|
|
|
public delegate int fun_create_crd(ushort index, IntPtr pAxisIndex, ushort nsize); //pAxisIndex -- ushort[]
|
|
|
public delegate int fun_add_line_pos(int crd, IntPtr ppos, ushort nsize, double vel, double acc, double endvel); //ppos -- double[]
|
|
|
public delegate int fun_add_arc_pos(int crd, IntPtr ppos1, IntPtr ppos2, IntPtr ppos3, ushort nsize, double vel, double acc, double endvel);
|
|
|
public delegate int fun_crd_move(int crd);
|
|
|
public delegate int fun_crd_is_moving(int crd, IntPtr progress); //int*
|
|
|
public delegate int fun_close_crd(int crd);
|
|
|
|
|
|
//控制卡底层继承类接口声明 -- IO接口
|
|
|
public delegate int fun_read_in(ushort index, ushort in_index);
|
|
|
public delegate int fun_read_out(ushort index, ushort out_index);
|
|
|
public delegate int fun_write_out(ushort index, ushort out_index, ushort val);
|
|
|
|
|
|
//控制卡底层继承类接口声明 -- AD接口
|
|
|
public delegate int fun_read_ad(ushort index, ushort ad_index, IntPtr pVal); //double*
|
|
|
public delegate int fun_write_ad(ushort index, ushort ad_index, double val);
|
|
|
|
|
|
public struct MotorFun
|
|
|
{//回调函数列表
|
|
|
public fun_init funinit;
|
|
|
public fun_deinit fundeinit;
|
|
|
public fun_get_status funstatus;
|
|
|
public fun_send_msg funsend;
|
|
|
public fun_recv_msg funrecv;
|
|
|
public fun_get_cmd_info funcmdinfo;
|
|
|
|
|
|
public fun_axis_reset funreset;
|
|
|
public fun_axis_home funhome;
|
|
|
public fun_axis_zero_pos funzero;
|
|
|
public fun_axis_is_moving funismoving;
|
|
|
public fun_axis_set_speed funsetspeed;
|
|
|
public fun_axis_set_pos funsetpos;
|
|
|
public fun_axis_stop funstop;
|
|
|
public fun_axis_move_pos funmovepos;
|
|
|
public fun_axis_move_offset funmoveoffset;
|
|
|
public fun_axis_move_jog funmovejog;
|
|
|
public fun_axis_read funaxisread;
|
|
|
public fun_axis_write funaxiswrite;
|
|
|
public fun_axis_get_pos fungetpos;
|
|
|
public fun_create_crd funcrd;
|
|
|
public fun_add_line_pos funaddline;
|
|
|
public fun_add_arc_pos funaddarc;
|
|
|
public fun_crd_move funcrdmove;
|
|
|
public fun_crd_is_moving funcrdmoving;
|
|
|
public fun_close_crd funclosecrd;
|
|
|
|
|
|
public fun_read_in funreadin;
|
|
|
public fun_read_out funreadout;
|
|
|
public fun_write_out funwriteout;
|
|
|
|
|
|
public fun_read_ad funreadad;
|
|
|
public fun_write_ad funwritead;
|
|
|
};
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//安全类接口回调
|
|
|
//pid 轴ID或IO
|
|
|
//curval 当前位置 可标识axis/io位置
|
|
|
//val 目标位置 表示运动目标位置(mm) IO表示气缸控制目标信号
|
|
|
//bhome 轴ID时1表示回原,0表示不是回原,IO控制时此参数无意义
|
|
|
//返回值 返回1表示检测通过,可以运动 返回0表示检测不通过,则control会终止该轴/IO所有运动接口
|
|
|
public delegate int FunSafeCallBack(int pid, int curval, int val, int bhome);
|
|
|
|
|
|
public class control
|
|
|
{
|
|
|
/***********************************************
|
|
|
*Function: 注册一个插件增加一个插件
|
|
|
*Intput: pszdev 硬件ID,不能重复
|
|
|
pszdesc 硬件描述符 <32字节
|
|
|
pszhome 回原描述符 多种回原方式以;分割<256字节
|
|
|
ctx 初始化参数描述符 多个参数以;分割<256字节 参数描述与默认值以|分割
|
|
|
axiscnt 插件支持轴数量
|
|
|
iocnt 插件支持IO数量
|
|
|
adcnt 插件支持AD数量
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS:如果需要在应用层注册插件,每次程序启动必须按以下步骤初始化:
|
|
|
1. 调用control_init 初始化模块
|
|
|
2. 调用control_regist_dev 注册插件
|
|
|
3. 调用control_load_cfg 加载配置文件
|
|
|
***********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "regist_card_devs", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int regist(string pszdev, string pszdesc,
|
|
|
string pszhome, string ctx, ushort axiscnt,
|
|
|
ushort iocnt, ushort adcnt, ref MotorFun pfunList);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 初始化control模块资源
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 初始化以后才能调用该模块其它接口
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int init();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 释放control模块资源
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int deinit();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 独占方式启动所有控制卡
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_startup", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int startup();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 停止控制所有卡
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_shutdown", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int shutdown();
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: control服务是否在运行
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 正在运行返回1,否则返回0
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_is_run", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int isrun();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取control控制引擎版本号 - 4位整数
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 返回control版本号1401->1.4.01
|
|
|
*PS: 当版本号为5位时,为beta测试版,个位数为测试版本号
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int version();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 整体复位、重置 -- 仅发送指令
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 向所有插件发送"reset"指令
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int reset();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 整体暂停 -- 仅发送指令
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 向所有插件发送"pause,1/0"指令
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "control_pause", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int pause(int bpause = 1);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 加载点位、料盘配置 -- 默认data\\product
|
|
|
*Intput: path 配置目录 <256字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 加载成功后,下次会默认从此目录读取
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "load_points", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int load_points(string path);
|
|
|
|
|
|
/***********************************************
|
|
|
*Function: 初始化一个对象(卡/视觉/工站)
|
|
|
*Intput: pid 对象ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "init_dev", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int init_dev(int pid);
|
|
|
|
|
|
/***********************************************
|
|
|
*Function: 反初始化一个对象(卡/视觉/工站)
|
|
|
*Intput: pid 对象ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "uninit_dev", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int uninit_dev(int pid);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 向指定对象发送消息(万能接口)
|
|
|
*Intput: pid 对象ID
|
|
|
msg 要发送的消息
|
|
|
res 返回消息,可以不传
|
|
|
*Output: res 返回消息,可以不传
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "send_custom_msg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int send_custom_msg(int pid, string msg, uint z = 0);
|
|
|
|
|
|
[DllImport(@"control.dll", EntryPoint = "send_custom_msg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int send_custom_msg(int pid, string msg, StringBuilder res);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 接收指定对象消息(万能接口)
|
|
|
*Intput: pid 对象ID
|
|
|
msg 过滤字段及参数,可以为空字符串
|
|
|
res 返回消息
|
|
|
timeout 超时机制 默认不等待 [0,500] 单位ms
|
|
|
*Output: res 返回消息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 超时返回ERR_TIMEOUT
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "recv_custom_msg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int recv_custom_msg(int pid, string msg, StringBuilder res, int timeout = 0);
|
|
|
|
|
|
/***********************************************
|
|
|
*Function: 获取一个对象状态
|
|
|
*Intput: pid 对象ID
|
|
|
*Output: NULL
|
|
|
*Return: 返回对象状态,参考EDevStatus/EMoveStatus
|
|
|
*PS: 卡/工站/视觉/轴,全部使用此接口
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_dev_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_dev_status(int pid);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 通过名称获取一个对象的ID > 0
|
|
|
*Intput: pszname 对象名称
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回对象ID,失败返回错误码<0
|
|
|
*PS: 可以获取control模块所有对象ID
|
|
|
包括卡/视觉/工站/轴/IO/AD
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_id_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_id_by_name(string pszname);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 清除指定轴限位状态/停止标识 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 停止状态下才可调用此接口
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_reset(int axis);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴停止运动 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
stoptype 0平滑停止 1紧急停止
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_stop(int axis, int stoptype = 0);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴回原 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 调用 axis_status 判断回原是否结束
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_home", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_home(int axis);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 读取轴对应的特殊IO状态 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
dio_type io类型
|
|
|
*Output: NULL
|
|
|
*Return: 有信号1 无信号0, 其它为异常
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_read", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_read(int axis, EIOType dio_type);
|
|
|
public static bool axisIO(int axis, EIOType dio_type)
|
|
|
{
|
|
|
if (0 == axis) return false;
|
|
|
return axis_read(axis, dio_type) == 1;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置轴对应的特殊IO输出状态 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
dio_type io类型 仅限 使能、清除报警两种类型
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_write", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_write(int axis, EIOType dio_type, int val);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取指定轴当前位置 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
posType 0编码器位置 1规划器位置
|
|
|
*Output: pval 返回当前位置 mm
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_get_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_get_pos(int axis, ref double pval, int posType = -1);
|
|
|
public static double getAxisPos(int axis)
|
|
|
{
|
|
|
double val = 0;
|
|
|
int ret = axis_get_pos(axis, ref val);
|
|
|
return ret == 0 ? val : 0;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴jog运动 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
dir 0负方向 1正方向
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_move_jog", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_move_jog(int axis, int dir);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴点位运动 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
pos 目标位置
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_move_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_move_pos(int axis, double pos);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴强制点位运动 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
pos 目标位置
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 在运动中调用此接口,可以改变目标位置
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_set_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_set_pos(int axis, double pos);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定轴偏移量运动 -- 此接口创建工站后才有效
|
|
|
*Intput: axis 轴ID
|
|
|
offset 偏移量
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "axis_move_offset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int axis_move_offset(int axis, double offset);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置指定工站接下来的运动速度
|
|
|
*Intput: tid 工站ID
|
|
|
vel 运动速度 按百分比算 [0.01,100]
|
|
|
acc 加速度 按百分比算 [0.01,100]
|
|
|
dec 减速度 按百分比算 [0.01,100]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 点位运动中也可设置,仅更改速度,加减速下次运动才生效
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int set_speed(int tid, double vel, double acc, double dec);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取指定工站的速度
|
|
|
*Intput: tid 工站ID
|
|
|
vel 运动速度 按百分比算 [0.01,100]
|
|
|
acc 加速度 按百分比算 [0.01,100]
|
|
|
dec 减速度 按百分比算 [0.01,100]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 点位运动中也可设置,仅更改速度,加减速下次运动才生效
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_speed(int tid, ref double vel, ref double acc, ref double dec);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置指定工站的全局速度
|
|
|
*Intput: tid 工站ID
|
|
|
vel 最大值的百分比 [0.01,100]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS:工站最终运动速度会*全局速度的百分比,默认100%
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_global_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int set_global_speed(int tid, double vel);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取指定工站的全局速度
|
|
|
*Intput: tid 工站ID
|
|
|
pvel 最大值的百分比 [0.01,100]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_global_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_global_speed(int tid, ref double pvel);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function:清除指定工站所有轴限位状态/停止标识
|
|
|
*Intput: tid 工站ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 停止状态下才可调用
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "station_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int station_reset(int tid);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定工站开始回原
|
|
|
*Intput: tid 工站ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 调用get_dev_status 判断回原是否结束
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "station_home", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int station_home(int tid);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定工站暂停/恢复运动
|
|
|
*Intput: tid 工站ID
|
|
|
ipause 1暂停 0恢复
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "station_pause", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int station_pause(int tid, int ipause = 1);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 让指定工站停止运动
|
|
|
*Intput: tid 工站ID
|
|
|
stoptype 0平滑停止 1紧急停止
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "station_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int station_stop(int tid, int stoptype = 0);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定工站点位运动到指定位置
|
|
|
*Intput: tid 工站ID
|
|
|
ptPos,点位置,包含每个轴目标位置
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 此接口支持强制点位运动,即点位运动中时,可以强制改变目标位置
|
|
|
*PS: 未回原也可以调用此接口运动
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "go_to_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int go_to_pos(int tid, IntPtr ptr);
|
|
|
public static int gopos(int tid, TPoint pos)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(pos, ptr, false);
|
|
|
ret = go_to_pos(tid, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定工站点位运动到指定点
|
|
|
*Intput: tid 工站ID
|
|
|
index,点索引[0,200] 为0时基于当前位置
|
|
|
ptOffset 是否增加偏移
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: index=0时,必须带偏移量,否则不运动
|
|
|
*PS: 此接口支持强制点位运动,即点位运动中时,可以强制改变目标位置
|
|
|
当index=0时,未回原也可以运动
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "go_to_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int go_to_point(int tid, int index, IntPtr ptr);
|
|
|
public static int go(int tid, int index)
|
|
|
{
|
|
|
return go_to_point(tid, index, IntPtr.Zero);
|
|
|
}
|
|
|
public static int go(int tid, int index, TPoint ptOffset)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(ptOffset, ptr, false);
|
|
|
ret = go_to_point(tid, index, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 指定工站直线插补运动到指定点
|
|
|
*Intput: tid 工站ID
|
|
|
index 点索引[0,200] 为0时基于当前位置
|
|
|
ptOffset 是否增加偏移
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "move_to_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int move_to_point(int tid, int index, IntPtr ptr);
|
|
|
public static int move(int tid, int index)
|
|
|
{
|
|
|
return move_to_point(tid, index, IntPtr.Zero);
|
|
|
}
|
|
|
public static int move(int tid, int index, TPoint ptOffset)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(ptOffset, ptr, false);
|
|
|
ret = move_to_point(tid, index, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 以当前位置为起始点, 圆弧插补运动
|
|
|
*Intput: tid 工站ID
|
|
|
iPointMiddle, 圆弧上的中间点;
|
|
|
iPointEnd, 圆弧上的终点;
|
|
|
ptOffset 是否增加偏移
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "move_arc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int move_arc(int tid, int iPointMiddle, int iPointEnd, IntPtr ptr);
|
|
|
public static int arc(int tid, int iPointMiddle, int iPointEnd)
|
|
|
{
|
|
|
return move_arc(tid, iPointMiddle, iPointEnd, IntPtr.Zero);
|
|
|
}
|
|
|
public static int arc(int tid, int iPointMiddle, int iPointEnd, TPoint ptOffset)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(ptOffset, ptr, false);
|
|
|
ret = move_arc(tid, iPointMiddle, iPointEnd, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 添加直线插补运动点位到连续运动合集
|
|
|
*Intput: tid 工站ID
|
|
|
index 点索引
|
|
|
ptOffset 是否增加偏移
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "add_cp_line_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int add_cp_line_point(int tid, int index, IntPtr ptr);
|
|
|
public static int add_line(int tid, int index)
|
|
|
{
|
|
|
return add_cp_line_point(tid, index, IntPtr.Zero);
|
|
|
}
|
|
|
public static int add_line(int tid, int index, TPoint ptOffset)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(ptOffset, ptr, false);
|
|
|
ret = add_cp_line_point(tid, index, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 添加一段圆弧插补运动到连续运动合集
|
|
|
*Intput: tid 工站ID
|
|
|
iPointMiddle, 圆弧上的中间点;
|
|
|
iPointEnd, 圆弧上的终点;
|
|
|
ptOffset 是否增加偏移
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "add_cp_arc_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int add_cp_arc_point(int tid, int iPointMiddle, int iPointEnd, IntPtr ptr);
|
|
|
public static int add_arc(int tid, int iPointMiddle, int iPointEnd)
|
|
|
{
|
|
|
return add_cp_arc_point(tid, iPointMiddle, iPointEnd, IntPtr.Zero);
|
|
|
}
|
|
|
public static int add_arc(int tid, int iPointMiddle, int iPointEnd, TPoint ptOffset)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(ptOffset, ptr, false);
|
|
|
ret = add_cp_arc_point(tid, iPointMiddle, iPointEnd, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 启动cp运动
|
|
|
*Intput: tid 工站ID
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "start_cp_move", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int start_cp_move(int tid);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取指定工站的点位置(点列表的数据)
|
|
|
*Intput: tid,工站ID
|
|
|
name 点位名称
|
|
|
pt,用于接收工站位置的point结构体
|
|
|
*Output: 返回点位结构体指针
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_point_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_point(int tid, string name, ref TPoint pt);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取指定工站的点位置(点列表的数据)
|
|
|
*Intput: tid,工站ID
|
|
|
index,点位索引
|
|
|
pt 返回的点结构体
|
|
|
*Output: 返回点位结构体指针
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_point_by_index", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_point(int tid, int index, ref TPoint pt);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取料盘数据点位
|
|
|
*Intput: tid 工站ID
|
|
|
index,料盘索引 [1,50]
|
|
|
col 第几列 > 0
|
|
|
row 第几行 > 0
|
|
|
*Output: pt 返回的点结构体
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_point_by_pallet", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_point(int tid, int index, int col, int row, ref TPoint pt);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置点数据,只设置到内存,不会改变名字
|
|
|
*Intput: tid,工站ID
|
|
|
pt,要保存的点数据
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int set_point(int tid, IntPtr ptr);
|
|
|
public static int setpoint(int tid, TPoint pt)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(pt, ptr, false);
|
|
|
ret = set_point(tid, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 判断当前位置是否在指定点附近
|
|
|
*Intput: tid 工站ID
|
|
|
index 点索引[1,200]
|
|
|
ptOffset 是否增加偏移
|
|
|
offset 最大偏移值
|
|
|
*Output: NULL
|
|
|
*Return: 1在 0不在,其它返回错误码
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "is_near_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int is_near_point(int tid, int index, IntPtr ptr, double offset = 0.1);
|
|
|
public static bool chk_near_pos(int tid, int index)
|
|
|
{
|
|
|
return is_near_point(tid, index, IntPtr.Zero) == 1;
|
|
|
}
|
|
|
|
|
|
public static bool chk_near_pos(int tid, int index, TPoint ptoffset, double offset = 0.01)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ptoffset));
|
|
|
Marshal.StructureToPtr(ptoffset, ptr, false);
|
|
|
ret = is_near_point(tid, index, ptr, offset);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret == 1;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置点位置数据 -- 名称、点位一块修改
|
|
|
*Intput: tid 工站ID
|
|
|
pt 要保存的点数据 点位索引[1,200]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "save_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int save_point(int tid, IntPtr ptr);
|
|
|
public static int savepoint(int tid, TPoint pt)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
TPoint point = new TPoint();
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(point));
|
|
|
Marshal.StructureToPtr(pt, ptr, false);
|
|
|
ret = save_point(tid, ptr);
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 示教当前点位
|
|
|
*Intput: tid 工站ID
|
|
|
index 点位索引[1,200]
|
|
|
name 点位名称 长度[1,31]
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "teach_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int teach_point(int tid, int index, string name);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 注册安全检测接口,注册后所有运动+IO操作
|
|
|
都会回调到接口检查安全性
|
|
|
*Intput: fun... 回调接口
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 传入fun=0即为反注册,注册后必须打开配置中的bSafeChk开关才生效
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "regist_safe_chk", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int regist_safe_chk(FunSafeCallBack fun);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 启动安全控制限制
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "start_safe_monitor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int start_safe_monitor();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 停止安全控制限制
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "stop_safe_monitor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int stop_safe_monitor();
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 根据名称读取指定io的输入/输出状态
|
|
|
*Intput: name io名称
|
|
|
*Output: NULL
|
|
|
*Return: 有信号1 无信号0, 其它为异常
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "read_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int read(string name);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function:根据IO名称设置一个IO输出状态
|
|
|
*Intput: out_name: io名称
|
|
|
val 操作值 必须为1/0
|
|
|
*Output: 无
|
|
|
*Return: 成功返回0,失败返回错误代码
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "write_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int write(string out_name, ushort val);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 读取输入电压值
|
|
|
*Intput: ad_name, ad名称
|
|
|
*Output: pval 读取到的电压值
|
|
|
*Return: 成功返回0,失败返回错误代码
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "read_ad_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int read(string ad_name, ref double pVal);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 根据名称写入指定ad的输出值
|
|
|
*Intput: name ad别名
|
|
|
val 电压值
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*********************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "write_ad_by_name", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int write(string ad_name, double val);
|
|
|
|
|
|
/**************************************************
|
|
|
*Function: 获取系统IO状态
|
|
|
*Intput: type 系统IO类型 start <= type <= stop
|
|
|
*Output: NULL
|
|
|
*Return: 返回组合状态1/0,start都为1则返回1,其它都为0则0
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_sysio_value", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int get_sysio_value(int type);
|
|
|
|
|
|
/**************************************************
|
|
|
*Function: 打开/关闭所有刹车
|
|
|
*Intput: val 1刹车有效 0刹车无效
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_break", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int set_break(int val = 1);
|
|
|
public static int get_start_value()
|
|
|
{
|
|
|
return get_sysio_value(Convert.ToInt32(EMIOSYSType.IOS_START));
|
|
|
}
|
|
|
public static int get_reset_value()
|
|
|
{
|
|
|
return get_sysio_value(Convert.ToInt32(EMIOSYSType.IOS_RESET));
|
|
|
}
|
|
|
public static int get_pause_value()
|
|
|
{
|
|
|
return get_sysio_value(Convert.ToInt32(EMIOSYSType.IOS_PAUSE));
|
|
|
}
|
|
|
public static int get_estop_value()
|
|
|
{
|
|
|
return get_sysio_value(Convert.ToInt32(EMIOSYSType.IOS_ESTOP));
|
|
|
}
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 视觉处理指令,拍照完成返回
|
|
|
*Intput: vid 视觉ID
|
|
|
secne 场景ID,需根据视觉通讯协议传递
|
|
|
timeout 超时设置
|
|
|
*Output: NULL
|
|
|
*Return: EM_ERR_CODE
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "vision_process", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int process(int vid, int secne);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取视觉处理结果
|
|
|
*Intput: vid 视觉ID
|
|
|
secne 场景ID,需根据视觉通讯协议传递
|
|
|
timeout 超时设置 -1无限等待
|
|
|
*Output: pres 返回结果
|
|
|
*Return: EM_ERR_CODE 超时返回ERR_TIMEOUT
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "recv_process_result", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int recv_result(int vid, int secne, ref TVisionResult pres, int timeout = -1);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取本机注册信息
|
|
|
*Intput: NULL
|
|
|
*Output: pInfo 注册信息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "license_get_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int license_get_info(ref TLicenseInfo info);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 本机注册licence
|
|
|
*Intput: pszregsn 注册码
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "license_regist", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int regist(string pszregsn);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取许可证是否有效
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 有效返回1,无效返回0
|
|
|
******************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "license_is_valid", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int license_is_valid();
|
|
|
|
|
|
#region nouse
|
|
|
|
|
|
public struct TAxisParam
|
|
|
{//轴参数
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string name; //名称
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string outIO; //回原IO or 刹车IO
|
|
|
public int axis; //轴ID
|
|
|
public int cid; //卡ID
|
|
|
public int index; //在当前卡的索引
|
|
|
public int homeIndex; //回原方法序号 参考 插件返回的回原方式序列 -- 超过最大序号表示自定义回原
|
|
|
public int bDirNeg; //方向取反 1取反 0不取反
|
|
|
public EMAxisDir dir; //0==x 1==y 2==z 3==u 4==v 5==w
|
|
|
public EMAxisType motorType; //参考 0伺服, 1步进 2流水线 3绝对值编码器
|
|
|
public EMHomeType homeType; //回原方式 0负限位 1回正限位 2找原点 3IO控制回原 4直接回零 5直接回零 6不回零
|
|
|
|
|
|
public int homePos; //回原搜索的距离+方向 mm
|
|
|
public int limitN; //负限位位置 软限位
|
|
|
public int limitP; //正限位位置 软限位
|
|
|
public int highHomePos; //高速回原位置,为0则禁用高速回原
|
|
|
public int iAfterhomeOffset; //回原后偏移量
|
|
|
public int arriveOffset; //到位误差 0表示无效 否则会检查编码器与规划期误差,到位后才结束运动
|
|
|
|
|
|
public double limitvel; //搜索限位速度 mm/s
|
|
|
public double homeVel; //搜索原点速度 mm/s
|
|
|
public double maxVel; //最大工作速度 mm/s
|
|
|
public double maxAcc; //最大工作加速度 mm/s^2
|
|
|
public double maxDec; //最大工作减速度 mm/s^2
|
|
|
public double stepvalue; //1mm对应多少脉冲
|
|
|
};
|
|
|
|
|
|
public struct TAdParam
|
|
|
{//ad参数 最终ad = readAD * ratio + offset
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string name; //名称
|
|
|
public double ratio; //比例、系数
|
|
|
public double offset; //补偿值
|
|
|
public int aid; //ID
|
|
|
public int cid; //卡ID
|
|
|
public int index; //索引
|
|
|
public int reserved; //保留字符,8位对齐
|
|
|
};
|
|
|
|
|
|
public struct IOConfig
|
|
|
{//io参数
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
public string name; //名称
|
|
|
public int iid; //ID
|
|
|
public int cid; //卡ID
|
|
|
public int index; //索引
|
|
|
public int sense; //是否取反 0取反 1不取反
|
|
|
public EIOType type; //参考 EIOType 通用输入/输出 限位/原点等
|
|
|
public EMIOSYSType ios; //参考 EMIOSYSType 系统类型,开始?停止?等等
|
|
|
};
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 通过卡ID获取卡信息
|
|
|
*Intput: card 卡ID
|
|
|
*Output: pcard 返回卡信息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_card", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_card(int card, ref TCard pcard);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取轴信息
|
|
|
*Intput: axis 轴ID
|
|
|
*Output: pAxisParam 轴信息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: pAxisParam 为空判断轴是否存在
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_axis_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_axis_info(int axis, ref TAxisParam paxis);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取ad信息
|
|
|
*Intput: aid ID
|
|
|
*Output: pad ad信息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: pAdParam 为空判断ad是否存在
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_ad_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_ad_info(int aid, ref TAdParam pad);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 获取Io信息
|
|
|
*Intput: iid ID
|
|
|
*Output: pio io信息
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: pIoParam 为空判断io是否存在
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "get_io_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
public static extern int get_io_info(int iid, ref IOConfig pio);
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置轴信息,以结构体中的ID为准
|
|
|
*Intput: pAxisParam,轴参数结构体
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
*PS: 仅支持修改部分项
|
|
|
*PS:
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_axis_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int set_axis(IntPtr ptr);
|
|
|
public static bool set_axis_info(TAxisParam paxis)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(paxis));
|
|
|
Marshal.StructureToPtr(paxis, ptr, false);
|
|
|
ret = set_axis(ptr);
|
|
|
Marshal.FreeHGlobal(ptr); //释放非托管内存
|
|
|
return 0 == ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置ad信息,以结构体中的ID为准
|
|
|
*Intput: pAdParam,ad参数结构体
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_ad_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int set_ad(IntPtr ptr);
|
|
|
public static bool set_ad_info(TAdParam pad)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(pad));
|
|
|
Marshal.StructureToPtr(pad, ptr, false);
|
|
|
ret = set_ad(ptr);
|
|
|
Marshal.FreeHGlobal(ptr); //释放非托管内存
|
|
|
return 0 == ret;
|
|
|
}
|
|
|
|
|
|
/*********************************************
|
|
|
*Function: 设置Io信息,以结构体中的ID为准
|
|
|
*Intput: pio,Io参数结构体
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码<0
|
|
|
************************************************/
|
|
|
[DllImport(@"control.dll", EntryPoint = "set_io_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
private static extern int set_io(IntPtr ptr);
|
|
|
public static bool set_io_info(IOConfig pio)
|
|
|
{
|
|
|
IntPtr ptr;
|
|
|
int ret = 0;
|
|
|
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(pio));
|
|
|
Marshal.StructureToPtr(pio, ptr, false);
|
|
|
ret = set_io(ptr);
|
|
|
Marshal.FreeHGlobal(ptr); //释放非托管内存
|
|
|
return 0 == ret;
|
|
|
}
|
|
|
|
|
|
// /*********************************************
|
|
|
// *Function: 通过工站ID获取轴组信息
|
|
|
// *Intput: tid,工站ID
|
|
|
// *Output: pStation,工站信息 传空可以判断是否存在
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_station", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_axis_group(int tid, ref TAxisGroup pStation);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 通过工站ID获取机器人信息
|
|
|
// *Intput: tid,工站ID
|
|
|
// *Output: pStation,工站信息 传空可以判断是否存在
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_station", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_robot(int tid, ref TRobot pStation);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 获取工站类型,电机 EM_AXIS_STATION / EM_NET_ROBOT
|
|
|
// *Intput: tid,工站ID
|
|
|
// *Output: NULL
|
|
|
// *Return: 返回工站类型,错误返回错误代码
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_station_type", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_type(int tid);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 设置指定工站tool坐标系
|
|
|
// *Intput: tid,工站ID
|
|
|
// index tool 序号 0 < index <= 10
|
|
|
// ptOffset 偏移量
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "create_tool", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int create_tool(int tid, int index, ref TPoint ptOffset);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 指定工站使用哪种模式
|
|
|
// *Intput: tid,工站ID
|
|
|
// iModel 0 世界坐标 1工具坐标
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "set_model", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int set_model(int tid, int iModel);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 获取指定工站使用的model
|
|
|
// *Intput: tid,工站ID
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回使用的model,失败返回错误码
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_model", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_model(int tid);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 设置料盘
|
|
|
// *Intput: tid,工站ID
|
|
|
// plt 料盘数据 0 < index <= 10
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "create_pallet", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int create_pallet(int tid, ref TPallet plt);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 根据索引获取料盘
|
|
|
// *Intput: tid,工站ID
|
|
|
// index 料盘索引
|
|
|
// plt 料盘数据 0 < index <= 10
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_pallet_by_index", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_pallet(int tid, int index, ref TPallet plt);
|
|
|
//
|
|
|
// /*********************************************
|
|
|
// *Function: 根据索引获取Tool点位偏移量
|
|
|
// *Intput: tid,工站ID
|
|
|
// index tool坐标系索引
|
|
|
// pt 坐标系数据 0 < index <= 10
|
|
|
// *Output: NULL
|
|
|
// *Return: 成功返回0,失败返回错误码<0
|
|
|
// *********************************************/
|
|
|
// [DllImport(@"control.dll", EntryPoint = "get_tool_by_index", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
|
// public static extern int get_tool_info(int tid, int index, ref TPoint pt);
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|