using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading; // namespace WindowsFormsApplication1 { public partial class Form1 : Form { //VK70xnMCDLL_fmt int Def_Function_OUTfmt VK70xNMC_Set_SystemMode(int mci, int modelval,int samplemethod,int sdfilefmt); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_Set_SystemMode", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_Set_SystemMode(int mci, int modelval, int samplemethod, int sdfilefmt); //------------------------------------------- ADC Sampling control //VK70xnMCDLL_fmt int Def_Function_OUTfmt VK70xNMC_Initialize(int mci, double refvol, int bitmode, int sr, int volrg15, int volrg26, int volrg37, int volrg48); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_Initialize", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_Initialize(int mci, double refvol, int bitmode, int sr, int volrg15, int volrg26, int volrg37, int volrg48); //VK70xnMCDLL_fmt int Def_Function_OUTfmt VK70xNMC_Initialize_2(int mci, double refvol, int bitmode, int sr, int npoints, int timeinval, int *volrg); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_Initialize_2", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_Initialize_2(int mci, double refvol, int bitmode, int sr, int npoints, int timeinval, int[] volrg); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_StartSampling", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_StartSampling(int mci); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_StartSampling_NPoints", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_StartSampling_NPoints(int mci, int Npointsnums); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_StopSampling", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_StopSampling(int mci); //------------------------------------------ ADC Sampling Data ouppout [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetOneChannel", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetOneChannel(int mci, int CHNum, double[] adcbuffer, int rsamplenum);// for VK701N,VK701S,VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetFourChannel", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetFourChannel(int mci, double[] adcbuffer, int rsamplenum);// for VK701N,VK701S,VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetAllChannel", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetAllChannel(int mci, double[] adcbuffer, int rsamplenum); // for VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetOneChannel_WithIOStatus", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetOneChannel_WithIOStatus(int mci, int CHNum, double[] adcbuffer, int rsamplenum, int ioenable);// for VK701N,VK701S,VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetFourChannel_WithIOStatus", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetFourChannel_WithIOStatus(int mci, double[] adcbuffer, int rsamplenum, int ioenable);// for VK701N,VK701S,VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetAllChannel_WithIOStatus", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetAllChannel_WithIOStatus(int mci, double[] adcbuffer, int rsamplenum, int ioenable); // for VK702N //------------------------- [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetFixedFourChannel_CH1CH2_IO2IO3", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetFixedFourChannel_CH1CH2_IO2IO3(int mci, double[] adcbuffer, int rsamplenum);// for VK701N,VK701S,VK702N [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetFixedFourChannel_CH3CH4_IO2IO3", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetFixedFourChannel_CH3CH4_IO2IO3(int mci, double[] adcbuffer, int rsamplenum);// for VK701N,VK701S,VK702N //------------ [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "VK70xNMC_GetIOStatus", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int VK70xNMC_GetIOStatus(int mci, int[] iostatus); //------------------------------------------ TCP/IP Server [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_TCPClose", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_TCPClose(int portnumber); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_TCPOpen", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_TCPOpen(int portnumber); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_Get_ServerPort", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_Get_ServerPort(ref int iport); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_Bind_ConnectedClient", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_Bind_ConnectedClient(int tflag); //---------------------------------------- device information [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_Get_ConnectedClientNumbers", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_Get_ConnectedClientNumbers(ref int cnum); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_Get_ConnectedClientHandle", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_Get_ConnectedClientHandle(int mci, ref int ihadble, Byte[] ipadr); [DllImport("VK70xNMC_DAQ2.dll", EntryPoint = "Server_Get_RxTotoalBytes", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Server_Get_RxTotoalBytes(ref int totalbytesnum, int clrflag); //====================================== int ConenctedCardNum; int DAQ1SampleNum, DAQ2SampleNum, DAQ3SampleNum, DAQ4SampleNum, DAQ5SampleNum; public Form1() { InitializeComponent(); timer1.Interval = 1000; timer1.Enabled = true; timer2.Interval = 10; timer2.Enabled = false; ConenctedCardNum = 0; DAQ1SampleNum=0; DAQ2SampleNum=0; DAQ3SampleNum=0; DAQ4SampleNum = 0; DAQ5SampleNum = 0; label1.Text = "已连接卡(0)传输速度:0字节每秒"; DAQ1.Text = "DAQ1 disconnected!"; DAQ2.Text = "DAQ2 disconnected!"; DAQ3.Text = "DAQ3 disconnected!"; DAQ4.Text = "DAQ4 disconnected!"; DAQ5.Text = "DAQ5 disconnected!"; label2.Text = ""; } private void button3_Click(object sender, EventArgs e) { int Cardindex, Res; if (ConenctedCardNum > 0) { label2.Text = "Start to Setup!"; timer1.Enabled = false; timer2.Enabled = false; for (Cardindex = 0; Cardindex < ConenctedCardNum; Cardindex++) { //Res = VK70xNMC_Set_SystemMode(Cardindex, 0, 0, 0);// power on then back to the normal mode //if (Res >= 0) label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Setup successfully!"; //else label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Setup Failed!"; //Thread.Sleep(100); Res = VK70xNMC_Initialize(Cardindex, 4, 24, 1000, 0, 0, 0, 0); if (Res >= 0) label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Initialize successfully!"; else { label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Initialize Failed!"; break; } if (Cardindex == 0) { DAQ1SampleNum = 0; DAQ1.Text = "DAQ1:" + String.Format("{0}", DAQ1SampleNum); } else if (Cardindex == 1) { DAQ2SampleNum = 0; DAQ2.Text = "DAQ2:" + String.Format("{0}", DAQ2SampleNum); } else if (Cardindex == 2) { DAQ3SampleNum = 0; DAQ3.Text = "DAQ3:" + String.Format("{0}", DAQ3SampleNum); } else if (Cardindex == 3) { DAQ4SampleNum = 0; DAQ4.Text = "DAQ4:" + String.Format("{0}", DAQ4SampleNum); } else if (Cardindex == 4) { DAQ5SampleNum = 0; DAQ5.Text = "DAQ5:" + String.Format("{0}", DAQ5SampleNum); } Thread.Sleep(1); //Delay 1ms } } } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e)// start all cards { int Cardindex, Res; if (ConenctedCardNum > 0) { label2.Text = "Start to Setup!"; timer1.Enabled = false; timer2.Enabled = false; for (Cardindex = 0; Cardindex < ConenctedCardNum; Cardindex++) { Res = VK70xNMC_StartSampling(Cardindex); if (Res >= 0) label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Start to sampling!!"; else { label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] Open sampling failed!"; break; } if (Cardindex == 0) { DAQ1SampleNum = 0; DAQ1.Text = "DAQ1:" + String.Format("{0}", DAQ1SampleNum); } else if (Cardindex == 1) { DAQ2SampleNum = 0; DAQ2.Text = "DAQ2:" + String.Format("{0}", DAQ2SampleNum); } else if (Cardindex == 2) { DAQ3SampleNum = 0; DAQ3.Text = "DAQ3:" + String.Format("{0}", DAQ3SampleNum); } else if (Cardindex == 3) { DAQ4SampleNum = 0; DAQ4.Text = "DAQ4:" + String.Format("{0}", DAQ4SampleNum); } else if (Cardindex == 4) { DAQ5SampleNum = 0; DAQ5.Text = "DAQ5:" + String.Format("{0}", DAQ5SampleNum); } Thread.Sleep(1); //Delay 1ms } timer2.Enabled = true; } } private void button2_Click(object sender, EventArgs e)// stop all cards { int Cardindex, Res; if (ConenctedCardNum > 0) { for (Cardindex = 0; Cardindex < ConenctedCardNum; Cardindex++) { Res = VK70xNMC_StopSampling(Cardindex); if (Res >= 0) label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] had been stop!"; else label2.Text = "DQA[" + String.Format("{0:00}", Cardindex) + "] stop sampling failed!"; if (Cardindex == 0) DAQ1.Text = "DAQ1 stop!"; else if (Cardindex == 1) DAQ2.Text = "DAQ2 stop!"; else if (Cardindex == 2) DAQ3.Text = "DAQ3 stop!"; else if (Cardindex == 3) DAQ4.Text = "DAQ4 stop!"; else if (Cardindex == 4) DAQ5.Text = "DAQ5 stop!"; } //===================== timer2.Enabled = false; //===================== } } private void timer1_Tick(object sender, EventArgs e) { int Res, temp, tspeed; temp = 0; tspeed=0; Res=0; Res = Server_Get_ConnectedClientNumbers(ref temp); if (Res >= 0) { ConenctedCardNum=temp; Res = Server_Get_RxTotoalBytes(ref tspeed, 1); label1.Text = "已连接卡(" + String.Format("{0}", temp) + ")传输速度:" + String.Format("{0}", tspeed) + "字节每秒";//传输速度(0):0字节每秒 } } private void timer2_Tick(object sender, EventArgs e) { double[] revResult = new double[12000]; /// max 1000 points x (8 adc channels + 4 IO channels) int Res,Cardindex; if (ConenctedCardNum > 0) { for (Cardindex = 0; Cardindex < ConenctedCardNum; Cardindex++) { Res = VK70xNMC_GetFourChannel(Cardindex, revResult, 1000); if (Res <= 0) continue; if (Cardindex == 0) { DAQ1SampleNum += Res; DAQ1.Text = "DAQ1:" + String.Format("{0}", DAQ1SampleNum); } else if (Cardindex == 1) { DAQ2SampleNum += Res; DAQ2.Text = "DAQ2:" + String.Format("{0}", DAQ2SampleNum); } else if (Cardindex == 2) { DAQ3SampleNum += Res; DAQ3.Text = "DAQ3:" + String.Format("{0}", DAQ3SampleNum); } else if (Cardindex == 3) { DAQ4SampleNum += Res; DAQ4.Text = "DAQ4:" + String.Format("{0}", DAQ4SampleNum); } else if (Cardindex == 4) { DAQ5SampleNum += Res; DAQ5.Text = "DAQ5:" + String.Format("{0}", DAQ5SampleNum); } } } } } }