Search code examples
usrpuhd

Addressing multiple B200 devices through the UHD API


I have 2 B210 radios on USB3 on a Windows 10 system using the UHD USRP C API latest release and Python 3.6 as the programming environment. I can "sort of" run them simultaneously in separate processes but would like to know if it is possible to run them in a single thread? How?

1 Happy to move to Linux if it makes things easier, I'm just more familiar with Windows.

2 "sort of" = I sometimes get errors which might be the two processes colliding somewhere down the stack.

The code below illustrates the race condition, sometimes one or both processes fail with error code 40 (UHD_ERROR_ASSERTION) or occasionally code 11 ( UHD_ERROR_KEY )

from ctypes import (windll, byref, c_void_p, c_char_p)
from multiprocessing import Process, current_process

def pread(argstring):
    # get handle for device
    usrp = c_void_p(0)  
    uhdapi = windll.uhd
    p_str=c_char_p(argstring.encode("UTF8"))
    errNo = uhdapi.uhd_usrp_make(byref(usrp),p_str) 
    if errNo != 0: 
        print("\r*****************************************************************")
        print("ERROR: ",errNo," IN: ",  current_process())
        print("=================================================================")
    if usrp.value != 0:
        uhdapi.uhd_usrp_free(byref(usrp))
    return

if __name__ == '__main__':
    while True:
        p2 = Process(target=pread, args=("",))
        p1 = Process(target=pread, args=("",))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        print("end")

Solution

  • Yes, you can have multiple multi_usrp handles.

    By the way, note that UHD is natively C++, and the C API is just a wrapper around that. It's designed for generating scripting interfaces like the Python thing you're using (don't know which interface between Python and the C API you're using – something self-written?).

    While it's possible, there's no good reason to call the recv and send functions from the same thread – most modern machines are multi-threaded, and you should make use of that. Real-time SDR is a CPU-intensive task and you should use all the CPU resources available to get data to and from the driver, as to avoid overflowing buffers.