C#之windows桌面软件第十课:电脑ADC值显示(上位机)(单通道显示)
生活随笔
收集整理的這篇文章主要介紹了
C#之windows桌面软件第十课:电脑ADC值显示(上位机)(单通道显示)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
C#之windows桌面軟件第十課:電腦ADC值顯示(上位機)?(單通道顯示)
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.IO.Ports;//using System.IO.Ports; namespace Adc_Display {public partial class Form1 : Form{public Form1()//構(gòu)造函數(shù){InitializeComponent();serialPort1.DataReceived += new SerialDataReceivedEventHandler(PortDataReceivedEvent); //添加串口數(shù)據(jù)接受事件//關閉多線程間操作檢查,這樣就可以在串口接收數(shù)據(jù)處理線程中可以操作定義的線程。否則會出錯。System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; }//通過進度條把值顯示出來(串口數(shù)據(jù)接收)private void PortDataReceivedEvent(object sender, SerialDataReceivedEventArgs args) {byte Data = (byte)serialPort1.ReadByte(); //把接受到的數(shù)據(jù)賦給變量DataprogressBar1.Value = Data; //把Data值給進度條}/*下面語句用來調(diào)整窗口的大小和是否可見groupBox2.Visible = false; //第二個框不可見this.Size = new Size(620, 117); //縮小窗口groupBox2.Visible = true; //第二個框框可見this.Size = new Size(620, 172); //放大窗口*///打開串口按鈕private void button1_Click(object sender, EventArgs e){if (serialPort1.IsOpen) //判斷{groupBox2.Visible = false; //第二個框不可見this.Size = new Size(620, 117); //縮小窗口serialPort1.Close(); //此處可不加try,catchbutton1.Text = "打開串口";}else{try{serialPort1.PortName = comboBox1.Text; //串口號serialPort1.Open(); //打開groupBox2.Visible = true; //第二個框框可見this.Size = new Size(620, 172); //放大窗口button1.Text = "關閉串口"; //按鍵標題}catch{MessageBox.Show("串口打開錯誤", "錯誤");}}}} }www.DoYoung.net(部分代碼來至杜洋工作室)
總結(jié)
以上是生活随笔為你收集整理的C#之windows桌面软件第十课:电脑ADC值显示(上位机)(单通道显示)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#之windows桌面软件第九课:汉字
- 下一篇: C#之windows桌面软件第十一课:电