日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示)

發布時間:2025/6/15 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?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;namespace Adc_Display {public partial class Form1 : Form{public Form1(){InitializeComponent();serialPort1.DataReceived += new SerialDataReceivedEventHandler(PortDataReceivedEvent); //串口數據接收事件 System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; //不檢查線程間的操作 }//剛開始讓窗口遮蔽住下面的進度條private void Form1_Load(object sender, EventArgs e){this.Size = new Size(620, 107);//縮小窗口}//定義10個進度條對象ProgressBar[] GetProgressBar(){return new ProgressBar[] { progressBar1, progressBar2, progressBar3, progressBar4, progressBar5, progressBar6, progressBar7, progressBar8, progressBar9, progressBar10,};//返回一個對象數組}//串口數據接收private void PortDataReceivedEvent(object sender, SerialDataReceivedEventArgs args) {ProgressBar[] MyProgressBar = GetProgressBar();byte[] Data = new byte[serialPort1.BytesToRead]; serialPort1.Read(Data,0,Data.Length);//讀foreach (byte MyData in Data){for(int i = 1;i < 10;i++){MyProgressBar[10 - i].Value = MyProgressBar[10 - i - 1].Value;//把9的值給10,8給9,,,,,,}progressBar1.Value = (int)MyData;/*把值顯示在textBox1中*/string str = MyData.ToString("x");textBox1.Text = "0x" + (str.Length == 1 ? "0" + str : str);}}private void button1_Click(object sender, EventArgs e){if (serialPort1.IsOpen)//判斷{groupBox2.Visible = false; //第二個框框不可見this.Size = new Size(620, 107); //縮小serialPort1.Close();//此處可不加try,catchProgressBar[] MyProgeressBar = GetProgressBar();foreach(ProgressBar theBar in MyProgeressBar)//遍歷,每個progressbar歸零{theBar.Value = 0;}button1.Text = "打開串口";}else{try{serialPort1.PortName = comboBox1.Text;//串口號serialPort1.Open(); //打開groupBox2.Visible = true; //第二個框框可見this.Size = new Size(620, 436); //放大button1.Text = "關閉串口";//按鍵標題}catch{MessageBox.Show("串口打開錯誤", "錯誤");}}}} }

www.DoYoung.net(部分代碼來至杜洋工作室)

總結

以上是生活随笔為你收集整理的C#之windows桌面软件第十一课:电脑ADC值显示(上位机)(多通道显示)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。