我想用PyQt或PySide连接到一个MAC地址( BLE dongle )。我知道我需要创建一个控制器和一个mac address对象,但不知怎么的,它不起作用。
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()发布于 2022-07-18 18:20:31
按正确的顺序做事。首先,将您的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()https://stackoverflow.com/questions/73008459
复制相似问题