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

pc-ble-driver-py more dongles

Hello I would like to use more dongles with pc-ble-driver-py. For example I want to create multiple advertisers and test that my DUT would see multiple advertisers. I tried to reuse your Advertiser.py example.

The script crashes when I try to open 2nd dongle (calling driver.open())

  • Is there a way how to use pc-ble-drive-py to connect multiple nRF51 dognles?
  • If not then are you planning to implement such a feature?
  • If yes when we can expect such a feature?
  • I also ran into this issue with another python tool, pynrfjprog. It also crashes on the .open() method call.To work around it I had to wrap into separate multiprocessing.Process instances. Perhaps it could work for your issue too.

  • I tried to use python threading.Thread and it did not help. Still getting crash on driver.open() even when it is in second thread (Exception in thread Thread-2:...). But even then it would be workaround. I would prefer to be able to run my test in one thread...

  • Here is a working example with two advertisers:

    import sys
    from multiprocessing import Condition, Lock
    from pc_ble_driver_py.ble_driver import BLEDriver, BLEDriverObserver, BLEAdvData, BLEEvtID
    import multiprocessing
    
    
    class TimeoutObserver(BLEDriverObserver):
        def __init__(self):
            self.cond = Condition(Lock())
    
        def on_gap_evt_timeout(self, ble_driver, conn_handle, src):
            with self.cond:
                self.cond.notify_all()
    
        def wait_for_timeout(self):
            with self.cond:
                self.cond.wait()
    
    
    def main(serial_port, name):
        print("Serial port used: {}".format(serial_port))
        driver      = BLEDriver(serial_port=serial_port)
        observer    = TimeoutObserver()
        adv_data    = BLEAdvData(complete_local_name=name)
    
        driver.observer_register(observer)
        driver.open()
        driver.ble_enable()
        driver.ble_gap_adv_data_set(adv_data)
        driver.ble_gap_adv_start()
        observer.wait_for_timeout()
    
        print("Closing")
        driver.close()
    
    if __name__ == "__main__":
        p1 = multiprocessing.Process(target=main, args=('COM45', 'adv1'))
        p2 = multiprocessing.Process(target=main, args=('COM46', 'adv2'))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
    
  • Thank you. I confirm it works. I did not notice you propose multiprocessing while I tried threading. But still are u planning to update driver to work in single process? For example when I use pyserial I control easily multiple serial devices from one thread...

Related