-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectDeviceThread.py
46 lines (34 loc) · 1.22 KB
/
ConnectDeviceThread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import threading
import bluetooth
import Device
import json
from PyQt5.QtBluetooth import QBluetoothAddress, QBluetoothTransferRequest
from PyQt5.QtCore import pyqtSignal, QThread
class ConnectDeviceThread(QThread):
done = pyqtSignal()
error = pyqtSignal(int)
dongleNotFound = pyqtSignal()
NO_SERVICE_FOUND = 1001
device = None
retry = 4
def run(self):
self.device.updating = True
services = []
while len(services) is 0 and self.retry > 0:
services = bluetooth.find_service(address=self.device.host)
if len(services) > 0:
self.retry = 0
if len(services) is 0:
print('No services found for device, stop connect')
self.device.updating = False
self.error.emit(self.NO_SERVICE_FOUND)
self.done.emit()
return
a = json.dumps(services)
self.device.services = services
# If device not yet know it's manufacturer it's first connect
if len(self.device.vendor) == 0:
pnp_info_service = self.device.get_service_by_name('PnPInformation')
if pnp_info_service:
print('PnpService found')
self.device.updating = False