📄 ulai02.cs
字号:
// ==============================================================================
// File: ULAI02.CS
//
// Library Call Demonstrated: Mccdaq.MccBoard.AInScan()in Foreground mode
// with scan options = MccDaq.ScanOptions.ConvertData
//
// Purpose: Scans a range of A/D Input Channels and stores
// the sample data in an array.
//
// Demonstration: Displays the analog input on up to eight channels.
//
// Other Library Calls: MccDaq.MccService.ErrHandling()
// MccDaq.MccService.WinBufAlloc
// MccDaq.MccService.WinBufToArray()
// MccDaq.MccService.WinBufFree()
//
// Special Requirements: Board 0 must have an A/D converter.
// Analog signals on up to eight input channels.
//
// ==============================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.IO;
using MccDaq;
namespace ULAI02
{
public class frmDataDisplay : System.Windows.Forms.Form
{
// Required by the Windows Form Designer
private System.ComponentModel.IContainer components;
public ToolTip ToolTip1;
public Button cmdStopConvert;
public Button cmdStart;
public Label Label1;
public Label lblDemoFunction;
//public Label[] lblADData;
int NumPoints; // Number of data points to collect
int NumPerCh; // Number of data points per channel
const int FirstPoint = 0; // set first element in buffer to transfer to array
const int ChanNum=2; // Number of collecting channels
const char space='\n';
private MccDaq.MccBoard DaqBoard;
private ushort[] ADData;
//private ushort[][] ADData_ch0 = new ushort[2],[3];
//private ushort[] ADData_ch1 = new ushort[NumPoints/ChanNum];
private System.Windows.Forms.Button cmdSaveCounts;
public System.Windows.Forms.Label label2;
public System.Windows.Forms.TextBox txtSamplesPerCh;
private System.Windows.Forms.Button cmdDraw;
private System.Windows.Forms.TextBox textStep;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textTotalPoints;
private System.Windows.Forms.Button cmdClear; // dimension an array to hold the input values
private int MemHandle = 0; // define a variable to contain the handle for memory allocated
// by Windows through MccDaq.MccService.WinBufAlloc()
public frmDataDisplay()
{
MccDaq.ErrorInfo ULStat;
// This call is required by the Windows Form Designer.
InitializeComponent();
// Initiate error handling
// activating error handling will trap errors like
// bad channel numbers and non-configured conditions.
// Parameters:
// MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
// MccDaq.ErrorHandling.StopAll :if an error is encountered, the program will stop
ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);
// Create a new MccBoard object for Board 1
DaqBoard = new MccDaq.MccBoard(1);
// Get the total number of points to collect
//NumPerCh = int.Parse(txtSamplesPerCh.Text);
//txtSamplesPerCh.Text = NumPerCh.ToString();
NumPerCh=32000;
NumPoints=NumPerCh*ChanNum;
// Initiate the data array
ADData=new ushort[NumPoints];
// Allocate memory buffer to hold data..
MemHandle = MccDaq.MccService.WinBufAlloc(NumPoints); // set aside memory to hold data
// This gives us access to labels via an indexed array
//lblADData = (new Label[] {this._lblADData_0, this._lblADData_1, this._lblADData_2, this._lblADData_3, this._lblADData_4, this._lblADData_5, this._lblADData_6, this._lblADData_7});
}
// Form overrides dispose to clean up the component list.
protected override void Dispose(bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
// be sure to release the memory buffer...
if ( MemHandle != 0)
MccDaq.MccService.WinBufFree(MemHandle);
}
base.Dispose(Disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.cmdStopConvert = new System.Windows.Forms.Button();
this.cmdStart = new System.Windows.Forms.Button();
this.Label1 = new System.Windows.Forms.Label();
this.lblDemoFunction = new System.Windows.Forms.Label();
this.cmdSaveCounts = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.txtSamplesPerCh = new System.Windows.Forms.TextBox();
this.cmdDraw = new System.Windows.Forms.Button();
this.textStep = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textTotalPoints = new System.Windows.Forms.TextBox();
this.cmdClear = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// cmdStopConvert
//
this.cmdStopConvert.BackColor = System.Drawing.SystemColors.Control;
this.cmdStopConvert.Cursor = System.Windows.Forms.Cursors.Default;
this.cmdStopConvert.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cmdStopConvert.ForeColor = System.Drawing.SystemColors.ControlText;
this.cmdStopConvert.Location = new System.Drawing.Point(432, 96);
this.cmdStopConvert.Name = "cmdStopConvert";
this.cmdStopConvert.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.cmdStopConvert.Size = new System.Drawing.Size(58, 26);
this.cmdStopConvert.TabIndex = 17;
this.cmdStopConvert.Text = "Quit";
this.cmdStopConvert.Click += new System.EventHandler(this.cmdStopConvert_Click);
//
// cmdStart
//
this.cmdStart.BackColor = System.Drawing.SystemColors.Control;
this.cmdStart.Cursor = System.Windows.Forms.Cursors.Default;
this.cmdStart.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cmdStart.ForeColor = System.Drawing.SystemColors.ControlText;
this.cmdStart.Location = new System.Drawing.Point(432, 56);
this.cmdStart.Name = "cmdStart";
this.cmdStart.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.cmdStart.Size = new System.Drawing.Size(58, 26);
this.cmdStart.TabIndex = 18;
this.cmdStart.Text = "Start";
this.cmdStart.Click += new System.EventHandler(this.cmdStart_Click);
//
// Label1
//
this.Label1.BackColor = System.Drawing.SystemColors.Window;
this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label1.ForeColor = System.Drawing.SystemColors.WindowText;
this.Label1.Location = new System.Drawing.Point(56, 66);
this.Label1.Name = "Label1";
this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Label1.Size = new System.Drawing.Size(136, 17);
this.Label1.TabIndex = 19;
this.Label1.Text = "Measure Channels 0 to 1";
//
// lblDemoFunction
//
this.lblDemoFunction.BackColor = System.Drawing.SystemColors.Window;
this.lblDemoFunction.Cursor = System.Windows.Forms.Cursors.Default;
this.lblDemoFunction.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblDemoFunction.ForeColor = System.Drawing.SystemColors.WindowText;
this.lblDemoFunction.Location = new System.Drawing.Point(8, 8);
this.lblDemoFunction.Name = "lblDemoFunction";
this.lblDemoFunction.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.lblDemoFunction.Size = new System.Drawing.Size(337, 41);
this.lblDemoFunction.TabIndex = 0;
this.lblDemoFunction.Text = "Demonstration of MccBoard.AInScan() with scan option set to MccDaq.ScanOptions.Fo" +
"reground";
this.lblDemoFunction.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// cmdSaveCounts
//
this.cmdSaveCounts.BackColor = System.Drawing.SystemColors.Control;
this.cmdSaveCounts.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cmdSaveCounts.ForeColor = System.Drawing.Color.Black;
this.cmdSaveCounts.Location = new System.Drawing.Point(328, 56);
this.cmdSaveCounts.Name = "cmdSaveCounts";
this.cmdSaveCounts.TabIndex = 20;
this.cmdSaveCounts.Text = "Save Counts";
this.cmdSaveCounts.Click += new System.EventHandler(this.cmdSaveCounts_Click);
//
// label2
//
this.label2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.ForeColor = System.Drawing.Color.Black;
this.label2.Location = new System.Drawing.Point(56, 104);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 23);
this.label2.TabIndex = 22;
this.label2.Text = "Samples per channel";
//
// txtSamplesPerCh
//
this.txtSamplesPerCh.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtSamplesPerCh.Location = new System.Drawing.Point(168, 104);
this.txtSamplesPerCh.Name = "txtSamplesPerCh";
this.txtSamplesPerCh.Size = new System.Drawing.Size(112, 20);
this.txtSamplesPerCh.TabIndex = 23;
this.txtSamplesPerCh.Text = "16000";
//
// cmdDraw
//
this.cmdDraw.BackColor = System.Drawing.SystemColors.Control;
this.cmdDraw.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cmdDraw.ForeColor = System.Drawing.Color.Black;
this.cmdDraw.Location = new System.Drawing.Point(384, 368);
this.cmdDraw.Name = "cmdDraw";
this.cmdDraw.TabIndex = 24;
this.cmdDraw.Text = "draw";
this.cmdDraw.Click += new System.EventHandler(this.cmdDraw_Click);
//
// textStep
//
this.textStep.Location = new System.Drawing.Point(96, 368);
this.textStep.Name = "textStep";
this.textStep.Size = new System.Drawing.Size(48, 20);
this.textStep.TabIndex = 25;
this.textStep.Text = "1";
//
// label3
//
this.label3.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.ForeColor = System.Drawing.Color.Black;
this.label3.Location = new System.Drawing.Point(64, 368);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(32, 23);
this.label3.TabIndex = 26;
this.label3.Text = "Step";
//
// label4
//
this.label4.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.ForeColor = System.Drawing.Color.Black;
this.label4.Location = new System.Drawing.Point(168, 368);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(112, 23);
this.label4.TabIndex = 27;
this.label4.Text = "Total Points to draw";
//
// textTotalPoints
//
this.textTotalPoints.Location = new System.Drawing.Point(280, 368);
this.textTotalPoints.Name = "textTotalPoints";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -