基本信息
源码名称:数据采集卡读取(USB)
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2020-09-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
对电压进行数据多路采集,USB多通道数据采集
对电压进行数据多路采集,USB多通道数据采集
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public partial class Form1 : Form { [DllImport("usb-1000.dll")] public static extern int FindUSBDAQ(); [DllImport("usb-1000.dll")] public static extern int OpenDevice(int DevIndex); [DllImport("usb-1000.dll")] public static extern int ResetDevice(int DevIndex); [DllImport("usb-1000.dll")] public static extern void CloseDevice(int DevIndex); [DllImport("usb-1000.dll")] public static extern int SetUSB1AiRange(int DevIndex, float Range); [DllImport("usb-1000.dll")] public static extern int SetSampleRate(int DevIndex, uint SampleRate); [DllImport("usb-1000.dll")] public static extern int SetChanSel(int DevIndex, UInt16 ChSel); [DllImport("usb-1000.dll")] public static extern int SetChanMode(int DevIndex, byte ChanMode); [DllImport("usb-1000.dll")] public static extern int SetTrigSource(int DevIndex, byte TrigSource); [DllImport("usb-1000.dll")] public static extern int SetSoftTrig(int DevIndex, byte Trig); //public static extern int SetTrigEdge(int DevIndex, byte TrigEdge); [DllImport("usb-1000.dll")] public static extern int ClearTrigger(int DevIndex); //public static extern int SetDioOut(int DevIndex, byte DioChanSel, byte DioOut); //public static extern int TransDioIn(int DevIndex, byte TransDioSwitch); //public static extern int SetCounter(int DevIndex, byte CtrNum, byte CtrMode, byte CtrEdge); //public static extern int StartCounter(int DevIndex, byte CtrNum, byte OnOff); //public static extern int InitDA(int DevIndex); //public static extern int SetDA(int DevIndex, byte DANum, float DAVolt); //public static extern int SetWavePt(int DevIndex, byte DANum, float DAVolt); //public static extern int ClrWavePt(int DevIndex, byte DANum); //public static extern int SetWaveSampleRate(int DevIndex, uint WaveSampleRate); //public static extern int WaveOutput(int DevIndex, byte DANum); [DllImport("usb-1000.dll")] public static extern int ClearBufs(int DevIndex); //public static extern int ClearCounter(int DevIndex, byte CtrNum); [DllImport("usb-1000.dll")] public static extern int StartRead(int DevIndex); [DllImport("usb-1000.dll")] public static extern int StopRead(int DevIndex); [DllImport("usb-1000.dll")] public static extern int GetAiChans(int DevIndex, int Num, UInt16 ChSel, float[] Ai, int TimeOut); public Form1() { InitializeComponent(); } private void Read_Click(object sender, EventArgs e) { int temp , i; int QTYperCH , Dev_Index; uint SampleRate ; UInt16 Channel_Select = 0; byte ChannelMode ; Dev_Index = Convert.ToInt32(Dev_Index_Input.Text); QTYperCH = Convert.ToInt32(QTYperCH_Input.Text); SampleRate = Convert.ToUInt32(SampleRate_Input.Text); ChannelMode = Convert.ToByte(ChannelMode_Input.Text); listView1.Clear(); listView1.Columns.Add("Num"); int QTYofCH = 0; for (i = 0; i < 16; i ) { if (Channel_Select_Input.GetItemChecked(i)) { Channel_Select = (UInt16)(Channel_Select (UInt16)Math.Pow(2, i)); listView1.Columns.Add("ai" i.ToString() ); QTYofCH ; } } float[] ai = new float[QTYperCH * QTYofCH]; temp = OpenDevice(Dev_Index); temp = ResetDevice(Dev_Index); temp = SetUSB1AiRange(Dev_Index, 5); // 设置量程 temp = SetSampleRate(Dev_Index, SampleRate); // 设置采样率 temp = SetChanMode(Dev_Index, ChannelMode); temp = SetChanSel(Dev_Index, Channel_Select); // 设置需要采集的通道,此处选择ai0~ai7 temp = StartRead(Dev_Index); // 启动读取数据线程 //Sleep(30); // 等待读数线程启动完毕 temp = SetSoftTrig(Dev_Index, 1); // 设置软件触发信号 // 用户读取数据 // 连续采集时循环使用GetAiChans() temp = GetAiChans(Dev_Index, QTYperCH, Channel_Select, ai, 4000); // 每通道读取1000点,超时设置1000ms listView1.Items.Clear(); for (i = 0; i < QTYperCH; i ) { ListViewItem lvi = new ListViewItem(); lvi.Text = i.ToString(); int j = 0 , k = 0; for (j = 0; j < 15; j ) { if (Channel_Select_Input.GetItemChecked(j)) { lvi.SubItems.Add(ai[k * QTYperCH i].ToString()); k ; } } lvi.SubItems.Add(ai[i].ToString()); this.listView1.Items.Add(lvi); } temp = StopRead(Dev_Index); // 结束读取数据线程 temp = SetSoftTrig(Dev_Index, 0); // 释放软件触发信号 //temp = ClearTrigger(Dev_Index); // 清空触发标志 temp = ClearBufs(Dev_Index); // 清空所有缓存数据 CloseDevice(Dev_Index); } private void Form1_Load(object sender, EventArgs e) { int temp; temp = FindUSBDAQ(); Dev_QTY.Text = temp.ToString(); } } }