实例介绍
【实例简介】MCC示例代码
//It has not been tested or validated as a product,
//for use in a deployed application or system, or for use in hazardous environments.
//You assume all risks for use of the Code or Example.
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 MccDaq;
namespace AnalogIn_toStripchart_SW_Timed
{
public partial class Form1 : Form
{
public MccDaq.DaqDeviceDescriptor[] inventory;
public MccDaq.MccBoard DaqBoard;
public MccDaq.ErrorInfo ULStat;
public MccDaq.Range Range;
public System.Int32 numchannels = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//First Lets make sure there's an E-1608 plugged in,
System.Boolean Boardfound = false;
//First Lets make sure there's an E-1608 plugged in,
MccDaq.DaqDeviceManager.IgnoreInstaCal(); //Don't use Information from InstaCal
//Load all the boards it can find
inventory = MccDaq.DaqDeviceManager.GetDaqDeviceInventory(MccDaq.DaqDeviceInterface.Any);
System.Int32 numDevDiscovered = inventory.Length; //how many was that?
if (numDevDiscovered > 0)
{
for (System.Int16 BoardNum = 0; BoardNum < numDevDiscovered; BoardNum )
{
try
{
DaqBoard = MccDaq.DaqDeviceManager.CreateDaqDevice(BoardNum, inventory[BoardNum]);
if (DaqBoard.BoardName.Contains("E-1608"))
{
Boardfound = true;
DaqBoard.FlashLED();
break;
}
else
{
MccDaq.DaqDeviceManager.ReleaseDaqDevice(DaqBoard);
}
}
catch (MccDaq.ULException ule)
{
System.Windows.Forms.MessageBox.Show(ule.Message, "No Board detected");
}
}
}
if (Boardfound == false)
{
System.Windows.Forms.MessageBox.Show("No E-1608 board found in system. Please run InstaCal.", "No Board detected");
this.Close();
}
System.String mystring = DaqBoard.BoardName.Substring(0, DaqBoard.BoardName.Trim().Length)
" found as board number: " DaqBoard.BoardNum.ToString();
this.Text = mystring;
//Initialize objects on the form needing attention
LoadComboBox(cmboAInRange);
//Determine if the device is set for single ended or differential by the number of channels.
DaqBoard.BoardConfig.GetNumAdChans(out numchannels);
nudAInChannel.Maximum = numchannels - 1;
//set up sample timing
for (int i = 1; i < 11; i )
cbRate.Items.Add(i);
cbRate.SelectedIndex = 9;
}
public void LoadComboBox(ComboBox sender)
{
sender.Items.Add("BIP10VOLTS");
sender.Items.Add("BIP5VOLTS");
sender.Items.Add("BIP2VOLTS");
sender.Items.Add("BIP1VOLTS");
sender.SelectedIndex = 0;
}
public void SelectRange(Int32 ComboBoxIndex)
{
switch (ComboBoxIndex)
{
case 0:
Range = MccDaq.Range.Bip10Volts;
stripChart1.YMaximum = 10;
stripChart1.YMinimum = -10;
stripChart1.YTicks = 10;
break;
case 1:
Range = MccDaq.Range.Bip5Volts;
stripChart1.YMaximum = 5;
stripChart1.YMinimum = -5;
stripChart1.YTicks = 10;
break;
case 2:
Range = MccDaq.Range.Bip2Volts;
stripChart1.YMaximum = 2;
stripChart1.YMinimum = -2;
stripChart1.YTicks = 4;
break;
case 3:
Range = MccDaq.Range.Bip1Volts;
stripChart1.YMaximum = 1;
stripChart1.YMinimum = -1;
stripChart1.YTicks = 2;
break;
}
}
public void errhandler(MccDaq.ErrorInfo ULStat)
{
//Generic UL error handler
System.Windows.Forms.MessageBox.Show(ULStat.Message, "Universal Library Error ");
lblAIMode.Text = "Idle";
btnStartStop.Text = "Start";
}
private void btnStartStop_Click(object sender, EventArgs e)
{
if (btnStartStop.Text == "Start")
{
btnStartStop.Text = "Stop";
lblAIMode.Text = "Running";
btnStartStop.Refresh();
tmrAnalogIn.Interval = 1000 / Convert.ToInt32(cbRate.SelectedItem);
this.stripChart1.TimeInterval = (tmrAnalogIn.Interval); //enter the timer interval and number of ticks for X scale
stripChart1.XTicks = 3;
stripChart1.Reset(); //reset/clear the stripchart
SelectRange(cmboAInRange.SelectedIndex);
tmrAnalogIn.Enabled = true;
cmboAInRange.Enabled = false;
cbRate.Enabled = false;
}
else
{
btnStartStop.Text = "Start";
lblAIMode.Text = "Idle";
tmrAnalogIn.Enabled = false;
cmboAInRange.Enabled = true;
cbRate.Enabled = true;
}
}
private void Button6_Click(object sender, EventArgs e)
{
this.Close();
}
private void tmrAnalogIn_Tick(object sender, EventArgs e)
{
//here is how to implement the VIn32 Method.
System.Double VInVolts;
ULStat = DaqBoard.VIn32(Convert.ToInt16(nudAInChannel.Value), Range, out VInVolts, MccDaq.VInOptions.Default);
if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
{
errhandler(ULStat);
return;
}
txtADValue.Text = VInVolts.ToString("#0.####");
stripChart1.AddValue(VInVolts);
}
}
}
【实例截图】
//It has not been tested or validated as a product,
//for use in a deployed application or system, or for use in hazardous environments.
//You assume all risks for use of the Code or Example.
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 MccDaq;
namespace AnalogIn_toStripchart_SW_Timed
{
public partial class Form1 : Form
{
public MccDaq.DaqDeviceDescriptor[] inventory;
public MccDaq.MccBoard DaqBoard;
public MccDaq.ErrorInfo ULStat;
public MccDaq.Range Range;
public System.Int32 numchannels = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//First Lets make sure there's an E-1608 plugged in,
System.Boolean Boardfound = false;
//First Lets make sure there's an E-1608 plugged in,
MccDaq.DaqDeviceManager.IgnoreInstaCal(); //Don't use Information from InstaCal
//Load all the boards it can find
inventory = MccDaq.DaqDeviceManager.GetDaqDeviceInventory(MccDaq.DaqDeviceInterface.Any);
System.Int32 numDevDiscovered = inventory.Length; //how many was that?
if (numDevDiscovered > 0)
{
for (System.Int16 BoardNum = 0; BoardNum < numDevDiscovered; BoardNum )
{
try
{
DaqBoard = MccDaq.DaqDeviceManager.CreateDaqDevice(BoardNum, inventory[BoardNum]);
if (DaqBoard.BoardName.Contains("E-1608"))
{
Boardfound = true;
DaqBoard.FlashLED();
break;
}
else
{
MccDaq.DaqDeviceManager.ReleaseDaqDevice(DaqBoard);
}
}
catch (MccDaq.ULException ule)
{
System.Windows.Forms.MessageBox.Show(ule.Message, "No Board detected");
}
}
}
if (Boardfound == false)
{
System.Windows.Forms.MessageBox.Show("No E-1608 board found in system. Please run InstaCal.", "No Board detected");
this.Close();
}
System.String mystring = DaqBoard.BoardName.Substring(0, DaqBoard.BoardName.Trim().Length)
" found as board number: " DaqBoard.BoardNum.ToString();
this.Text = mystring;
//Initialize objects on the form needing attention
LoadComboBox(cmboAInRange);
//Determine if the device is set for single ended or differential by the number of channels.
DaqBoard.BoardConfig.GetNumAdChans(out numchannels);
nudAInChannel.Maximum = numchannels - 1;
//set up sample timing
for (int i = 1; i < 11; i )
cbRate.Items.Add(i);
cbRate.SelectedIndex = 9;
}
public void LoadComboBox(ComboBox sender)
{
sender.Items.Add("BIP10VOLTS");
sender.Items.Add("BIP5VOLTS");
sender.Items.Add("BIP2VOLTS");
sender.Items.Add("BIP1VOLTS");
sender.SelectedIndex = 0;
}
public void SelectRange(Int32 ComboBoxIndex)
{
switch (ComboBoxIndex)
{
case 0:
Range = MccDaq.Range.Bip10Volts;
stripChart1.YMaximum = 10;
stripChart1.YMinimum = -10;
stripChart1.YTicks = 10;
break;
case 1:
Range = MccDaq.Range.Bip5Volts;
stripChart1.YMaximum = 5;
stripChart1.YMinimum = -5;
stripChart1.YTicks = 10;
break;
case 2:
Range = MccDaq.Range.Bip2Volts;
stripChart1.YMaximum = 2;
stripChart1.YMinimum = -2;
stripChart1.YTicks = 4;
break;
case 3:
Range = MccDaq.Range.Bip1Volts;
stripChart1.YMaximum = 1;
stripChart1.YMinimum = -1;
stripChart1.YTicks = 2;
break;
}
}
public void errhandler(MccDaq.ErrorInfo ULStat)
{
//Generic UL error handler
System.Windows.Forms.MessageBox.Show(ULStat.Message, "Universal Library Error ");
lblAIMode.Text = "Idle";
btnStartStop.Text = "Start";
}
private void btnStartStop_Click(object sender, EventArgs e)
{
if (btnStartStop.Text == "Start")
{
btnStartStop.Text = "Stop";
lblAIMode.Text = "Running";
btnStartStop.Refresh();
tmrAnalogIn.Interval = 1000 / Convert.ToInt32(cbRate.SelectedItem);
this.stripChart1.TimeInterval = (tmrAnalogIn.Interval); //enter the timer interval and number of ticks for X scale
stripChart1.XTicks = 3;
stripChart1.Reset(); //reset/clear the stripchart
SelectRange(cmboAInRange.SelectedIndex);
tmrAnalogIn.Enabled = true;
cmboAInRange.Enabled = false;
cbRate.Enabled = false;
}
else
{
btnStartStop.Text = "Start";
lblAIMode.Text = "Idle";
tmrAnalogIn.Enabled = false;
cmboAInRange.Enabled = true;
cbRate.Enabled = true;
}
}
private void Button6_Click(object sender, EventArgs e)
{
this.Close();
}
private void tmrAnalogIn_Tick(object sender, EventArgs e)
{
//here is how to implement the VIn32 Method.
System.Double VInVolts;
ULStat = DaqBoard.VIn32(Convert.ToInt16(nudAInChannel.Value), Range, out VInVolts, MccDaq.VInOptions.Default);
if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
{
errhandler(ULStat);
return;
}
txtADValue.Text = VInVolts.ToString("#0.####");
stripChart1.AddValue(VInVolts);
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论