久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4861|回復: 1
打印 上一主題 下一主題
收起左側

C#寫的串口設置HC05_BCM417藍牙上位機源碼

[復制鏈接]
跳轉到指定樓層
樓主
運行界面:




全部資料51hei下載地址:
2、COM_HC05_BCM417_1.zip (2.18 MB, 下載次數: 59)


源碼預覽:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Diagnostics.PerformanceData;
  11. using System.Threading;

  12. namespace COM_A
  13. {
  14.     public partial class analysis : Form
  15.     {
  16.         Form1 myFrm=new Form1();
  17.         public string myStr1;
  18.         public int myFlag=0;

  19.         public analysis()
  20.         {
  21.             InitializeComponent();
  22.         }

  23.         private void button1_Click(object sender, EventArgs e)
  24.         {
  25.             myFrm.Show();
  26.         }

  27.         private void button2_Click(object sender, EventArgs e)
  28.         {
  29.             myFrm.sendData("AT\r\n");
  30.             myFlag = 1;

  31.         }



  32.         private void analysis_Load(object sender, EventArgs e)
  33.         {
  34.             Control.CheckForIllegalCrossThreadCalls = false;
  35.             //this.pictureBox1.Image = Image.FromFile(@"C:\Users\nxzh\Desktop\2.jpg");
  36.             this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\2.jpg");//bin文件中
  37.             this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\2.jpg");//bin文件中
  38.             //開始執行后臺操作
  39.             //backgroundWorker1.RunWorkerAsync();
  40.             //多線程處理
  41.             Thread thread = new Thread(CrossThreadFlush);
  42.             thread.IsBackground = true;
  43.             thread.Start();
  44.         }

  45.         private void CrossThreadFlush()
  46.         {
  47.             while (true)
  48.             {
  49.                 //將sleep和無限循環放在等待異步的外面
  50.                 Thread.Sleep(10);
  51.                 ThreadFunction();
  52.             }
  53.         }

  54.         private delegate void FlushClient();//代理

  55.         private void ThreadFunction()//多線程處理
  56.         {
  57.             //try
  58.             {
  59.                 if ((this.txbBAUD.InvokeRequired) || (this.txbNameIn.InvokeRequired) || (this.txbNameOut.InvokeRequired) || (this.textBox4.InvokeRequired) || (this.textBox5.InvokeRequired) || (this.textBox6.InvokeRequired))//等待異步
  60.                 {
  61.                     FlushClient fc = new FlushClient(ThreadFunction);
  62.                     try
  63.                     {
  64.                         this.Invoke(fc);//通過代理調用刷新方法
  65.                     }
  66.                     catch
  67.                     { }

  68.                 }
  69.                 else
  70.                 {
  71.                     //this.txbBAUD.Text = DateTime.Now.ToString();
  72.                     analysisData(myFrm.myStr);
  73.                 }
  74.             }
  75.             //catch
  76.             { }

  77.         }

  78.         /*private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  79.         {
  80.             while (true)
  81.             {
  82.                 #region
  83.                 /*this.Invoke((EventHandler)(delegate
  84.                 {
  85.                     try
  86.                     {
  87.                         if (myFrm.myStr == "OK\r\n")
  88.                         {
  89.                             this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\green.png");

  90.                         }
  91.                         else
  92.                         {
  93.                             this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  94.                         }

  95.                         if (myFrm.myStr == "OK:" + comboBox1.Text + "\r\n")
  96.                         {
  97.                             this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  98.                         }
  99.                         else
  100.                         {
  101.                             this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  102.                         }
  103.                     }
  104.                     catch
  105.                     {

  106.                     }

  107.                 }));//
  108.                 //多線程使用時調用
  109.                 #endregion
  110.                 //analysisData(myFrm.myStr);

  111.            }
  112.         }*/

  113.         public void analysisData(string str)//解析函數
  114.         {
  115.             if ((str == "OK\r\n"))
  116.             {
  117.                 if (myFlag == 1)
  118.                 {
  119.                     this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  120.                     this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  121.                     this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  122.                 }
  123.                 else if (myFlag == 2)
  124.                 {
  125.                     this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  126.                     this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  127.                     this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  128.                 }
  129.                 else if (myFlag == 3)
  130.                 {
  131.                     this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  132.                     this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  133.                     this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");

  134.                 }

  135.             }
  136.             else
  137.             {
  138.                 this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  139.                 this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  140.                 this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  141.             }

  142.             if (str == "OK:" + myStr1 + "\r\n")
  143.             {
  144.                 this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  145.                 txbBAUD.Text = myStr1;
  146.             }
  147.             else
  148.             {
  149.                 this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  150.                 txbBAUD.Text = "";
  151.             }
  152.             if (str == "OK:" + txbNameIn.Text.ToString() + "\r\n")
  153.             {
  154.                 this.pictureBox3.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  155.                 txbNameOut.Text = txbNameIn.Text;
  156.             }
  157.             else
  158.             {
  159.                 this.pictureBox3.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  160.                 txbNameOut.Text = "";
  161.             }

  162.             if (str == "OK:" + textBox4.Text.ToString() + "\r\n")
  163.             {
  164.                 this.pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  165.                 textBox5.Text = textBox4.Text;
  166.             }
  167.             else
  168.             {
  169.                 this.pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  170.                 textBox5.Text = "";
  171.             }

  172.             if ((str == "OK:M\r\n") || (myFrm.myStr == "OK:S\r\n"))
  173.             {
  174.                 this.pictureBox7.Image = Image.FromFile(Application.StartupPath + "\\green.png");
  175.                 textBox6.Text = comboBox2.Text;
  176.             }
  177.             else
  178.             {
  179.                 this.pictureBox7.Image = Image.FromFile(Application.StartupPath + "\\red.png");
  180.                 textBox6.Text = "";
  181.             }
  182.         }

  183.         private void analysis_FormClosing(object sender, FormClosingEventArgs e)
  184.         {
  185.             if (DialogResult.Yes == MessageBox.Show("程序正在使用中,確認退出?", "確認退出", MessageBoxButtons.YesNo))
  186.             {
  187.                 //MessageBox.Show("立即退出!");

  188.                 e.Cancel = false;
  189.             }
  190.             else
  191.             {
  192.                 e.Cancel = true;
  193.             }
  194.         }

  195.         private void button3_Click(object sender, EventArgs e)
  196.         {
  197.             string myTempStr;
  198.             switch (cbxBAUD.SelectedIndex)
  199.             {
  200.                 case 9:
  201.                     myTempStr = "A";
  202.                     break;
  203.                 case 10:
  204.                     myTempStr = "B";
  205.                     break;
  206.                 case 11:
  207.                     myTempStr = "C";
  208.                     break;
  209.                 default:
  210.                     myTempStr = (cbxBAUD.SelectedIndex + 1).ToString();
  211.                     break;
  212.             }
  213.             //MessageBox.Show(comboBox1.SelectedIndex.ToString());
  214.             myFrm.sendData("AT+BAUD:" + myTempStr + "\r\n");
  215.             myStr1 = this.cbxBAUD.Text;

  216.         }

  217.         private void button4_Click(object sender, EventArgs e)
  218.         {
  219.             if (txbNameIn.Text.Length < 20)
  220.             {
  221.                 myFrm.sendData("AT+NAME:" + txbNameIn.Text.ToString() + "\r\n");
  222.             }
  223.             else
  224.             {
  225.                 MessageBox.Show("藍牙名稱超過20個字符","提示");
  226.             }

  227.         }

  228.         private void button5_Click(object sender, EventArgs e)
  229.         {
  230.             if (textBox4.Text.Length ==4)
  231.             {
  232.                 myFrm.sendData("AT+PIN:" + textBox4.Text.ToString() + "\r\n");
  233.             }
  234.             else
  235.             {
  236.                 MessageBox.Show("藍牙密碼不等于4個字符", "提示");
  237.             }
  238.         }

  239.         private void button6_Click(object sender, EventArgs e)
  240.         {
  241.             myFlag = 2;
  242.             myFrm.sendData("AT+PAIR\r\n");
  243.         }

  244.         private void button7_Click(object sender, EventArgs e)
  245.         {
  246.             myFrm.sendData("AT+DEFAULT\r\n");
  247.             myFlag = 3;
  248.         }

  249.         private void button8_Click(object sender, EventArgs e)
  250.         {
  251.             if (comboBox2.Text == "主模式")
  252.             {
  253.                 myFrm.sendData("AT+ROLE=M\r\n");
  254.             }
  255.             else if (comboBox2.Text == "從模式")
  256.             {
  257.                 myFrm.sendData("AT+ROLE=S\r\n");
  258.             }
  259.         }
  260.     }
  261. }
