我正在编写一个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