久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
C#寫的串口設置HC05_BCM417藍牙上位機源碼
[打印本頁]
作者:
laoxianccc
時間:
2018-6-14 20:54
標題:
C#寫的串口設置HC05_BCM417藍牙上位機源碼
運行界面:
0.png
(11.9 KB, 下載次數: 52)
下載附件
2018-6-14 22:27 上傳
0.png
(40.51 KB, 下載次數: 59)
下載附件
2018-6-14 22:21 上傳
全部資料51hei下載地址:
2、COM_HC05_BCM417_1.zip
(2.18 MB, 下載次數: 59)
2018-6-14 20:54 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
源碼預覽:
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.Diagnostics;
using System.Diagnostics.PerformanceData;
using System.Threading;
namespace COM_A
{
public partial class analysis : Form
{
Form1 myFrm=new Form1();
public string myStr1;
public int myFlag=0;
public analysis()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
myFrm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
myFrm.sendData("AT\r\n");
myFlag = 1;
}
private void analysis_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
//this.pictureBox1.Image = Image.FromFile(@"C:\Users\nxzh\Desktop\2.jpg");
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\2.jpg");//bin文件中
this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\2.jpg");//bin文件中
//開始執行后臺操作
//backgroundWorker1.RunWorkerAsync();
//多線程處理
Thread thread = new Thread(CrossThreadFlush);
thread.IsBackground = true;
thread.Start();
}
private void CrossThreadFlush()
{
while (true)
{
//將sleep和無限循環放在等待異步的外面
Thread.Sleep(10);
ThreadFunction();
}
}
private delegate void FlushClient();//代理
private void ThreadFunction()//多線程處理
{
//try
{
if ((this.txbBAUD.InvokeRequired) || (this.txbNameIn.InvokeRequired) || (this.txbNameOut.InvokeRequired) || (this.textBox4.InvokeRequired) || (this.textBox5.InvokeRequired) || (this.textBox6.InvokeRequired))//等待異步
{
FlushClient fc = new FlushClient(ThreadFunction);
try
{
this.Invoke(fc);//通過代理調用刷新方法
}
catch
{ }
}
else
{
//this.txbBAUD.Text = DateTime.Now.ToString();
analysisData(myFrm.myStr);
}
}
//catch
{ }
}
/*private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
#region
/*this.Invoke((EventHandler)(delegate
{
try
{
if (myFrm.myStr == "OK\r\n")
{
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\green.png");
}
else
{
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
if (myFrm.myStr == "OK:" + comboBox1.Text + "\r\n")
{
this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\green.png");
}
else
{
this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
}
catch
{
}
}));//
//多線程使用時調用
#endregion
//analysisData(myFrm.myStr);
}
}*/
public void analysisData(string str)//解析函數
{
if ((str == "OK\r\n"))
{
if (myFlag == 1)
{
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\green.png");
this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");
this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
else if (myFlag == 2)
{
this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\green.png");
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
else if (myFlag == 3)
{
this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\green.png");
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
}
else
{
this.pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\red.png");
this.pictureBox5.Image = Image.FromFile(Application.StartupPath + "\\red.png");
this.pictureBox6.Image = Image.FromFile(Application.StartupPath + "\\red.png");
}
if (str == "OK:" + myStr1 + "\r\n")
{
this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\green.png");
txbBAUD.Text = myStr1;
}
else
{
this.pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\red.png");
txbBAUD.Text = "";
}
if (str == "OK:" + txbNameIn.Text.ToString() + "\r\n")
{
this.pictureBox3.Image = Image.FromFile(Application.StartupPath + "\\green.png");
txbNameOut.Text = txbNameIn.Text;
}
else
{
this.pictureBox3.Image = Image.FromFile(Application.StartupPath + "\\red.png");
txbNameOut.Text = "";
}
if (str == "OK:" + textBox4.Text.ToString() + "\r\n")
{
this.pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\green.png");
textBox5.Text = textBox4.Text;
}
else
{
this.pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\red.png");
textBox5.Text = "";
}
if ((str == "OK:M\r\n") || (myFrm.myStr == "OK:S\r\n"))
{
this.pictureBox7.Image = Image.FromFile(Application.StartupPath + "\\green.png");
textBox6.Text = comboBox2.Text;
}
else
{
this.pictureBox7.Image = Image.FromFile(Application.StartupPath + "\\red.png");
textBox6.Text = "";
}
}
private void analysis_FormClosing(object sender, FormClosingEventArgs e)
{
if (DialogResult.Yes == MessageBox.Show("程序正在使用中,確認退出?", "確認退出", MessageBoxButtons.YesNo))
{
//MessageBox.Show("立即退出!");
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
string myTempStr;
switch (cbxBAUD.SelectedIndex)
{
case 9:
myTempStr = "A";
break;
case 10:
myTempStr = "B";
break;
case 11:
myTempStr = "C";
break;
default:
myTempStr = (cbxBAUD.SelectedIndex + 1).ToString();
break;
}
//MessageBox.Show(comboBox1.SelectedIndex.ToString());
myFrm.sendData("AT+BAUD:" + myTempStr + "\r\n");
myStr1 = this.cbxBAUD.Text;
}
private void button4_Click(object sender, EventArgs e)
{
if (txbNameIn.Text.Length < 20)
{
myFrm.sendData("AT+NAME:" + txbNameIn.Text.ToString() + "\r\n");
}
else
{
MessageBox.Show("藍牙名稱超過20個字符","提示");
}
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox4.Text.Length ==4)
{
myFrm.sendData("AT+PIN:" + textBox4.Text.ToString() + "\r\n");
}
else
{
MessageBox.Show("藍牙密碼不等于4個字符", "提示");
}
}
private void button6_Click(object sender, EventArgs e)
{
myFlag = 2;
myFrm.sendData("AT+PAIR\r\n");
}
private void button7_Click(object sender, EventArgs e)
{
myFrm.sendData("AT+DEFAULT\r\n");
myFlag = 3;
}
private void button8_Click(object sender, EventArgs e)
{
if (comboBox2.Text == "主模式")
{
myFrm.sendData("AT+ROLE=M\r\n");
}
else if (comboBox2.Text == "從模式")
{
myFrm.sendData("AT+ROLE=S\r\n");
}
}
}
}
復制代碼
作者:
mk_cs
時間:
2018-9-3 20:15
很詳細啊,學習學習
歡迎光臨 (http://m.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
欧美777
|
青草av在线
|
亚洲免费在线观看视频
|
三年中文在线看免费观看
|
一区二区国产在线
|
久久久久久97
|
高潮一区二区三区乱码
|
精品久久久久久一区二区里番
|
日韩欧美综合
|
亚洲精品无
|
久久精品视频国产
|
成人免费在线观看网站
|
精品免费国产
|
五月婷婷丁香六月
|
亚洲一级大片
|
欧美日韩黄
|
色妞色视频一区二区三区四区
|
天天拍天天干
|
久久精品日韩
|
成年视频在线观看
|
在线一区视频
|
日韩精品中文字幕在线观看
|
国内av在线
|
欧美成人精品一区二区
|
四虎com
|
久久精品视频一区
|
99视频免费在线观看
|
中文字幕高清在线
|
中国农村毛片免费播放
|
久草国产视频
|
欧美日视频
|
国产成人精品亚洲男人的天堂
|
国产一区二区网站
|
91精品国
|
国产精品久久一区二区三区
|
亚洲区在线
|
亚洲一区在线免费观看
|
求av网站
|
国产精品一区二区在线免费观看
|
欧美亚洲激情
|
一色桃子av
|