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 lot; //产品批次/料号 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string pmodel; //测试模式如:MP GRR Offline [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string sitel; //厂商 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string project; //项目代码 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string serverip; //测试服务端IP地址 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string visionip; //视觉服务端IP地址 public int bAAB; //测试模式 1AAB 0ABC 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, //治具报警 }; public struct TestMachine {//测试治具 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string ate; //治具编码 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string sn; //SN public int benable; //是否禁用 public TestStatus status; //治具状态 }; public enum EMapPos {//产品处于什么位置? LocationVacm = 0, //吸嘴 LocationInput, //进料仓 LocationOk, //ok仓 LocationNg1, //NG1仓 LocationNg2, //NG2仓 LocationNg3, //NG3仓 LocationTest, //测试治具 }; public struct TProduct {//产品数据 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string sn; //二维码 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string ate1; //治具编码1 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string ate2; //治具编码2 NG1次才有此编码 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string ate3; //治具编码3 NG2次才有此编码 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string start; //取料时间 YYYY/MM/DD HH:MM:SS [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] string end; //放料时间 YYYY/MM/DD HH:MM:SS int status; //最终状态 1pass 0ng EMapPos pos; //当前处于哪个位置 int index; //对应位置的序号 比如治具第几个?料盘上的第几个? int count; //测试了几次? }; public struct TPruductFlag {//产品有无标识 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public int flag; //256颗料 }; 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 core_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 core_deinit(); /**************************************************** *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: pdata传入NULL可判断产品有无 ******************************************************/ [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: 获取某个位置的产品列表 -- 进料仓时,sn为null *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 = IntPtr.Zero, int nsize = 0); public static int GetProductListCount(EMapPos pos) { return get_product_list(pos); } 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); if (count > 0) { len = Marshal.SizeOf(info); ptr = Marshal.AllocHGlobal(len * 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 = IntPtr.Zero, int nsize = 0); public static int GetAllProductCount() { return get_all_product_info(); } public static int GetAllProduct(TProduct[] pst) { IntPtr ptr; int len = 0; int count = 0; TProduct info = new TProduct(); count = get_all_product_info(); 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: 根据sn生产数据,并从1号吸嘴创建,并将数据移入治具,开始测试 ******************************************************/ [DllImport(@"corework.dll", EntryPoint = "test_debug", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern int test_debug(int index, string sn); } }