QQ登录

只需一步,快速开始

查看: 3233|回复: 0
收起左侧

[求助] 万博网页版登陆页派连接蓝牙适配器,与手机通过蓝牙进行通信

[复制链接]
发表于 2015-10-14 11:07:03 | 显示全部楼层 |阅读模式
  • #include <stdio.h>
  • #include <unistd.h>
  • #include <sys/socket.h>
  • #include <bluetooth/bluetooth.h>
  • #include <bluetooth/rfcomm.h>
  • int main(int argc, char **argv)
  • {
  •     struct sockaddr_rc addr = { 0 };
  •     int s, status, len=0;
  •     char dest[18 = "00:12:01:31:01:13";
  •     char buf[256;
  •     // allocate a socket
  •     s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
  •     // set the connection parameters (who to connect to)
  •     addr.rc_family = AF_BLUETOOTH;
  •     addr.rc_channel = (uint8_t) 1;
  •     str2ba( dest, &addr.rc_bdaddr );
  •     // connect to server
  •     status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
  •     if(status){
  •         printf(" failed to connect the device!\n");
  •         return -1;
  •     }
  •     do{
  •         len = read(s, buf, sizeof buf);
  •      if( len>0 ) {
  •          buf[len=0;
  •          printf("%s\n",buf);
  •          write(s, buf, strlen(buf));
  •      }
  •     }while(len>0);
  •     close(s);
  •     return 0;
  • }
  • 现在万博网页版登陆页派与手机已经连接,但无法读取到手机发送的信息,万博网页版登陆页派上的连接选的是Serial Port

  • 回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则