C#實(shí)現(xiàn)串口示波器
本文實(shí)例為大家分享了C#實(shí)現(xiàn)串口示波器的具體代碼,供大家參考,具體內(nèi)容如下
開發(fā)工具
- visual studio2019
C#串口示波器,實(shí)時(shí)刷新端口號(hào),動(dòng)態(tài)繪制多條折線,獲取串口數(shù)據(jù)并輸出到文本框
之前用Java實(shí)現(xiàn)串口示波器對(duì)我來說還是比較困難的,而且實(shí)現(xiàn)的效果不盡如人意,就用C#開發(fā)了。
C#可以自由布置界面,在工具欄直接拖拽控件到窗體,然后雙擊控件就能添加事件了,很方便
最終效果是實(shí)現(xiàn)了,但是有個(gè)數(shù)據(jù)丟失的問題
數(shù)據(jù)處理到繪圖分三個(gè)步驟:
1、獲取串口發(fā)送的數(shù)據(jù)
2、把數(shù)據(jù)按需要提取到中間容器集合list1中
3、從集合中提取繪圖的y值
測(cè)試得出的結(jié)果就是數(shù)據(jù)放進(jìn)集合前不存在丟失,從集合中拿出數(shù)據(jù)這一過程也沒問題。所以問題就出在第二步了,已解決(按需提取數(shù)據(jù)的規(guī)則要盡可能設(shè)置的詳細(xì)一點(diǎn)就行)。
代碼:
namespace CommPortsDesigner { ? ? public partial class Form1 : Form ? ? { ? ? ? ? public Form1() ? ? ? ? { ? ? ? ? ? ? InitializeComponent(); ? ? ? ? } ? ? ? ? private void Form1_Load(object sender, EventArgs e) //窗體運(yùn)行完成即為加載,加載完成會(huì)觸發(fā)事件 ? ? ? ? { ? ? ? ? } ? ? ? ? //傳入原始數(shù)據(jù)datas及需要匹配的字符串r,得到需要的數(shù)據(jù)列表list ? ? ? ? private List<int> DealData(string datas, Regex r, string split)? ? ? ? ? { ? ? ? ? ? ? if (string.IsNullOrEmpty(datas)) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? throw new ArgumentException($"“{nameof(datas)}”不能是 Null 或?yàn)榭铡?, nameof(datas)); ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? List<int> list1=new List<int> { }; ? ? ? ? ? ? string s1=""; ? ? ? ? ? ? MatchCollection mc = r.Matches(datas); ?//提取符合要求的字符串 ? ? ? ? ? ? for (int i = 0; i < mc.Count; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? textBox2.AppendText(mc[i].Value + "\r\n"); ? ?//測(cè)試數(shù)據(jù)是否正確輸出 ? ? ? ? ? ? ? ? s1 = s1 + mc[i].Value; ? ? ? ? ? ? } ? ? ? ? ? ? string[] d = s1.Split( new string[]{split}, StringSplitOptions.RemoveEmptyEntries); ? ? ? ? ? ? for (int i=0;i<d.Length;i++) ? ? ? ? ? ?//將數(shù)字存入列表 ? ? ? ? ? ? { ? ? ? ? ? ? ? ? list1.Add( int.Parse(d[i])); ? ? ? ? ? ? } ? ? ? ? ? ? //測(cè)試畫圖用的數(shù)據(jù)是否解析正確 ? ? ? ? ? ? if (split.Equals("LP4:")) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? foreach (int m in list1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? textBox3.AppendText(m + "\r\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? return list1; ? ? ? ? }? ? ? ? ? private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) ? ? ? ? { ? ? ? ? } ? ? ? ? private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ?? ? ? ? ? ? ? ? ? serialPort1.BaudRate = int.Parse(comboBox2.SelectedItem.ToString()); ? ? ? ? } ? ? ? ? private void searchPort() ? ? ? ? { ? ? ? ? ? ? string Buffer; ? ? ? ? ? ? comboBox1.Items.Clear(); ? ? ? ? ? ? for (int i = 1; i < 20; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? Buffer = "COM" + i.ToString(); ? ? ? ? ? ? ? ? ? ? serialPort1.PortName = Buffer; ? ? ? ? ? ? ? ? ? ? serialPort1.Open(); ? ? ? ? ? ? ? ? ? ? comboBox1.Items.Add(Buffer); ? ? ? ? ? ? ? ? ? ? comboBox1.SelectedItem = Buffer; ? ? ? ? ? ? ? ? ? ? serialPort1.Close(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? { } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void getDatas()? ? ? ? ? { ? ? ? ? ? ? System.Text.RegularExpressions.Regex r1 = new System.Text.RegularExpressions.Regex("LP1:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r2 = new System.Text.RegularExpressions.Regex("LP2:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r3 = new System.Text.RegularExpressions.Regex("LP3:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r4 = new System.Text.RegularExpressions.Regex("LP4:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r5 = new System.Text.RegularExpressions.Regex("LP5:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r6 = new System.Text.RegularExpressions.Regex("CC1:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r7 = new System.Text.RegularExpressions.Regex("CC2:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r8 = new System.Text.RegularExpressions.Regex("CC3:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r9 = new System.Text.RegularExpressions.Regex("CC4:(-?)\\d+"); ? ? ? ? ? ? System.Text.RegularExpressions.Regex r10 = new System.Text.RegularExpressions.Regex("CC5:(-?)\\d+"); ? ? ? ? ? ? byte[] inbuffer = null; ? ? ? ? ? ? //Queue<int> q1 = new Queue<int>(); ? ? ? ? ? ? if (serialPort1.IsOpen && serialPort1.BytesToRead > 0) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss.ff"; ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Milliseconds; ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Milliseconds; ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? inbuffer = new byte[serialPort1.BytesToRead]; ? ? ? ? ? ? ? ? ? ? serialPort1.Read(inbuffer, 0, serialPort1.BytesToRead); ? ? ? ? ? ? ? ? ? ? string strRaad = ASCIIEncoding.ASCII.GetString(inbuffer, 0, inbuffer.Length); ? ? ? ? ? ? ? ? ? ? textBox1.AppendText(strRaad); ? ? ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.Minimum = DateTime.Now.AddSeconds(-5).ToOADate(); ? ? ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.Maximum = DateTime.Now.ToOADate(); ? ? ? ? ? ? ? ? ? ? chart1.ChartAreas[0].AxisX.Interval = 500; ? ? ? ? ? ? ? ? ? ? if (btn_start.Text.Equals("停止")) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? //LP1 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox2.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r2, "LP2:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[1].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count2 = count2 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[1].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? //LP2 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox2.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r2, "LP2:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[1].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count2 = count2 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[1].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //LP3 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox3.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r3, "LP3:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[2].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count3 = count3 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[2].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //LP4 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox4.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r4, "LP4:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[3].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//count4 = count4 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[3].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //LP5 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox5.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r5, "LP5:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[4].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count5 = count5 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[4].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //CC1 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox6.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r6, "CC1:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[5].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count6 = count6 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[5].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //CC2 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox7.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r7, "CC2:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[6].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count7 = count7 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[6].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //CC3 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox8.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r8, "CC3:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[7].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count8 = count8 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[8].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //CC4 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox9.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r9, "CC4:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[8].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count9 = count9 + 5; } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[8].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? //CC5 ? ? ? ? ? ? ? ? ? ? ? ? if (checkBox10.Checked) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? foreach (int y in DealData(strRaad, r10, "CC5:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[9].Points.AddXY(DateTime.Now.ToOADate(), y); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //count10 = count10 + 5; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? chart1.Series[9].Points.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? ? ? ? ? private void btn_open_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? if (serialPort1.IsOpen||btn_open.Text.Equals("關(guān)閉")) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? serialPort1.Close(); ? ? ? ? ? ? ? ? ? ? btn_open.Text = "打開"; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? { } ? ? ? ? ? ? } ? ? ? ? ? ? else ? ? ? ? ? ? { ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? serialPort1.PortName = comboBox1.Text; ? ? ? ? ? ? ? ? ? ? serialPort1.Open(); ? ? ? ? ? ? ? ? ? ? btn_open.Text = "關(guān)閉"; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? MessageBox.Show("串口打開失??!", "錯(cuò)誤"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ?? ? ? ? ? } ? ? ? ? private void timer1_Tick(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? if (!serialPort1.IsOpen) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? searchPort(); ? ? ? ? ? ? } ? ? ? ? ? ? else{} ? ? ? ? ? ?? ? ? ? ? ? ? getDatas(); ? ? ? ? } ? ? ? ? private void btn_clear_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? ?textBox1.Clear(); ? ? ? ? } ? ? ? ? private void btn_save_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? if (this.textBox1.TextLength > 0) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? string path = "D:\\log.txt"; ? ? ? ? ? ? ? ? using (StreamWriter sw = new StreamWriter(path, true)) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? String time = DateTime.Now.ToLocalTime().ToString(); ? ? ? ? ? ? ? ? ? ? sw.WriteLine("\n" + time); ? ? ? ? ? ? ? ? ? ? sw.Write(this.textBox1.Text); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? MessageBox.Show("已保存到 D:\\log.txt!"); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void btn_start_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? if (serialPort1.IsOpen) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (btn_start.Text.Equals("開始")) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? btn_start.Text = "停止"; ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? ? ? { } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? btn_start.Text = "開始"; ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? else? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (btn_start.Text.Equals("停止")) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? try ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? btn_start.Text = "開始"; ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? catch ? ? ? ? ? ? ? ? ? ? { } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? MessageBox.Show("串口未打開!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } }
因?yàn)榈谝淮伍_發(fā),所以要實(shí)現(xiàn)的功能代碼都放在一個(gè)類里了,大家將就著看吧
最終實(shí)現(xiàn)的效果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
AjaxControlToolkit AjaxFileUpload 顯示英文改成中文的解決方法
AjaxControlToolkit AjaxFileUpload 顯示英文改成中文的解決方法,需要的朋友可以參考一下2013-03-03WPF實(shí)現(xiàn)背景燈光隨鼠標(biāo)閃動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)背景燈光隨鼠標(biāo)閃動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08C#中BitConverter.ToUInt16()和BitConverter.ToString()的簡(jiǎn)單使用
這篇文章主要介紹了C#中BitConverter.ToUInt16()和BitConverter.ToString()的簡(jiǎn)單使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02基于WPF繪制一個(gè)點(diǎn)贊大拇指動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)繪制一個(gè)點(diǎn)贊大拇指動(dòng)畫,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下2023-02-02