Failed to connect to BLED112 adapter with BGAPIBackend
haroldgohjc opened this issue · 0 comments
haroldgohjc commented
Hi all,
I have recently started a new project involving a BLE application. I got myself a BLED112 dongle and I am trying to get it to work on a Windows 10 64-bit PC. The version of pygatt I am using is 4.0.5.
I am getting an exception "pygatt.exceptions.NotConnectedError" every time I call adapter.connect(). I was looking at a very similar issue #240 and #118, unfortunately the solution did not seem to work in my case.
Any help that could point me in the right direction will be greatly appreciated. Thanks!
This is the code that results in the error:
import pygatt
import logging
logging.basicConfig()
logging.getLogger('pygatt').setLevel(logging.DEBUG)
adapter = pygatt.BGAPIBackend("COM12") #COM Port that BLED112 is on
adapter.start()
device = adapter.connect(address='60:a4:23:58:75:e4', address_type=pygatt.BLEAddressType.random) #MAC address of the BLED112
This is the log:
INFO:pygatt.backends.bgapi.bgapi:Initialized new BGAPI backend
INFO:pygatt.backends.bgapi.bgapi:Resetting and reconnecting to device for a clean environment
DEBUG:pygatt.backends.bgapi.bgapi:Opening connection to serial port (attempt 1)
DEBUG:pygatt.backends.bgapi.bgapi:Opening connection to serial port (attempt 1)
DEBUG:pygatt.backends.bgapi.bgapi:Failed to open serial port
Traceback (most recent call last):
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 174, in _open_serial_port
self._ser = serial.Serial(serial_port, baudrate=115200,
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialwin32.py", line 33, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialutil.py", line 244, in __init__
self.open()
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM12': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
DEBUG:pygatt.backends.bgapi.bgapi:Opening connection to serial port (attempt 2)
DEBUG:pygatt.backends.bgapi.bgapi:Failed to open serial port
Traceback (most recent call last):
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 174, in _open_serial_port
self._ser = serial.Serial(serial_port, baudrate=115200,
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialwin32.py", line 33, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialutil.py", line 244, in __init__
self.open()
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM12': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
DEBUG:pygatt.backends.bgapi.bgapi:Opening connection to serial port (attempt 3)
INFO:pygatt.backends.bgapi.bgapi:Running receiver
INFO:pygatt.backends.bgapi.bgapi:Disabling advertising
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.gap_set_mode: 58>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.gap_set_mode packet: Success
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.sm_set_bondable_mode: 51>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.sm_set_bondable_mode packet: Success
DEBUG:pygatt.backends.bgapi.bgapi:Stopping any outstanding GAP procedure
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.gap_end_procedure: 61>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.gap_end_procedure packet: Device in wrong state
INFO:pygatt.backends.bgapi.bgapi:Connecting to device at address 60:a4:23:58:75:e4 (timeout 5s)
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.sm_set_bondable_mode: 51>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.sm_set_bondable_mode packet: Success
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.gap_connect_direct: 60>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.gap_connect_direct packet: Success
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<EventPacketType.connection_status: 11>] within 5.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Expecting a response of one of [<ResponsePacketType.gap_end_procedure: 61>] within 1.000000s
DEBUG:pygatt.backends.bgapi.bgapi:Received a ResponsePacketType.gap_end_procedure packet: Success
Traceback (most recent call last):
File "c:\Users\user\Desktop\bleproj\testconnection.py", line 11, in <module>
device = adapter.connect(address='60:a4:23:58:75:e4', address_type=pygatt.BLEAddressType.random) #MAC address of the BLED112 dongle
File "C:\Users\user\Desktop\bleproj\venv\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 456, in connect
raise exc
pygatt.exceptions.NotConnectedError