[英]Connecting to a MAC address with PyQt6
I would like to connect to a MAC address ( of a BLE dongle ) with PyQt or PySide.我想使用 PyQt 或 PySide 连接到 MAC 地址(BLE 加密狗)。 I know that I need to create a controller and a mac address object but somehow it does not work.
我知道我需要创建一个控制器和一个 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()
Do things in the right order.按正确的顺序做事。 First, convert your mac address to a
QBluetoothAddress
.首先,将您的 mac 地址转换为
QBluetoothAddress
。 Then, pass that to QBluetoothDeviceInfo
to create a device info structure.然后,将其传递给
QBluetoothDeviceInfo
以创建设备信息结构。 Then, pass that to createCentral
and connect to the device.然后,将其传递给
createCentral
并连接到设备。
I have not tried this, but this should be the right sequence:我没有尝试过,但这应该是正确的顺序:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.