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.

204 lines
9.7 KiB
C#

2 years ago
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{
public class cshrap_dll
{
static private string _pszcmddesc =
"业务模块自定义消息格式.\n" +
"\n发送消息格式\n\n\n" +
"M1 通知取料仓拍照,并返回拍照结果\n\n" +
"M2 通知搬运模组拍照,并返回拍照结果\n\n" +
"M3 通知OK仓拍照并返回拍照结果\n\n" +
"M4 通知NG仓拍照并返回拍照结果\n\n" +
"M5 通知NG取一拍一模式拍照并返回拍照结果\n\n" +
"M6 通知NG放一拍一模式拍照并返回拍照结果\n\n" +
"M7 通知治具取料模式拍照,并返回拍照结果\n\n" +
"M8 通知治具放料模式拍照,并返回拍照结果\n\n" +
"MT tindex [sn] 模拟治具发送侧相机处理请求\n\n" +
"vacmreset 通知释放吸嘴产品数据\n\n" +
"makeinput 模拟生成进料盘数据\n\n" +
"posreset sindex 通知释放拍照数据 sindex料仓编号[1-5]\n\n" +
"posget sindex 获取拍照取料位置数据写入变量 res=0标识获取成功,否则标识要拍照获取数据.取料信息写入(sn,x,y)\n\n" +
"posset sindex index sn x y 将拍照数据暂存起来,sindex料仓编号[1-5] index数据编号[1-4] sn二维码 x,y基于相机的坐标值\n\n" +
"posmap sindex 拍照3次(左上、右上、左下)后,此指令可计算矩阵,生成料盘位置数据.\n\n" +
"clear tindex 清空治具统计参数 tindex治具编号[1-6]\n\n" +
"home tindex 通知治具回原 tindex治具编号[1-6]\n\n" +
"pause tindex flag 通知治具暂停 tindex治具编号[1-6] flag 1暂停 0暂停取消\n\n" +
"grip tindex 1/0 通知治具控制夹爪 tindex治具编号[1-6] 1夹紧 0松开\n\n" +
"status tindex a 设置治具状态更新到某个变量 tindex治具编号[1-6] a变量名\n\n" +
"sim tindex bsim 打开/关闭模拟治具 tindex治具编号[1-6] bsim 1打开模拟 0关闭模拟\n\n" +
"stockreset sindex 通知释放料盘产品数据 sindex料仓编号[1-5]\n\n" +
"where 通知设置当前是给治具换料还是放料到料仓,设置到变量't'中0标识放料到料仓[1-6]标识给治具换料\n\n" +
"vacmtake 通知设置需要取料的吸嘴编号为0时无效设置到变量'v'中\n\n" +
"testput 通知设置需要进入治具的吸嘴编号->'v',治具编号->'t'为0时无效\n\n" +
"testake 通知设置需要从治具取料的吸嘴编号->'v',治具编号->'t'为0时无效\n\n" +
"stockput 通知设置需要放回料仓的吸嘴编号->'v',料仓编号[2-5]->'t'为0时无效\n\n" +
"create sn vindex 从进料仓到吸嘴,并创建产品资料 vindex吸嘴编号\n\n" +
"vacm_to_test vindex tindex 变更产品位置,从吸嘴到测试治具并开始测试 vindex吸嘴编号 tindex治具编号\n\n" +
"test_to_vacm tindex vindex 变更产品位置,从测试治具到吸嘴 tindex治具编号 vindex吸嘴编号\n\n" +
"vacm_to_stock vindex sindex 变更产品位置,从吸嘴到料仓 vindex吸嘴编号 sindex料仓编号[2-5]\n\n" +
"\n接收消息(\"msg\"格式)\n\n\n" +
"waitOk tindex 等待测试治具就绪当状态就绪时返回0否则返回超时\n\n" +
"WaitM1 接收进料仓拍照处理结果消息返回格式res,sn,x,y res=0标识成功\n\n" +
"WaitM2 sindex sindex料仓编号[1-5] 等待搬运模组拍照处理结果,自动刷新产品标识到数组中,消息返回格式res 0标识成功\n\n" +
"WaitM3 接收OK仓拍照结果消息返回格式res,x,y res=0标识成功\n\n" +
"WaitM4 接收NG仓拍照结果消息返回格式res,x,y res=0标识成功\n\n" +
"WaitM5 接收NG取一拍一拍照结果消息返回格式res,x,y res=0标识成功\n\n" +
"WaitM6 接收NG放一拍一拍照结果消息返回格式res,x,y res=0标识成功\n\n" +
"WaitM7 接收治具取料拍照结果消息返回格式res,x,y res=0标识成功\n\n" +
"WaitM8 接收治具放料拍照结果消息返回格式res,x,y res=0标识成功\n\n"
;
static private Byte[] _cmdinfo = System.Text.Encoding.Default.GetBytes(_pszcmddesc);
static private MotorFun m_fun = new MotorFun();
static private coreworks m_pk = new coreworks();
/***********************************************
*Function: / -- 使
*Intput: index ,,0
ctx ;<256,PARAM_CNT
*Output: NULL
*Return: 0<0
*********************************************/
static public int Init(ushort index, string ctx)
{
if (0 != index) return -1000;
return m_pk.Init(ctx);
}
/***********************************************
*Function: /
*Intput: index
*Output: NULL
*Return: 0<0
*********************************************/
static public int Deinit(ushort index)
{
if (0 != index) return -1000;
return m_pk.Deinit();
}
/***********************************************
*Function:
*Intput: index
*Output: NULL
*Return: EDevStatus or EMoveStatus
*********************************************/
static public int GetStatus(ushort index)
{
if (0 != index) return (int)EDevStatus.EDev_NOINIT;
return m_pk.GetStatus();
}
static public int GetCmdInfo(IntPtr p)
{//获取指令描述
if (p == IntPtr.Zero) return _cmdinfo.Length;
Marshal.Copy(_cmdinfo, 0, p, _cmdinfo.Length);
return 0;
}
/*********************************************
*Function:
*Intput: index
msg
res ,
*Output: res ,
*Return: 0,<0
*********************************************/
static public int SendMessage(ushort index, string msg, IntPtr res)
{
int ret = 0;
string str = "";
if (0 != index) return -1000;
ret = m_pk.SendMessage(msg, ref str);
if (res != IntPtr.Zero && str != "")
{//传入指针且有结果传出
Byte[] bt = System.Text.Encoding.Default.GetBytes(str);
Marshal.Copy(bt, 0, res, bt.Length);
}
return ret;
}
/*********************************************
*Function:
*Intput: index
msg
res
timeout ms
*Output: res
*Return: 0,<0
*PS: ERR_TIMEOUT
*PS:
*********************************************/
static public int RecvMessage(ushort index, string msg, IntPtr res, int timeout)
{
int ret = 0;
string str = "";
if (0 != index) return -1000;
ret = m_pk.RecvMessage(msg, ref str, timeout);
if (res != IntPtr.Zero && str != "")
{//传入指针且有结果传出
Byte[] bt = System.Text.Encoding.Default.GetBytes(str);
Marshal.Copy(bt, 0, res, bt.Length);
}
return ret;
}
static public void Regist()
{//注册插件
//string home = "捕获回原;Index回原;普通回原;";
string ctx = "服务端IP:|127.0.0.1;服务端端口:|6060";
m_fun.funinit = new fun_init(Init);
m_fun.fundeinit = new fun_deinit(Deinit);
m_fun.funstatus = new fun_get_status(GetStatus);
m_fun.funcmdinfo = new fun_get_cmd_info(GetCmdInfo);
m_fun.funsend = new fun_send_msg(SendMessage);
m_fun.funrecv = new fun_recv_msg(RecvMessage);
control.regist("CSharpCore", "C#业务库", "", ctx, 0, 0, 0, ref m_fun);
}
}
public class coreworks
{//核心业务类
public int Init(string ctx)
{//初始化
return 0;
}
public int Deinit()
{//反初始化
return 0;
}
public int GetStatus()
{//获取模块状态
return (int)EDevStatus.EDev_IDLE;
}
public int SendMessage(string msg, ref string res)
{
if (msg == "hello")
{
res = "world.";
return 0;
}
return -1;
}
public int RecvMessage(string msg, ref string res, int timeout)
{
return -1;
}
}
}