-
i see the example of two device,but id did not happend. def conn_blue_devices(self,addresses):
tasks = []
for i,address in enumerate(addresses):
if i == 0:
task = asyncio.create_task(self.conn_blue_device(address))
tasks.append(task)
elif i == 1:
task2 = asyncio.create_task(self.conn_blue_device2(address))
tasks.append(task2)
asyncio.gather(*tasks)
async def conn_blue_device(self, address):
async with BleakClient(address, loop=self.main_window.loop) as self.ble_client:
x = await self.ble_client.is_connected()
logger.debug("Connected: {0}".format(x))
self.main_window.label_status_value.setText("已连接")
self.main_window.button_device_connect.setText("断开")
self.main_window.connect_setting_log.appendPlainText("connect success")
self.main_window.button_device_scan.setDisabled(True)
print("ok"+address)
await self.ble_client.start_notify(ble_service_uuid, self.notification_handler)
while 1:
await asyncio.sleep(0.001)
async def conn_blue_device2(self, address):
async with BleakClient(address, loop=self.main_window.loop) as self.ble_client2:
x = await self.ble_client2.is_connected()
logger.debug("Connected: {0}".format(x))
self.main_window.label_status_value.setText("已连接")
self.main_window.button_device_connect.setText("断开")
self.main_window.connect_setting_log.appendPlainText("connect success")
self.main_window.button_device_scan.setDisabled(True)
print("ok "+address)
await self.ble_client2.start_notify(ble_service_uuid, self.notification_handler2)
while 1:
await asyncio.sleep(0.001)
def notification_handler(self, sender, data):
if self.flag:
print("blue 1")
data_queue = DataQueue([None] * 525)
decode_queue = DecodeQueue()
try:
for b in data:
data_queue.en_queue(b)
decode_queue.decode_data(data_queue, self.main_window)
except GeneratorExit:
print("GeneratorExit")
def notification_handler2(self, sender, data):
if self.flag:
print("blue 2")
data_queue = DataQueue([None] * 525)
decode_queue = DecodeQueue()
try:
for b in data:
data_queue.en_queue(b)
decode_queue.decode_data(data_queue, self.main_window)
except GeneratorExit:
print("GeneratorExit")` |
Beta Was this translation helpful? Give feedback.
Answered by
tomuGo
May 21, 2021
Replies: 2 comments
-
At the beginning,i can receieve two device data,but a few seconds later,there is only one device data i can receieve. |
Beta Was this translation helpful? Give feedback.
0 replies
-
i found ,the later connected device will work a few second ,first device worked well. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hbldh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i found ,the later connected device will work a few second ,first device worked well.