復制代碼


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:393156 發表于 2018-9-3 20:15 | 只看該作者
很詳細啊,學習學習
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: a黄视频| av一二三区 | 久久久国产视频 | 精品蜜桃一区二区三区 | 永久免费在线观看 | 成人不卡| 狠狠操狠狠干 | 紧缚调教一区二区三区视频 | 美女国产| 视频一区中文字幕 | 久久网站免费视频 | 一级毛片大全免费播放 | 亚洲一区二区 | 婷婷五月色综合香五月 | 色播久久久 | 成人av片在线观看 | 精品视频免费在线 | 五月婷六月丁香 | 五月综合激情在线 | 色婷婷亚洲国产女人的天堂 | 久久91av | 亚洲 欧美 日韩在线 | 免费观看一级特黄欧美大片 | 国产91综合一区在线观看 | 国产1页| 波多野结衣先锋影音 | 男女羞羞在线观看 | 亚洲欧美中文日韩在线v日本 | 亚洲欧美日韩电影 | 麻豆久久久久久 | 在线观看日韩av | 一区二区精品 | 久久国产精品视频 | 三级视频在线观看 | 天天色av| 欧美精品一区二区蜜桃 | 成人国产精品久久 | 91黄色免费看 | 久久亚洲春色中文字幕久久久 | 免费v片在线观看 | 亚洲一区二区黄 |