This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

re-init or resetting nrf52 dongle with pc-ble-driver-py

Hi,

I have a python program using an NRF52 dongle and its working great with the a minor detail that if the program crashes and does not get a chance to close the adapter, then it does not allow you to open it again until the dongle is unplugged and plugged back in.

I've tried opening and closing the device through the library and I've also tried using pyserial to do something similar, but in every case I get either "NordicSemiException: Failed to ble_enable. Error code: 3" or Error Code 13. once the device is power cycled, it works great.

Is there anyway to programmatically ensure that the device is reset when the program loads so that a physical action is not necessary?

Thanks,

Gabe

Parents
  • Using the comments from this thread I was able to come up with a solution that does not require modification of the pc-ble-driver-py library. For anyone else looking for an answer, here is my code snippet:

    def parametrizedDecorator(dec):
        def layer(*args, **kwargs):
            def repl(f):
                return dec(f, *args, **kwargs)
            return repl
        return layer
    
    @parametrizedDecorator
    def extendClass(func, c):
        setattr(c, func.__name__, func)
        return func
    
    from pc_ble_driver_py import config
    config.__conn_ic_id__ = "NRF52"
    from pc_ble_driver_py.ble_driver import NordicSemiErrorCheck
    from pc_ble_driver_py.ble_driver import driver
    
    @NordicSemiErrorCheck
    @wrapt.synchronized(BLEDriver.api_lock)
    @extendClass(BLEDriver)
    def reset(self, resetType=0):
        return driver.sd_rpc_conn_reset(self.rpc_adapter, resetType) 

    and to use it you should do something like this:

    def reset_function():
        driver = BLEDriver(serial_port=self.serial_port, auto_flash=False)
        adapter = BLEAdapter(driver)
        adapter.driver.reset(resetType)
        time.sleep(1)

Reply
  • Using the comments from this thread I was able to come up with a solution that does not require modification of the pc-ble-driver-py library. For anyone else looking for an answer, here is my code snippet:

    def parametrizedDecorator(dec):
        def layer(*args, **kwargs):
            def repl(f):
                return dec(f, *args, **kwargs)
            return repl
        return layer
    
    @parametrizedDecorator
    def extendClass(func, c):
        setattr(c, func.__name__, func)
        return func
    
    from pc_ble_driver_py import config
    config.__conn_ic_id__ = "NRF52"
    from pc_ble_driver_py.ble_driver import NordicSemiErrorCheck
    from pc_ble_driver_py.ble_driver import driver
    
    @NordicSemiErrorCheck
    @wrapt.synchronized(BLEDriver.api_lock)
    @extendClass(BLEDriver)
    def reset(self, resetType=0):
        return driver.sd_rpc_conn_reset(self.rpc_adapter, resetType) 

    and to use it you should do something like this:

    def reset_function():
        driver = BLEDriver(serial_port=self.serial_port, auto_flash=False)
        adapter = BLEAdapter(driver)
        adapter.driver.reset(resetType)
        time.sleep(1)

Children
No Data
Related