Connection failure after multiple connect/disconnect cycles.
Opened this issue · 1 comments
borisw37 commented
Can't connect to device after numerous connect / disconnect cycles.
Windows 10
Python 3.8
Pygatt 4.0.5
Dongle BLED112
Code:
import pygatt
import time
def connect_show_devices():
adapter_timeout = 5
adapter = None
try:
adapter = pygatt.BGAPIBackend()
adapter.start()
except:
print("FAILURE")
if adapter:
devices = adapter.scan(run_as_root=True, timeout=adapter_timeout)
print(f"SCAN COMPLETE {adapter_timeout}s:")
print("SCAN FOUND:")
for device in devices:
print(f'Name:{device["name"]}, Address:{device["address"]}')
adapter.stop()
return
if __name__=='__main__':
i = 0
for i in range (300):
print(f"Iteration: {i}")
connect_show_devices()
time.sleep(1)
Error
INFO:pygatt.backends.bgapi.bgapi:Auto-detecting serial port for BLED112
DEBUG:pygatt.backends.bgapi.util:Found 1 serial USB devices
DEBUG:pygatt.backends.bgapi.util:Checking serial USB device: COM3 - Bluegiga Bluetooth Low Energy (COM3)
DEBUG:pygatt.backends.bgapi.util:USB device: Bluegiga Bluetooth Low Energy (COM3) VID=0x2458 PID=0x0001 on COM3
INFO:pygatt.backends.bgapi.bgapi:Found BLED112 on serial port COM3
DEBUG:pygatt.backends.bgapi.bgapi:Failed to open serial port
Traceback (most recent call last):
File "C:\code\64bit\venv2\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 174, in _open_serial_port
self._ser = serial.Serial(serial_port, baudrate=115200,
File "C:\code\64bit\venv2\lib\site-packages\serial\serialwin32.py", line 31, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\code\64bit\venv2\lib\site-packages\serial\serialutil.py", line 240, in __init__
self.open()
File "C:\code\64bit\venv2\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
WARNING:pygatt.backends.bgapi.bgapi:Unexpectedly not connected to USB device
Traceback (most recent call last):
File "C:/code/64bit/test_BLED112_failure.py", line 45, in <module>
connect_show_devices()
File "C:/code/64bit/test_BLED112_failure.py", line 37, in connect_show_devices
scan_bt(adapter, adapter_timeout)
File "C:/code/64bit/test_BLED112_failure.py", line 18, in scan_bt
devices = adapter.scan(run_as_root=True, timeout=adapter_timeout)
File "C:\code\64bit\venv2\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 340, in scan
self.send_command(
File "C:\code\64bit\venv2\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 283, in send_command
raise NotConnectedError()
pygatt.exceptions.NotConnectedError
Current resolution
Go to device manager, find the Bluegiga device (with failure exclamation icon). Disable / re-enable the device.
Device status in device manager
This device cannot start. (Code 10)
{Operation Failed}
The requested operation was unsuccessful.
peplin commented
The error message is interesting:
The system cannot find the file specified
When this happens, has the BLED device been detected under a new name?