python连接蓝牙设备_使用Pybluez连接到已经配对的蓝牙设备?

我正在编写一个python程序,它涉及到使用蓝牙设备。对吗现在我可以从python程序连接到bluetooth设备,但是每次退出python程序时,我都必须将设备包切换到配对模式(通过拉一个开关),然后再与它配对。

我希望你能给我展示一种方法,通过这种方法我可以自动连接到配对的设备上,而不是每次运行python程序时都让它进入配对模式并再次连接。在

这是我的bluetooth python模块的代码:import bluetooth

from bluetooth.btcommon import BluetoothError

import time

class DeviceConnector:

TARGET_NAME = "Device name"

TARGET_ADDRESS = None

SOCKET = None

def __init__(self):

pass

def getConnectionInstance(self):

self.deviceDiscovery()

if(DeviceConnector.TARGET_ADDRESS is not None):

print('Device found!')

self.connect_bluetooth_addr()

return DeviceConnector.SOCKET

else:

print('Could not find target bluetooth device nearby')

def deviceDiscovery(self):

try:

nearby_devices = b


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部