📄 ulai02.cs
字号:
this.textTotalPoints.Size = new System.Drawing.Size(56, 20);
this.textTotalPoints.TabIndex = 28;
this.textTotalPoints.Text = "1000";
//
// cmdClear
//
this.cmdClear.BackColor = System.Drawing.SystemColors.Control;
this.cmdClear.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cmdClear.ForeColor = System.Drawing.Color.Black;
this.cmdClear.Location = new System.Drawing.Point(496, 368);
this.cmdClear.Name = "cmdClear";
this.cmdClear.TabIndex = 29;
this.cmdClear.Text = "clear";
this.cmdClear.Click += new System.EventHandler(this.cmdClear_Click);
//
// frmDataDisplay
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 13);
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(1000, 405);
this.Controls.Add(this.cmdClear);
this.Controls.Add(this.textTotalPoints);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.textStep);
this.Controls.Add(this.cmdDraw);
this.Controls.Add(this.txtSamplesPerCh);
this.Controls.Add(this.label2);
this.Controls.Add(this.cmdSaveCounts);
this.Controls.Add(this.cmdStopConvert);
this.Controls.Add(this.cmdStart);
this.Controls.Add(this.Label1);
this.Controls.Add(this.lblDemoFunction);
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.ForeColor = System.Drawing.Color.Blue;
this.Location = new System.Drawing.Point(190, 108);
this.Name = "frmDataDisplay";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Universal Library Analog Input Scan";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmDataDisplay());
}
private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)
{
int j;
int i;
MccDaq.ErrorInfo ULStat;
MccDaq.Range Range;
MccDaq.ScanOptions Options;
int Rate;
int Count;
int LowChan;
int HighChan;
float TemSamp;
cmdStart.Enabled = false;
// Collect the values by calling MccDaq.MccBoard.AInScan function
// Parameters:
// LowChan :the first channel of the scan
// HighChan :the last channel of the scan
// Count :the total number of A/D samples to collect
// Rate :sample rate
// Range :the range for the board
// MemHandle :Handle for Windows buffer to store data in
// Options :data collection options
LowChan = 0; // first channel to acquire
HighChan=1; // last channel to acquire
//HighChan = int.Parse(txtHighChan.Text); // last channel to acquire
//if ((HighChan > 7)) HighChan = 7;
//txtHighChan.Text = HighChan.ToString();
Count = NumPoints; // total number of data points to collect
Rate = 16000; // per channel sampling rate ((samples per second) per channel)
// return data as 12-bit values (ignored for 16-bit boards)
Options = MccDaq.ScanOptions.ConvertData;
Range = MccDaq.Range.Bip1Volts; // set the range
ULStat = DaqBoard.AInScan( LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);
if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadRange)
{
MessageBox.Show( "Change the Range argument to one supported by this board.", "Unsupported Range", 0);
}
// Transfer the data from the memory buffer set up by Windows to an array
ULStat = MccDaq.MccService.WinBufToArray( MemHandle, out ADData[0], FirstPoint, Count);
/*
for (i=0; i<=HighChan; ++i)
lblADData[i].Text = ADData[i].ToString("D");
for (j=HighChan + 1; j<=7; ++j)
lblADData[j].Text = "0";*/
//unpack the array into each channel
//for(i=0; i<=(NumPoints-ChanNum); i=i+ChanNum)
//{
//ADData_ch0[i]
//}
FileStream dataFile_ch0=new FileStream("E:/micArray/dataV_ch0.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch0=new StreamWriter(dataFile_ch0);
FileStream dataFile_ch1=new FileStream("E:/micArray/dataV_ch1.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch1=new StreamWriter(dataFile_ch1);
for(i=0; i<=(NumPoints-ChanNum); i=i+ChanNum)
{
//write data from ch0 to file dataV_ch0.txt
ULStat=DaqBoard.ToEngUnits( Range, ADData[i], out TemSamp);
sw_ch0.Write(TemSamp);
sw_ch0.Write(space);
//write data from ch1 to file dataV_ch1.txt
ULStat=DaqBoard.ToEngUnits( Range, ADData[i+1], out TemSamp);
sw_ch1.Write(TemSamp);
sw_ch1.Write(space);
}
sw_ch0.Close();
sw_ch1.Close();
cmdStart.Enabled = true;
}
private void cmdStopConvert_Click(object eventSender, System.EventArgs eventArgs)
{
MccDaq.ErrorInfo ULStat;
ULStat = MccDaq.MccService.WinBufFree(MemHandle); // Free up memory for use by
// other programs
MemHandle = 0;
Application.Exit();
}
private void cmdSaveCounts_Click(object sender, System.EventArgs e)
{
FileStream dataFile_ch0=new FileStream("E:/micArray/data_ch0.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch0=new StreamWriter(dataFile_ch0);
FileStream dataFile_ch1=new FileStream("E:/micArray/data_ch1.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch1=new StreamWriter(dataFile_ch1);
for(int i=0; i<=(NumPoints-ChanNum); i=i+ChanNum)
{
sw_ch0.Write(ADData[i]);
sw_ch0.Write(space);
sw_ch1.Write(ADData[i+1]);
sw_ch1.Write(space);
}
sw_ch0.Close();
sw_ch1.Close();
}
private void cmdSveVolts_Click(object sender, System.EventArgs e)
{
float TemSamp;
MccDaq.ErrorInfo ULStat;
MccDaq.Range Range;
Range = MccDaq.Range.Bip1Volts;
FileStream dataFile_ch0=new FileStream("E:/micArray/dataV_ch0.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch0=new StreamWriter(dataFile_ch0);
FileStream dataFile_ch1=new FileStream("E:/micArray/dataV_ch1.txt",FileMode.Create,FileAccess.Write);
StreamWriter sw_ch1=new StreamWriter(dataFile_ch1);
for(int i=0; i<=(NumPoints-ChanNum); i=i+ChanNum)
{
//write data from ch0 to file dataV_ch0.txt
ULStat=DaqBoard.ToEngUnits( Range, ADData[i], out TemSamp);
sw_ch0.Write(TemSamp);
sw_ch0.Write(space);
//write data from ch1 to file dataV_ch1.txt
ULStat=DaqBoard.ToEngUnits( Range, ADData[i+1], out TemSamp);
sw_ch1.Write(TemSamp);
sw_ch1.Write(space);
}
sw_ch0.Close();
sw_ch1.Close();
}
private void cmdDraw_Click(object sender, System.EventArgs e)
{
MccDaq.ErrorInfo ULStat;
MccDaq.Range Range;
Range = MccDaq.Range.Bip1Volts;
int Step;
int NumDraw;
int StartY;
int EndY;
float TempSamp;
using(Graphics g=this.CreateGraphics())
{
g.DrawLine(Pens.Black, new Point(0,240), new Point(ClientRectangle.Width,240));
g.DrawLine(Pens.Black, new Point(0,140), new Point(ClientRectangle.Width,140));
g.DrawLine(Pens.Black, new Point(0,340), new Point(ClientRectangle.Width,340));
}
//initialize the drawing parameters
const int maxNum=1000;
Step = int.Parse(textStep.Text);
textStep.Text = Step.ToString();
NumDraw = int.Parse(textTotalPoints.Text);
textTotalPoints.Text = NumDraw.ToString();
//To make sure that all parameters are valid
if(NumDraw>maxNum)
NumDraw=maxNum;
if(NumDraw>NumPerCh-1)
NumDraw=NumPerCh-1;
if(NumDraw*Step>NumPerCh-1)
Step=(NumPerCh-1)/NumDraw;
if(NumDraw*Step>NumPerCh-1)
Step=Step-1;
ULStat=DaqBoard.ToEngUnits( Range, ADData[0], out TempSamp);
StartY=240+Convert.ToInt32(TempSamp*100);
Point StartP = new Point(0,StartY);
Point EndP;
for (int i=1; i<=NumDraw; i++)
{
ULStat=DaqBoard.ToEngUnits( Range, ADData[i*Step*ChanNum], out TempSamp);
EndY=240+Convert.ToInt32(TempSamp*100);
EndP= new Point(i,EndY);
using(Graphics g=this.CreateGraphics())
{
g.DrawLine(Pens.Blue, StartP, EndP);
}
StartP=EndP;
}
}
private void cmdClear_Click(object sender, System.EventArgs e)
{
using(Graphics g=this.CreateGraphics())
{
g.Clear(Color.White);
g.DrawLine(Pens.Black, new Point(0,240), new Point(ClientRectangle.Width,240));
g.DrawLine(Pens.Black, new Point(0,140), new Point(ClientRectangle.Width,140));
g.DrawLine(Pens.Black, new Point(0,340), new Point(ClientRectangle.Width,340));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -