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.

400 lines
18 KiB
C#

2 years ago
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{
public struct CoreConfig
{//模块参数设置
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string Config; //料号
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ConfigD; //料号
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string lot; //产品批次/料号
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string machine; //设备ID
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string sitel; //厂商
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string project; //项目代码
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string sublotname; //子产品批次
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string BinA; //BinA设定值
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string serverip; //测试服务端IP地址
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string visionip; //视觉服务端IP地址
public int bNodeLog; //是否记录Breakdown日志
public int testType; //测试模式 0 默认模式 1-AAB 2-ABC
public int bUpMes; //是否上传MES 治具用
public int bUpMTcp; //是否打开MTCP 治具用
public int bUpNoise; //是否上传噪音数据
public int bSingleTestFilter; //是否开启单测试过滤
public int bDirDate; //是否生成日期文件夹
public int bFourPic; //是否每次拍4个产品, 默认拍4个产品
public int bSavePos; //是否缓存位置 默认缓存
public int uphFrequency; //实时uph刷新频率
public int b2nd; //是否为二代机
public int bTestlog; //是否打印测试通讯日志
public int bVisionlog; //是否打印视觉通讯日志
public int idualindex; //分组序号 A组 1~(3-6)
public int bPassTestB; //是否测试pass才进入B组测试
public int bBindB; //B组是否为绑定模式 TC1->TCB1 TC2->TCB2
public int iSimYield; //模拟测试良率 [0-100] 默认100
public int iSimCT; //模拟测试时间
public int bSimTest1; //模拟测试治具
public int bSimTest2;
public int bSimTest3;
public int bSimTest4;
public int bSimTest5;
public int bSimTest6;
};
//struct TestResult
//{//测试结果,测试机台传递回来
// int bpass; //1pass 0ng
// char csvInfo[MAX_BUF_LEN];
// char failItem[MAX_BUF_LEN];
// char testItem[MAX_BUF_LEN];
//};
public enum TestStatus
{//治具状态
TestNoConn = 0, //未连接
TestRunning, //测试中
TestIdle, //就绪
TestWarn, //治具报警
TestHoming, //治具回原
};
public struct TestMachine
{//测试治具
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ate; //治具编码
public int benable; //是否禁用
public TestStatus status; //治具状态
public int lastct; //最后一次CT
public int total; //测量总数
public int pass; //pass总数
public float yield; //单治具良率
};
public enum EMapPos
{//产品处于什么位置?
LocationVacm = 0, //吸嘴
LocationInput, //进料仓
LocationOk, //ok仓
LocationNg1, //NG1仓
LocationNg2, //NG2仓
LocationNg3, //NG3仓
LocationTest, //测试治具
};
public struct TProduct
{//产品数据
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string sn; //二维码
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string lot; //产品批次/料号
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ate1; //治具编码1
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ate2; //治具编码2 NG1次才有此编码
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ate3; //治具编码3 NG2次才有此编码
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string start; //取料时间 YYYY/MM/DD HH:MM:SS
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string end; //放料时间 YYYY/MM/DD HH:MM:SS
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string level; //产品等级 -- 分bin使用
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string failItems;//测试不良项目 多项以;分割
public int status; //最终状态 1pass 0ng
public EMapPos pos; //当前处于哪个位置
public int index; //对应位置的序号 比如治具第几个?料盘上的第几个?
public int count; //测试了几次?
public int takeIndex; //取料时在料盘中的位置
};
public delegate void VisionMsgCallback(int source,int index, string msg,int dir);
public class corework
{
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "core_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int init();
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "core_deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int deinit();
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return: (4)
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "core_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int core_version();
public static string version()
{//获取版本
string str;
string beta = "";
int iver = core_version();
if (iver > 10000)
{
beta = "beta" + Convert.ToString(iver % 10);
iver %= 10000;
}
else if (iver <= 0)
{
iver = 1001;
}
str = "V" + Convert.ToString(iver / 1000) + "."
+ Convert.ToString((iver / 100) % 10) + "."
+ Convert.ToString(iver % 100);
if (beta != "")
{
str += " " + beta;
}
return str;
}
/****************************************************
*Function:
*Intput: NULL
*Output: NULL
*Return:
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_test_model", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr get_test_model();
public static string getTestModel()
{
IntPtr p = get_test_model();
return Marshal.PtrToStringAnsi(p);
}
/****************************************************
*Function:
*Intput: cfg
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "core_set_cfg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int core_set_cfg(ref CoreConfig cfg);
/****************************************************
*Function:
*Intput: cfg
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "core_get_cfg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int core_get_cfg(ref CoreConfig cfg);
/****************************************************
*Function:
*Intput: sn
pdata
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_product_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_product_info(ref TProduct cfg);
/****************************************************
*Function:
*Intput: pos EMapPos
index
pdata
*Output: NULL
*Return: 0,<0
*PS: pdataNULL
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_product_by_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_product_by_pos(EMapPos pos, int index, ref TProduct pdata);
[DllImport(@"corework.dll", EntryPoint = "get_product_by_pos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int chk_product_by_pos(EMapPos pos, int index, IntPtr p);
public static bool IsHaveProduct(EMapPos pos, int index)
{
return 0 == chk_product_by_pos(pos, index, IntPtr.Zero) ? true : false;
}
/****************************************************
*Function: -- snnull
*Intput: pos EMapPos
pdata
nsize
*Output: NULL
*Return:
*PS:NULL
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_product_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_product_list(EMapPos pos, IntPtr p, int nsize = 0);
public static int GetProductListCount(EMapPos pos)
{
return get_product_list(pos, IntPtr.Zero);
}
public static int GetProductList(EMapPos pos, TProduct[] pst)
{
IntPtr ptr;
int len = 0;
int count = 0;
TProduct info = new TProduct();
count = get_product_list(pos, IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
count = get_product_list(pos, ptr, count);
for (int i = 0; i < count; i++)
{
pst[i] = (TProduct)Marshal.PtrToStructure(
ptr + len * i, typeof(TProduct));
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function:
*Intput: pdata
nsize
*Output: NULL
*Return:
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_all_product_info", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_all_product_info(IntPtr p, int nsize = 0);
public static int GetAllProductCount()
{
return get_all_product_info(IntPtr.Zero);
}
public static int GetAllProduct(TProduct[] pst)
{
IntPtr ptr;
int len = 0;
int count = 0;
TProduct info = new TProduct();
count = get_all_product_info(IntPtr.Zero);
if (count > 0)
{
len = Marshal.SizeOf(info);
ptr = Marshal.AllocHGlobal(len * count);
get_all_product_info(ptr, count);
for (int i = 0; i < count; i++)
{
pst[i] = (TProduct)Marshal.PtrToStructure(
ptr + len * i, typeof(TProduct));
}
Marshal.FreeHGlobal(ptr); //释放非托管内存
}
return count;
}
/****************************************************
*Function: /
*Intput: index [1-6]
benable 1 0
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "test_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int test_enable(int index, int benable);
/****************************************************
*Function:
*Intput: index [1-6]
*Output: pdata
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "get_test_data", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_test_data(int index, ref TestMachine pdata);
/****************************************************
*Function:
*Intput: index [1-6]
sn
*Output: NULL
*Return: 0,<0
*PS: sn1
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "test_debug", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int test_debug(int index, string sn);
/****************************************************
*Function:
*Intput: index [1-6]
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "test_home", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int test_home(int index);
/****************************************************
*Function:
*Intput: index [1-6]
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "test_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int test_reset(int index);
/****************************************************
*Function:
*Intput: keyword
errcode 0
errmsg errcode!=0
msg
*Output: NULL
*Return: 0,<0
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "wlog", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int wlog(string keyword,int errcode,string errmsg,string msg);
/// <summary>
/// 增加对相机的连接状态的返回
/// </summary>
/// <returns></returns>
[DllImport(@"corework.dll", EntryPoint = "get_cam_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_cam_status();
/// <summary>
/// 增加对测试软件的连接状态的返回
/// </summary>
/// <returns></returns>
[DllImport(@"corework.dll", EntryPoint = "get_test_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int get_test_status();
[DllImport(@"corework.dll", EntryPoint = "registercallbackmsg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int registercallbackmsg(VisionMsgCallback visionmsg);
}
}