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.

269 lines
12 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 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: 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 = 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: sn1
******************************************************/
[DllImport(@"corework.dll", EntryPoint = "test_debug", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int test_debug(int index, string sn);
}
}