Python and Bluetooth
2024-09-20 18:48:17
环境
Windows7-64bit + Python2.7.15-64bit + Pybluez
安装pybluez时会报错,处理方法~
1.安装VCForPython27.msi,这是为了提供visual c++ 9.0运行环境
2.C:\Program Files (x86)\Microsoft SDKs\Windows\ 目录中 V7.0A 改为 V6.0A
重新pip2 install pybluez,很快就完成环境安装
PyBluez
A Python Bluetooth library for the Windows and GNU/Linux operating systems. Mac OSX and Linux Python are supported by LightBlue, a number of cell phones running the Symbian OS are supported under Python. The following examples use the PyBluez bluetooth library.
翻译成中文意思大概就是:Linux和Windows系统都能使用这个python蓝牙库,其中Mac和Linux还可以支持LightBlue这个库,部分塞班(Symbian)系统也支持蓝牙库pybluez
查看周围蓝牙设备
from bluetooth import * print "performing inquiry..." nearby_devices = discover_devices(lookup_names = True) print "found %d devices" % len(nearby_devices) for name, addr in nearby_devices:
print " %s - %s" % (addr, name)
设备连接
from bluetooth import *
# Create the client socket
client_socket=BluetoothSocket( RFCOMM ) client_socket.connect(("30:21:88:CD:4E:08", 3)) #client_socket.send("Hello World") print "Finished"
#进程一结束意味着连接断开,这里为了不断开用一个while循环来占用CPU
while True:
time.sleep(0.001)
continue client_socket.close()
手动部分
- 第一次连接设备时应该要手动配置PC和蓝牙设备,我这里因为是音乐盒子,所以只需要按照提示配置PC就OK
- Windows7发现就算连接上了,外部蓝牙设备依旧没反应,将程序打包成exe放到Windows8,没毛病(暂时不清楚是什么原因,知道的大神望告知!!!)
参考:
http://pages.iu.edu/~rwisman/c490/html/pythonandbluetooth.htm
最新文章
- Unity3d使用UGUI实现长按功能
- Linux小技巧总结
- C语言与套接字
- 关于三星I9305出现android.process.acore提示问题
- Hadoop学习笔记(1)
- javascript学习第三课引用类型object
- iOS - OC NSLocale		本地化信息
- 【阿里云产品公测】OTS使用之简单线上产品实践基于PythonSDK
- UNIX网络编程 卷2:进程间通信
- validate验证
- 项目swift的一些问题
- Mysql数据库引擎介绍--转载
- thread run 和 start 的区别
- 20155333 2016-2017-2 《Java程序设计》第六周学习总结
- drozer工具的安装与使用:之二使用篇
- Kattis之旅——Perfect Pth Powers
- jquery实现上一页下一页
- struts2学习(7)值栈简介与OGNL引入
- cronolog:日志分割工具
- Oracle基础 表分区
热门文章
- FW:考查嵌入式C开发人员的最好的16道题(转)
- 数据挖掘中ID3算法实现zz
- mongo学习-TTL索引 过期数据
- mongodb3 设置用户名密码 ,linux
- IE(IE6/IE7/IE8)支持HTML5标签
- (广搜)Dungeon Master -- poj -- 2251
- [leetcode] 9. Binary Tree Level Order Traversal
- Android-HttpUtil工具类
- 二道Const,readonly 和 override, new的面试题
- Mybatis 模糊查询 like【笔记】Could not set parameters for mapping