使用PyQt6连接到MAC地址



我想用PyQt或PySide连接到MAC地址(BLE加密狗)。我知道我需要创建一个控制器和一个mac地址对象,但不知何故它不工作。

def connect_to_mac(self, mac_address: str):
self.current_device = QtBluetooth.QBluetoothDeviceInfo()
self.controller = QtBluetooth.QLowEnergyController.createCentral(self.current_device)
QtBluetooth.QBluetoothAddress(mac_address)
address_type = QtBluetooth.QLowEnergyController.RemoteAddressType.PublicAddress
self.controller.setRemoteAddressType(address_type)
self.controller.connectToDevice()

按照正确的顺序做事。首先,将您的mac地址转换为QBluetoothAddress。然后,将其传递给QBluetoothDeviceInfo以创建设备信息结构。然后,将其传递给createCentral并连接到设备。

我没有试过,但这应该是正确的顺序:

def connect_to_mac(self, mac_address: str):
addr = QtBluetooth.QBluetoothAddress(mac_address)
device = QtBluetooth.QBluetoothDeviceInfo(addr)
self.controller = QtBluetooth.QLowEnergyController.createCentral(device)
self.controller.connectToDevice()

最新更新