Page 1 of 1

Simultaneous Reading from Both Rx Channels with Python Script

Posted: Sat Feb 03, 2024 3:16 am
by Dm_Yarem
Greetings,

I'm currently delving into the realm of BladeRF SDR and I've been using the Python script provided in the BladeRF repository as a reference. Specifically, I'm referring to the script available at the following link: https://github.com/Nuand/bladeRF/blob/m ... rx/txrx.py

However, my focus is solely on receiving data at the moment, and thus, I have simplified the receiving function to better suit my needs. Here's the simplified function:

Code: Select all

def receive(device, channel : int, freq : int, rate : int, gain : int,
            rxfile : str = '', num_samples : int = 1024):

    status = 0

    if( device == None ):
        print( "RX: Invalid device handle." )
        return -1

    if( channel == None ):
        print( "RX: Invalid channel." )
        return -1

    # Configure BladeRF
    ch             = device.Channel(channel)
    ch.frequency   = freq
    ch.sample_rate = rate
    ch.gain        = gain

    # Setup synchronous stream
    device.sync_config(layout         = _bladerf.ChannelLayout.RX_X1,
                       fmt            = _bladerf.Format.SC16_Q11,
                       num_buffers    = 16,
                       buffer_size    = 8192,
                       num_transfers  = 8,
                       stream_timeout = 3500)

    # Enable module
    print( "RX: Start" )
    ch.enable = True

    # Create receive buffer
    bytes_per_sample = 4
    buf = bytearray(1024*bytes_per_sample)
    num_samples_read = 0

    # Save the samples
    with open(rxfile, 'wb') as outfile:
        while True:
            if num_samples > 0 and num_samples_read == num_samples:
                break
            elif num_samples > 0:
                num = min(len(buf)//bytes_per_sample,
                          num_samples-num_samples_read)
            else:
                num = len(buf)//bytes_per_sample

            # Read into buffer
            num = int(num)
            if num != 1024:
                print(num)
            device.sync_rx(buf, num)
            num_samples_read += num

            # Write to file
            outfile.write(buf[:num*bytes_per_sample])

    # Disable module
    print( "RX: Stop" )
    ch.enable = False

    print( "RX: Done" )

    return 0
My inquiry pertains to the possibility of simultaneously receiving data from both Rx channels. I've tinkered with various parameters, but unfortunately, I haven't been successful in achieving this.

Could you kindly provide me with any tips or advice on how to achieve simultaneous reading from both Rx channels using the Python script?

Thank you in advance for your assistance.

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Thu Feb 08, 2024 11:00 am
by doja
.

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Thu Mar 21, 2024 5:50 am
by Vidal Sauer
JavaScript and SQL are two powerful programming languages that play a crucial role in digital marketingslope game

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Mon Mar 25, 2024 8:56 pm
by ulnaoperating
There are two powerful programming languages that are used in the digital marketing slope game, and those languages are JavaScript and SQL.

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Sat May 04, 2024 7:52 pm
by felixandrea
Hello,

To read data from both Rx channels of the BladeRF SDR simultaneously, you can follow these steps:

Modify the receive() function to be able to read data from both Rx channels:

Add a new parameter channel2: int to the receive() function to represent the second Rx channel.
Create a separate read stream for the second Rx channel by copying and modifying some of the code from the first Rx channel read stream.
Ensure that the two read streams for the two Rx channels are running concurrently.
Example of how to update the receive() function:

def receive(device, channel1: int, channel2: int, freq: int, rate: int, gain: int,
rxfile1: str = '', rxfile2: str = '', num_samples: int = 1024):
status = 0

# Configure Rx channel 1
ch1 = device.Channel(channel1)
ch1.frequency = freq
ch1.sample_rate = rate
ch1.gain = gain

# Configure Rx channel 2
ch2 = device.Channel(channel2)
ch2.frequency = freq
ch2.sample_rate = rate
ch2.gain = gain

# Set up synchronous stream
device.sync_config(layout=_bladerf.ChannelLayout.RX_X2,
fmt=_bladerf.Format.SC16_Q11,
num_buffers=16,
buffer_size=8192,
num_transfers=8,
stream_timeout=3500)

# Enable modules
print("RX: Start")
ch1.enable = True
ch2.enable = True

# Create receive buffers
bytes_per_sample = 4
buf1 = bytearray(1024 * bytes_per_sample)
buf2 = bytearray(1024 * bytes_per_sample)
num_samples_read1 = 0
num_samples_read2 = 0

# Save the samples
with open(rxfile1, 'wb') as outfile1, open(rxfile2, 'wb') as outfile2:
while True:
if num_samples > 0 and num_samples_read1 == num_samples and num_samples_read2 == num_samples:
break

# Read data from Rx channel 1
num1 = min(len(buf1) // bytes_per_sample, num_samples - num_samples_read1)
device.sync_rx(buf1, num1, channel=channel1)
num_samples_read1 += num1
outfile1.write(buf1[:num1 * bytes_per_sample])

# Read data from Rx channel 2
num2 = min(len(buf2) // bytes_per_sample, num_samples - num_samples_read2)
device.sync_rx(buf2, num2, channel=channel2)
num_samples_read2 += num2
outfile2.write(buf2[:num2 * bytes_per_sample])

# Disable modules
print("RX: Stop")
ch1.enable = False
ch2.enable = False

print("RX: Done")
return 0
In this example, the receive() function has been updated to read data from both Rx channels. You need to provide two new parameters channel1 and channel2 to specify the Rx channels to read from. Additionally, two separate buffers buf1 and buf2 are created to store the data from the two Rx channels, and the data is written to two corresponding files rxfile1 and rxfile2. rice purity test

Please try using the updated receive() function and see if you can successfully read data from both Rx channels simultaneously.

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Tue May 07, 2024 2:32 am
by vaulthinds
Learning knowledge is greatgeometry dash lite. The website always responds to problems quickly. Thank you for this great information!

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Tue May 14, 2024 12:40 am
by frank20054
Where can I learn more about it?

Re: Simultaneous Reading from Both Rx Channels with Python Script

Posted: Tue Jun 18, 2024 6:58 pm
by chloebailey262
vaulthinds wrote: Tue May 07, 2024 2:32 am Learning knowledge is greatgeometry dash lite. The website always responds to problems quickly. Thank you for this great information! papa's games
Hello, Eric and pals I'm currently working on a project that calls for simultaneous TX and RX on a single USRPA board.