怎么实现蓝牙串口与matlab的通信

怎么实现蓝牙串口与matlab的通信,第1张

首先将蓝牙适配器查到电脑USB,电脑自动识别并安装蓝牙驱动。完成后电脑右下方出现蓝牙标志。

Matlab蓝牙串口设置与连接通讯

利用外部设备(单片机等)给蓝牙数据模块上电,执行配对工作。

1 点击蓝牙标志,点击添加设备,

2 下一步

3 第二项“输入设备配对码”

4 密码:1234

5 至此蓝牙连接完成,电脑自动安装驱动。

3

开始进行软件配置

1 To find available Bluetooth devices

搜索蓝牙设备

2 To construct a Bluetooth Channel object

连接蓝牙

3 To connect the Bluetooth Channel object to the remote device

打开蓝牙

#include "stdio.h"

void main()

{

int code_in

int i,j,a

int code_out[15]

int mid[15]

/* code */

int g[15]={0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x365,0x1AF,0x35E,0x1D9,0x3B2}

printf("输入原始信息数据(16进制):")

scanf("%x",&code_in)

for(i=0i<15i++)

{

a=code_in&g[i]

for(j=0j<10j++)

{

mid[j]=a&1

a=a>>1

}

code_out[i]=mid[0]

for(j=1j<10j++)

code_out[i]=code_out[i]^mid[j]

}

printf("纠错编码后的输出比特流: ")

for(i=15i>0i--)

printf("%d",code_out[i-1])

/* decode and correct */

for (i=0i<15i++)

{

code_out[i]=0

mid[i]=0

}

code_in=0

i=0

j=0

a=0

int check_out[5]

int errorflag,matchbit,matchflag,comparebit

int check[5]={0x765,0x9AF,0x135E,0x21D9,0x43B2} /*the check array*/

printf("\n输入接受端收到的原始数据(16进制):")

scanf("%x",&code_in) /*input the data received at the receiver*/

a=code_in

for (i=0i<15i++) /*change the data received into bits*/

{

code_out[i]=a&1

a=a>>1

}

for(i=0i<5i++)/*caculate the cheksum*/

{

a=code_in&check[i]

for(j=0j<15j++)/*get every bit of a */

{

mid[j]=a&1

a=a>>1

}

check_out[i]=mid[0]

for(j=1j<15j++)

check_out[i]=check_out[i]^mid[j]/*add the bits in mode 2*/

}

i=0

errorflag=0

do

{

if (check_out[i]==1)

{

errorflag=1

i=5

}

else

i++

}

while (i<5)/* check if the check is all 0 */

if (errorflag==1)

{

i=0

matchbit=100 /* look for the same line*/

do

{

j=0

matchflag=1

do

{

comparebit=(check[j]>>i)&1/* get the [j][i] bit of the array*/

if (check_out[j]!=comparebit)

{

j=5

matchflag=0

}/*not coincident,jump out at once*/

else

j++

}

while (j<5)

if (matchflag==1)

{

matchbit=i

i=15

} /*if found,jump out at once*/

else

i++

}

while (i<15)

if (matchbit<=14)

{

code_out[matchbit]=code_out[matchbit]^1 /*correct the error bit*/

printf("第%d位数据出错!\n",matchbit+1)

}

else

printf("错误但不可纠!\n")

}

else printf("传输正确或错误不可检!\n")

printf("还原的信息比特为:")

for (i=10i>0i--) /*only print the information bits*/

printf("%d",code_out[i-1])

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8072819.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存