USRP Software Radio

cancel
Showing results for 
Search instead for 
Did you mean: 

USRP B200 Receiver thread Error

Hello. I was searching about the 

I would like to make a receiver by using usrp b200 and python(the final goal will be making a video streamer).

Here I have made the following codes. But I keep on getting the error/bug. When I run the code, the GUI(I made it), and by clicking the usrp configuration button, the usrp starts configuring and successfully finishes the job. On the next, I made a rx thread to receive the signal but when I run it, it only receives 70 times and the kernel processor excites and turns off.


I am so stuck on this task and asking StackExchange to consider this problem.

When I debugged, I found which line of the code was not working properly.
```
self.rx_streamer.recv(self.recv_buffer, self.rx_metadata)
```
This code does not work properly.

Also could anyone explain to me about the metadata. I am trying to debug where the issue has occurred by printing the rx_metadata from the rx_func thread.

Another question is whether the usrp b200 has the internal counter which counts the amount of buffer received?

It is the full code:

```
import sys
import numpy as np
import uhd
import threading
from PyQt5.QtWidgets import QApplication
import genWifi6, genDvbt2, wifi6_detect, dvbt2_detect, genTx
import matplotlib.pyplot as plt
import scipy.signal as sg
import time
from functions import *

# Import the GUI file
from gui import MyWindow, UI_class, GraphWindow

# basic info
Nwifi6 = 2000
Nwifi6_buffer = Nwifi6*2
Ndvbt2 = 8960
Ndvbt2_9M143Hz = 4096
Ndvbt2_buffer = 20000
Ndvbt2_9M143Hz_buffer = 9120    # 9975*2*16/35
# rx buffer (USRP buffer)
Nrx_buffer = Nwifi6         # rx buffer is based on wifi6

# Create an instance of the GUI application
class GenTx(MyWindow):
    def __init__(self):
        global loopidx, rxbuffer
        # Call the super constructor
        super().__init__()
        randseq = np.load("randomSeq.npz")
        self.seq_wifi6 = randseq['seq_wifi6']
        self.seq_dvbt2 = randseq['seq_dvbt2']
        self.rx_flag = False
        self.usrp_configured = False
        self.usrp_flag = True
        self.loopidx = None
        self.rxbuffer = None
        self.count = 0


    def rx_func(self):
        print(self.rx_metadata)
        samples = np.zeros(self.num_samps, dtype=np.complex64)
        while self.rx_flag == True:
            if not self.usrp_configured:
                time.sleep(1)
                continue
            self.rx_streamer.recv(self.recv_buffer, self.rx_metadata)
            samples[:2000] = self.recv_buffer[0]
            self.count +=1
            print(self.count)
            time.sleep(0.1)
        print(len(samples))
        print(samples[0:10])


    def usrpConfig(self):
        # global recv_buffer, rx_metadata
        # usrp = uhd.usrp.MultiUSRP()

        Fs = 20e6  # 20MHz sampling rate
        rf_freq = 2.62e9  # 2.62GHz carrier frequency
        tx_channel = 0
        txGain = 10  # dB
        rx_channel = 0
        rxGain = 10  # dB
        dev = uhd.libpyuhd.types.device_addr()
        myusrp = uhd.usrp.MultiUSRP(dev)
        self.num_samps = 2000

        myusrp.set_rx_antenna("RX2")
        myusrp.set_rx_rate(Fs)
        myusrp.set_rx_bandwidth(Fs)
        myusrp.set_rx_freq(uhd.libpyuhd.types.tune_request(rf_freq), rx_channel)
        myusrp.set_rx_gain(rxGain)
        rxDur = 4  # sec
        spp = 2000  # based on wifi6 spec

        # Set up the stream and receive buffer
        rxstream_args = uhd.usrp.StreamArgs('fc32', 'sc16')
        rxstream_args.args = f'spp={spp}'  # samples per packet
        rxstream_args.channels = [rx_channel]
        self.rx_streamer = myusrp.get_rx_stream(rxstream_args)
        self.recv_buffer = np.zeros((1, 2000), dtype=np.complex64)


        # Start Stream
        self.rx_metadata = uhd.types.RXMetadata()
        stream_cmd = uhd.types.StreamCMD(uhd.types.StreamMode.start_cont)
        stream_cmd.stream_now = True
        self.rx_streamer.issue_stream_cmd(stream_cmd)
        print("Finished Configuration")
        self.rx_flag = True
        self.usrp_configured = True


    def turnOnOffUSRP(self):
        if self.usrp_flag == True:
            self.RxThread = threading.Thread(target=self.rx_func)
            self.RxThread.start()
            self.usrp_flag = False
            self.turnOnOffUSRPButton.setText('Turn Off')
        else :
            self.rx_flag = False
            self.RxThread.join()  # Wait for the RxThread to finish
            self.RxThread = None
            self.usrp_flag = True
            self.turnOnOffUSRPButton.setText('Turn On')


if __name__ == '__main__':
    # basic info
    Nwifi6 = 2000
    Nwifi6_buffer = Nwifi6*2
    Ndvbt2 = 8960
    Ndvbt2_9M143Hz = 4096
    Ndvbt2_buffer = 20000
    Ndvbt2_9M143Hz_buffer = 9120    # 9975*2*16/35
    # rx buffer (USRP buffer)
    Nrx_buffer = Nwifi6         # rx buffer is based on wifi6
    # Start the GUI event loop
    app = QApplication(sys.argv)
    window = GenTx()
    window.show()
    sys.exit(app.exec_())
```

0 Kudos
Message 1 of 1
(1,206 Views)