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.

947 lines
47 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{
public enum EOpsMsgType
{//ops消息类型
MSG_APP_CALL = 0, //应用层消息
MSG_RUN_ERR, //错误消息
MSG_RUN_WARN, //警告消息
};
public enum EOpsStatus
{//系统状态
EOPS_NOINIT = 0, //未初始化
EOPS_ESTOP, //急停
EOPS_NEED_RESET, //等待复位
EOPS_IDLE, //就绪
EOPS_RESET, //复位中
EOPS_STOP, //停止中
EOPS_PAUSE, //暂停
EOPS_RUNING, //运行中
};
public enum EProcStatus
{//流程状态
EPROC_IDLE = 0, //就绪
EPROC_RUNING, //运行中
EPROC_PAUSE, //暂停
EPROC_STOP, //手动停止 - 中断
EPROC_ERROR, //运行错误
};
public enum ETaskStatus
{//任务运行状态
ETASK_IDLE = 0, //就绪
ETASK_PROCESS, //准备中
ETASK_SLEEP, //延时
ETASK_WAIT_APP, //等待应用层处理
ETASK_WAIT_IO, //等待io信号
ETASK_WAIT_POS, //等待到达指定位置
ETASK_WAIT_MSG, //等待接收消息
ETASK_WAIT_PROC, //等待流程运行完成
ETASK_WAIT_MOVE, //等待运动完成
ETASK_WAIT_CHECK, //等待检测信号
ETASK_WAIT_SIGNAL, //等待资源信号
ETASK_WAIT_VISIONR, //等待视觉结果
ETASK_RUN_ERR, //运行错误
};
//流程消息回调基于ID
public delegate void ProcReCall(int evt, int id, IntPtr lparam);
public class ops
{
/****************************************************
*Function: 初始化ops模块资源
*Intput: NULL
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 初始化以后才能调用该模块其它接口
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "ops_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int init();
/****************************************************
*Function: 释放ops模块资源
*Intput: NULL
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "ops_deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int deinit();
/****************************************************
*Function: 获取当前版本号
*Intput: NULL
*Output: NULL
*Return: 返回当前ops版本号1401->1.4.01
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int version();
/****************************************************
*Function: 启动ops服务 -- 为启动时ops状态为 未初始化
*Intput: NULL
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
*PS: 会启动线程执行扫描
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "ops_startup", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int startup();
/****************************************************
*Function: 关闭ops服务 -- 关闭后ops状态为 未初始化
*Intput: NULL
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "ops_shutdown", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int shutdown();
/****************************************************
*Function: 加载新项目 -- 默认为default
*Intput: pszname 产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "load_project", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int load_project(string pszname);
/****************************************************
*Function: 加载新项目 -- 默认为default
*Intput: pszname 产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_cur_project", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_cur_project(StringBuilder pszname);
public static string get_project()
{
StringBuilder pszname = new StringBuilder(32);
return 0 == get_cur_project(pszname) ? pszname.ToString() : "";
}
/****************************************************
*Function: 创建一个产品 -- 默认为default
*Intput: pszname 产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS: 基于工作目录下创建
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "create_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int create_product(string pszname);
/****************************************************
*Function: 删除一个产品
*Intput: pszname 产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS: 基于工作目录下的产品目录,不能删除当前产品
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "delete_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int delete_product(string pszname);
/****************************************************
*Function: 复制一个产品参数到另一个产品
*Intput: pszname 产品名称<32字节
pszcopy 待copy的产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS: 基于工作目录下创建 若pszname不存在则新建
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "copy_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int copy_product(string pszname, string pszcopy);
/****************************************************
*Function: 加载某个产品
*Intput: pszname 产品名称<32字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS: 必须保证该产品是存在的,否则加载会失败
*PS: 加载流程、点位、配置等等
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "load_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int load_product(string pszname);
/****************************************************
*Function: 获取当前产品名称
*Intput: NULL
*Output: pszname 当前产品名称 保证32字节
*Return: 成功返回0 失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_cur_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_cur_products(StringBuilder pszname);
public static string get_cur_product()
{
StringBuilder pval = new StringBuilder(256);
int ret = get_cur_products(pval);
return ret == 0 ? pval.ToString() : "";
}
/****************************************************
*Function: 获取产品目录
*Intput: NULL
*Output: path 当前产品目录 保证256字节
*Return: 成功返回0 失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_product_path", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_product_paths(StringBuilder path);
public static string get_product_path()
{
StringBuilder pval = new StringBuilder(256);
int ret = get_product_paths(pval);
return ret == 0 ? pval.ToString() : "";
}
/****************************************************
*Function: 设置产品目录
*Intput: path 产品目录 保证256字节
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS: 设置产品目录以后,会把原来产品目录下所有产品文件夹拷贝到新目录
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "set_product_path", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int set_product_path(string pszname);
/****************************************************
*Function: 获取所有产品名称列表
*Intput: NULL
*Output: pathlist 名称列表缓冲区
*Return: 返回列表字符串长度,包含两个'\0'结束符
*PS: 可以传入NULL获取字符串长度再申请内存传入获取
*PS: 返回多个产品目录数量,以'\0'分割,以两个'\0'结束
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_all_product", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_all_products(StringBuilder pathlist);
public static string get_all_product()
{
StringBuilder pval = new StringBuilder(10240);
int ret = get_all_products(pval);
return ret == 0 ? pval.ToString() : "";
}
#region 模拟信号
/****************************************************
*Function: 设置模拟IO信号
*Intput: type 类型 参考 EM_IO_TYPE 如EM_IO_START
val 1为有信号 0为无信号
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
*PS: 本接口功能是往ops专用变量写入信号
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "ops_analog_signal", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int ops_analog_signal(int type, int val);
public static void analog_reset()
{//模拟复位信号
ops_analog_signal((int)EMIOSYSType.IOS_RESET, 1);
//ops_analog_signal((int)EMIOSYSType.IOS_RESET, 0);
}
public static void analog_start()
{//模拟启动信号
ops_analog_signal((int)EMIOSYSType.IOS_START, 1);
//ops_analog_signal((int)EMIOSYSType.IOS_START, 0);
}
public static void analog_stop()
{//模拟停止信号
ops_analog_signal((int)EMIOSYSType.IOS_STOP, 1);
//ops_analog_signal((int)EMIOSYSType.IOS_STOP, 0);
}
public static void analog_estop()
{//模拟急停信号
if (get_status() == (int)EOpsStatus.EOPS_ESTOP)
{
ops_analog_signal((int)EMIOSYSType.IOS_ESTOP, 0);
}
else if ((int)EOpsStatus.EOPS_NOINIT != get_status())
{
ops_analog_signal((int)EMIOSYSType.IOS_ESTOP, 1);
}
}
public static void analog_pause()
{//模拟暂停信号
if (get_status() == (int)EOpsStatus.EOPS_PAUSE)
{
ops_analog_signal((int)EMIOSYSType.IOS_PAUSE, 0);
}
else
{
ops_analog_signal((int)EMIOSYSType.IOS_PAUSE, 1);
}
}
#endregion
/****************************************************
*Function: 查询当前ops状态
*Intput: 无
*Output: 无
*Return: 当前系统状态ID 参考 EM_OPSYS_STATE
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_ops_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_status();
/****************************************************
*Function: 获取一个流程的当前状态或者运行信息
*Intput: pid 流程ID
*Output: sid 正在执行的步骤ID 可不传入
*Return: 失败返回错误码<0就绪返回0 参考 EPROC_STATE
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_proc_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_proc_status(int pid, ref int sid);
/****************************************************
*Function: 获取最后一次流程运行ct, 单位ms 根据名称
*Intput: pid 流程ID
*Output: NULL
*Return: 返回运行耗时失败返回0
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_proc_ct", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_proc_ct(int pid);
/****************************************************
*Function: 获取task当前状态
*Intput: task taskID - 工站、卡、流程、视觉ID
*Output: pid 正在执行的流程ID 可不传入
sid 正在执行的步骤ID 可不传入
nid 正在执行的节点ID 可不传入
*Return: 失败返回错误码<0就绪返回0 参考 ETaskStatus
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_task_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_task_status(int task, ref int pid, ref int sid, ref int nid);
public static int get_task_status(int task)
{//获取一个工站的流程运行状态
int pid = 0;
int sid = 0;
int nid = 0;
return get_task_status(task, ref pid, ref sid, ref nid);
}
public static int get_task_pid(int task)
{//获取一个task正在运行的流程ID
int pid = 0;
int sid = 0;
int nid = 0;
get_task_status(task, ref pid, ref sid, ref nid);
return pid;
}
public static int get_task_sid(int task)
{//获取一个task正在运行的步骤ID
int pid = 0;
int sid = 0;
int nid = 0;
get_task_status(task, ref pid, ref sid, ref nid);
return sid;
}
public static int get_task_node(int task)
{//获取一个task正在运行的节点ID
int pid = 0;
int sid = 0;
int nid = 0;
get_task_status(task, ref pid, ref sid, ref nid);
return nid;
}
/****************************************************
*Function: 启动一个流程
*Intput: pid 流程ID
sid 步骤ID 传入0表示从头开始
*Output: NULL
*Return: 成功返回0, 失败返回错误码<0
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "proc_start", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int proc_start(int proc, int sid = 0);
/****************************************************
*Function: 暂停一个流程
*Intput: pid 流程ID
bPause 是否暂停 1暂停 0取消
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "proc_pause", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int proc_pause(int pid, int bPause = 1);
/****************************************************
*Function: 停止一个流程
*Intput: pid 流程ID
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
*PS: 手动停止流程后状态会变成"停止",但不影响再次启动
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "proc_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int proc_stop(int pid);
/****************************************************
*Function: 重置流程状态 -- 停止且重置
*Intput: pid 流程ID
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
*PS: 重置流程后状态会变成"就绪"
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "proc_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int proc_reset(int pid);
/****************************************************
*Function: 调试某个步骤或某个节点
*Intput: id 步骤ID/节点ID
*Output: NULL
*Return: 成功返回0失败返回错误码<0
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "proc_debug", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int proc_debug(int id);
/****************************************************
*Function: 控制流程跳转到某个步骤继续执行
*Intput: sid 步骤ID
*Output: NULL
*Return: 成功返回0,失败返回错误码<0
*PS: 必须保证该流程处于消息触发时调用
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "jump_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int jump_step(int sid);
/****************************************************
*Function: 控制某task跳转到某个节点继续执行
*Intput: nid 节点ID
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 必须保证该task处于消息触发时调用
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "jump_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int jump_node(int sid);
/****************************************************
*Function: 注册流程消息接收函数
*Intput: fun 回调函数
lparam 任意型指针
*Output: NULL
*Return: 成功返回0 失败返回错误码
*PS:可以注册多个接口ops会回调每一个接口,
但只要执行跳转动作后,其余的跳转将返回错误
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "regist_proc_notify", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int regist_proc_notify(ProcReCall fun, IntPtr ptr);
/****************************************************
*Function: 反注册流程消息接收函数
*Intput: fun 回调函数
*Output: NULL
*Return: 成功返回0 失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "unregist_proc_notify", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int unregist_proc_notify(ProcReCall fun);
#region 料盘
public struct TMatrix
{//阵列/矩阵 循环工作盘 一行一行走
public ushort mid; //ID
public ushort bEnable; //是否启用
public ushort bSavePos; //退出时记住当前行列
public ushort bRunSType; //是否走S型0正常路线1走S线
public double startX; //起始位x(横向)
public double startY; //起始位y(纵向)
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string name; //阵列描述
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string col; //列间距格式 如20*5,30,31*2 标识有9列,首列为起始位前6列等间距207列间距308-9列间距31
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string row; //行间距格式 如20*4 标识5行等间距20,首行为起始位
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string off; //需要屏蔽区域,按序号(先行后列)从1开始 如1-4,6,10-15 标识禁用序号1-4序号6序号10-15
};
public struct TMatrixInfo
{//矩阵盘工作信息 -- 运行时
public int col; //总列数
public int row; //总行数
public int count; //工作次数 = 总数量-禁用数量
public int size; //总数量 = col*row
};
public struct TMatrixNode
{//矩阵盘节点信息
public int index; //索引
public int col; //列
public int row; //行
public int boff; //是否被禁用 1禁用 0正常
public double x; //col位置
public double y; //row位置
};
/****************************************************
*Function: 设置一个矩阵工作盘
*Intput: mid 阵列索引 [1-20]
pMatrix 矩阵工作盘基础数据
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 可以清空pMatrix所有参数即为删除工作盘
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "set_matrix", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int set_matrix(int mid, ref TMatrix pMatrix);
[DllImport(@"ops.dll", EntryPoint = "set_matrix", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int set_matrix(int mid, IntPtr p);
public static int set_matrix(int mid, TMatrix info)
{
int ret = 0;
int len = Marshal.SizeOf(info);
IntPtr p = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(info, p, false);
ret = set_matrix(mid, p);
Marshal.FreeHGlobal(p);
return ret;
}
/****************************************************
*Function: 获取一个矩阵工作盘信息
*Intput: mid 阵列索引 [1-20]
pMatrix 矩阵工作盘基础数据
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_matrix", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_matrix(int mid, ref TMatrix pMatrix);
/****************************************************
*Function: 获取一个矩阵工作盘行列信息
*Intput: mid 阵列索引 [1-20]
pInfo 矩阵工作盘信息
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_matrix_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_matrix_info(int mid, ref TMatrixInfo pInfo);
/****************************************************
*Function: 获取一个矩阵工作盘当前运行节点
*Intput: mid 阵列索引 [1-20]
pNode 矩阵工作盘节点信息
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_matrix_cur_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_matrix_cur_node(int mid, ref TMatrixNode pNode);
/****************************************************
*Function: 设置一个矩阵工作盘当前运行节点索引
*Intput: mid 阵列索引 [1-20]
index 节点序号 从1开始 0标识重置工作盘
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 可以指定被禁用点,但运行时会自动过滤
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "set_matrix_cur_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int set_matrix_cur_node(int mid, int index);
/****************************************************
*Function: 获取一个矩阵工作盘节点信息
*Intput: mid 阵列索引 [1-20]
index 节点序号 从1开始 不得超过总数
pNode 矩阵工作盘节点信息
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_matrix_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_matrix_node(int mid, int index, ref TMatrixNode pNode);
#endregion
#region nouse
public enum ENodeType
{//节点类型 -- 所有带索引的参数都是从1开始 0无效
ENODE_CALLAPP = 0, //callapp 等待应用层指令 -- 回调到应用层等待操作
ENODE_SLEEP, //sleep 50 设置延迟. 等待50ms
ENODE_SPEED, //speed 50 50 50 设置速度. vel,acc,dec速度百分比
ENODE_HOME, //home 1 [asyn] 工站回原.可传入参数单轴回原,整体回原时,单轴不再回原.轴索引[1,6] asyn-异步模式标识
ENODE_JOG, //jog 1 [dir] 单轴连续运动 1表示轴索引[1,6] dir: N表示运动方向为负 P表示正方向
ENODE_POS, //pos 1 val 单轴强制运动(运动中更改目标位置) 1表示轴索引[1,6] val 目标位置
ENODE_PTSET, //p1=pallet(1,1,2) +x(0.1) 设置点位.p0表示当前位置 pallet标识料盘 +x标识偏移 :x标识位置
ENODE_GO, //go p1 [+x(0.1)] 点位运动. p0表示当前位置 asyn-异步模式标识
ENODE_MOVE, //move p1 [+x(0.1)] 直线插补. p0表示当前位置 asyn-异步模式标识
ENODE_ARC, //arc p1,p2 [+x(0.1)] 圆弧插补.p0表示当前位置 asyn-异步模式标识
ENODE_WORK, //work p0 mid 根据预设矩阵获取工作点位 p0矩阵待设置点位, mid矩阵ID 每次执行结果会放到task变量中通过变量判断结束(0)
ENODE_CHKPOS, //chkpos p1 [+x(0.1)] [0.001] 位置检测.p0表示当前位置 0.001-位置检测精度(double)
ENODE_WAITMOVE, //waitm 等待运动、回原结束
ENODE_STOP, //stopm 停止运动
ENODE_WIO, //wio 110011=1 写入IO值 110011-IO名称 1-写入1
ENODE_RIO, //rio 110011=1 500 [100] 读取/等待IO值 500-超时时间 100-扫描时间
ENODE_CHK, //chks 110011=1 500 检测执行, IO或者变量是否有效,仅有效信号触发时继续执行本工站本步骤后面节点
ENODE_WAITSIGNAL, //waits 101=1 等待竞争信号量,无限等待,多个流程竞争资源时使用 101-变量名 竞争1信号
ENODE_PROC, //startp 1002 [asyn] 启动流程 1002-流程ID asyn 异步模式标识
ENODE_WAITPROC, //waitp 1002 等待流程结束
ENODE_VP, //vp 101 1 视觉处理 101视觉ID 1-当前场景
ENODE_VPR, //vpr 101 2 5000 a1 a2...(16)等待视觉处理结果 2场景ID 5000超时时间ms a1,a2...(16)最多传入16个变量
ENODE_SEND, //send 101 msg 发送消息到一个对象.101-对象ID msg-消息内容
ENODE_RECV, //recv 101 "msg" 5000 a1 a2...(8)接收一个对象的消息 msg指令或消息匹配参数 5000超时时间ms a1,a2...(8)最多传入8个变量
ENODE_SHOWMSG, //msgbox 1 msg 弹窗提示消息,确认后会把结果写入当前工站对应的变量中,根据结果进行后续操作 1-MessageType msg 脚本内容
ENODE_PRINT, //print msg 打印日志 msg-脚本内容
ENODE_JUMP, //jump 1101 task跳转到某个节点继续执行
ENODE_SCRIPT, //cmd 运行脚本
};
public enum ENodeState
{//节点标识
ENode_Normal = 0, //正常
ENode_Disable, //禁用
ENode_PError, //解析异常
};
public enum EMProcType
{//流程类型
EMProc_General = 0, //普通流程
EMProc_Start, //启动流程
EMProc_Reset, //复位流程
EMProc_Stop, //停止流程
EMProc_Pause, //暂停流程
EMProc_Continue, //恢复流程
EMProc_Sys, //系统流程 -- 自动启动且不响应系统信号
};
public struct TNodeInfo
{//节点信息
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string desc; //名称\描述
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 200)]
public string cmd; //命令行
public int nid; //节点ID
public int task; //taskID -- 卡ID、视觉ID、工站ID、流程ID
public ENodeType type; //节点类型
public ENodeState state; //0正常 1被禁用 2解析异常
};
public struct TStepInfo
{//步骤信息
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string desc; //名称\描述
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string script; //脚本
public int sid; //步骤ID
public int bDisable; //是否被禁用
};
public struct TFlow
{//流程信息
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string name; //名称
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string start; //启动IO
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string pause; //暂停IO
public int pid; //流程ID
public EMProcType type; //流程类型
};
/****************************************************
*Function: 创建一个流程
*Intput: pstProc 流程基本信息
*Output: pstProc 会填充procID
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "create_proc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int create_proc(IntPtr ptr);
public static int create_proc(TFlow pstProc)
{
IntPtr ptr;
int ret = 0;
TFlow p = new TFlow();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p));
Marshal.StructureToPtr(pstProc, ptr, false);
ret = create_proc(ptr);
Marshal.FreeHGlobal(ptr);
return ret;
}
/****************************************************
*Function: 修改一个流程
*Intput: pstProc 流程基本信息
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "update_proc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int update_proc(IntPtr ptr);
public static int update_proc(TFlow pstProc)
{
IntPtr ptr;
int ret = 0;
TFlow p = new TFlow();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p));
Marshal.StructureToPtr(pstProc, ptr, false);
ret = update_proc(ptr);
Marshal.FreeHGlobal(ptr);
return ret;
}
/****************************************************
*Function: 插入一个步骤到流程
*Intput: index 步骤序号
pstStep 步骤结构体
*Output: pstStep 会填充stepID
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "insert_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int insert_step(int pid, int sindex, IntPtr ptr);
public static int insert_step(int pid, int sindex, TStepInfo pstStep)
{
IntPtr ptr;
int ret = 0;
TStepInfo p = new TStepInfo();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p));
Marshal.StructureToPtr(pstStep, ptr, false);
ret = insert_step(pid, sindex, ptr);
Marshal.FreeHGlobal(ptr);
return ret;
}
/****************************************************
*Function: 修改一个步骤
*Intput: pstStep 步骤结构体
*Output: NULL
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "update_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int update_step(IntPtr ptr);
public static int update_step(TStepInfo pstStep)
{
IntPtr ptr;
int ret = 0;
TStepInfo p = new TStepInfo();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p));
Marshal.StructureToPtr(pstStep, ptr, false);
ret = update_step(p);
Marshal.FreeHGlobal(ptr);
return ret;
}
/****************************************************
*Function: 启用/禁用一个步骤 -- 根据步骤ID
*Intput: sid 步骤ID
bEnable 1启用 / 0禁用
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "enable_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int enable_step(int sid, int bEnable = 1);
/****************************************************
*Function: 删除一个步骤
*Intput: sid 步骤ID
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "delete_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int delete_step(int sid);
/****************************************************
*Function: 插入一个节点到某个步骤
*Intput: sid 步骤ID
nindex 节点序号
pNode 节点信息结构体
*Output: pNode 会填充nodeID
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "insert_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int insert_node(int sid, int nindex, ref TNodeInfo pNode);
/****************************************************
*Function: 修改一个节点信息 -- 根据节点ID
*Intput: pNode 节点信息结构体
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "update_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int update_node(IntPtr ptr);
public static int update_node(TNodeInfo pNode)
{
IntPtr ptr;
int ret = 0;
TNodeInfo p = new TNodeInfo();
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p));
Marshal.StructureToPtr(pNode, ptr, false);
ret = update_node(p);
Marshal.FreeHGlobal(ptr);
return ret;
}
/****************************************************
*Function: 启用/禁用一个节点
*Intput: nid 节点ID
bEnable 1启用 / 0禁用
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "enable_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int enable_node(int nid, int bEnable = 1);
/****************************************************
*Function: 删除一个节点
*Intput: nid 节点ID
*Output: NULL
*Return: 成功返回0,失败返回错误码
*PS: 仅当该流程暂停时可设置
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "delete_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int delete_node(int nid);
/****************************************************
*Function: 获取所有流程基本信息
*Intput: pstProc 缓存指针 默认为空
*Output: pstProc 缓存指针
*Return: 返回工作流程数量
*PS: 先传NULL获取数量new一个数组再传进来获取信息
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_all_proc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_all_proc(IntPtr ptr);
public static int get_proc_count()
{
return get_all_proc(IntPtr.Zero);
}
public static int get_all_proc(TFlow[] pstWork)
{
IntPtr ptr;
int len = 0;
int count = 0;
TFlow info = new TFlow();
count = get_all_proc(IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
get_all_proc(ptr);
for (int i = 0; i < count; i++)
{
pstWork[i] = (TFlow)Marshal.PtrToStructure(
ptr + len * i, typeof(TFlow));
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function: 获取一个流程中所有步骤信息
*Intput: proc 流程ID
pstStep 缓存指针 默认为空,则获取数量
nsize 缓存区大小 -1 默认获取所有
*Output: pstProc 缓存指针
*Return: 返回所有步骤数量
*PS: 先传NULL获取数量new一个数组再传进来获取信息
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_all_step", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_all_step(string proc, IntPtr ptr, int nsize = -1);
public static int get_step_count(string proc)
{
return get_all_step(proc, IntPtr.Zero);
}
public static int get_all_step(string proc, TStepInfo[] pstStep)
{
IntPtr ptr;
int len = 0;
int count = 0;
TStepInfo info = new TStepInfo();
count = get_all_step(proc, IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
get_all_step(proc, ptr);
for (int i = 0; i < count; i++)
{
pstStep[i] = (TStepInfo)Marshal.PtrToStructure(
ptr + len * i, typeof(TStepInfo));
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function: 获取一个步骤的所有节点信息
*Intput: pszstep 步骤ID
pNode 缓存指针 默认为空,则获取数量
nsize 缓存区大小 -1 默认获取所有
*Output: pNode 节点信息结构体数组
*Return: 返回所有节点数量
*PS: 先传NULL获取数量new一个数组再传进来获取信息
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_all_node", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_all_node(string pszstep, IntPtr ptr, int nsize = -1);
public static int get_node_count(string proc)
{
return get_all_step(proc, IntPtr.Zero);
}
public static int get_all_node(string pszstep, TNodeInfo[] pstNode)
{
IntPtr ptr;
int len = 0;
int count = 0;
TNodeInfo info = new TNodeInfo();
count = get_all_node(pszstep, IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
get_all_node(pszstep, ptr);
for (int i = 0; i < count; i++)
{
pstNode[i] = (TNodeInfo)Marshal.PtrToStructure(
ptr + len * i, typeof(TNodeInfo));
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function: 获取某个流程基本信息
*Intput: pid 流程ID
pstProc 缓存指针 - 传0判断是否存在
*Output: pstProc 缓存指针
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_proc_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_proc_info(int pid, ref TFlow pstProc);
/****************************************************
*Function: 获取某个步骤基本信息
*Intput: sid 步骤ID
pstStep 缓存指针 - 传0判断是否存在
*Output: pstStep 缓存指针
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_step_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_step_info(int sid, ref TStepInfo pstStep);
/****************************************************
*Function: 获取某个节点基本信息
*Intput: nid 节点ID
pNode 缓存指针 - 传0判断是否存在
*Output: pNode 缓存指针
*Return: 成功返回0,失败返回错误码
******************************************************/
[DllImport(@"ops.dll", EntryPoint = "get_node_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_node_info(int nid, ref TNodeInfo pstNode);
public static bool node_is_enable(int nid)
{//判断节点是否启用
TNodeInfo pstNode = new TNodeInfo();
int ret = get_node_info(nid, ref pstNode);
if (ret != 0) return false;
return pstNode.state == ENodeState.ENode_Normal;
}
#endregion
}
}