Post Go back to editing

rf_port_select does not work

Category: Software
Product Number: iiolib

Good morning

for this

ret = iio_channel_attr_write(phy_chn_rx, "rf_port_select", rxcfg.rfport);

I get a -22

Other settings for the rx channel work

The 

 phy_chn_rx = iio_device_find_channel(phydev, "voltage0", false );

gives the channel for rx. This one works.

Additionally is of value to assign settings to altvoltage0 or altvoltage1 for the PLUTO?
It seems they are not available ...

Thank You

Pietro

Parents Reply Children
  • Hi 

    Thank You for the assistance. I will follow the indication.
    I have further questions.
    I want to reread the attribute.
    A list of what happens:
    1. iio_channel_attr_read( phy_chn_tx, "rf_port_select", (char*)txcfg.rfport, 10 )  -> -10014
    2. iio_channel_attr_read_longlong( phy_chn_tx, "rf_bandwidth", &txcfg.bw_hz ); -> -22
    3. iio_channel_attr_read_longlong( phy_chn_tx, "sampling_frequency", &txcfg.fs_hz ); -> 0
    4. iio_channel_attr_read_double(   phy_chn_tx, "hardwaregain", &txcfg.gain_db ); -> 0 but gain = 2600000
    5. iio_channel_attr_read_longlong( phy_chn_tx, "frequency", &txcfg.lo_hz); -> -2
    6. iio_channel_attr_read(          phy_chn_rx, "rf_port_select", (char*)rxcfg.rfport, 10 ); -> -5
    7. iio_channel_attr_read_longlong( phy_chn_rx, "rf_bandwidth", &rxcfg.bw_hz ); -> -10053
    8. iio_channel_attr_read_longlong( phy_chn_rx, "sampling_frequency", &rxcfg.fs_hz ); -> -10053
    9. iio_channel_attr_read_double(   phy_chn_rx, "hardwaregain", &rxcfg.gain_db ); -> -10053
    10. iio_channel_attr_read_longlong( phy_chn_rx, "frequency", &rxcfg.lo_hz); -> -2


    The attributes were written previously with return code 0.
    I suppose I should reread the same values. What happens?
    Where are the return codes ?
    Thank You

    Pietro

  • Attribute values written may have different read values if the value is not possible. If you want to get the return code look at the doc for each function you call: http://analogdevicesinc.github.io/libiio/v0.24/libiio/index.html

    -Travis

  • Hi Travis

    Thank You
    I suppose if the value is different simply I get the value but not the error.
    Can You tell me which file to open for reading the error codes?

    Thank You

    Pietro

  • Hi

    I just tested the iio_strerror()
    For all of the codes I have Unlnown error..
    Just help
    Than You

    Pietro

  • Can you provide the specific libiio function and error code?

    -Travis

  • Good morning Travis,

    It seems there is no way to attach  files.
    I dump here the source. Sorry it is long..

    The setup of the pluto is here. The calls to the IIO_LIB are prepended with a IIO_lib_itf.
    I use wxSidgets and the DLL functions are loaded in a data stracture.

    // ctx = IIO_lib_itf.iio_create_default_context();
    ctx = IIO_lib_itf.iio_create_network_context("pluto.local");
    if (ctx == NULL)
    {
    char buf[1024];
    char str[1400];
    wxString String;
    IIO_lib_itf.iio_strerror(errno, buf, sizeof(buf));
    sprintf( str, "Failed creating IIO context: %s", buf);

    ListBox->AppendString(wxString(str));
    return;
    }
    else
    {
    ListBox->AppendString( " IIO context created" );
    }
    scan_ctx = IIO_lib_itf.iio_create_scan_context( NULL, 0 );
    if (scan_ctx) {
    int info_count = IIO_lib_itf.iio_scan_context_get_info_list( scan_ctx, &info );
    if (info_count > 0) {

    char *buf = (char *)IIO_lib_itf.iio_context_info_get_description( info[ 0 ] );
    sprintf(str, "* Found %s", buf);
    ListBox->AppendString( wxString( str ) );
    IIO_lib_itf.iio_context_info_list_free(info);
    }
    IIO_lib_itf.iio_scan_context_destroy( scan_ctx );
    scan_ctx = NULL;
    }

    ListBox->AppendString("* Acquiring devices\n");

    device_count = IIO_lib_itf.iio_context_get_devices_count( ctx );
    if (!device_count) {
    ListBox->AppendString( "No supported PLUTOSDR devices found");
    return;
    }

    sprintf(str, "* Context has %d device(s).\n", device_count );

    ListBox->AppendString( wxString(str) );

    ListBox->AppendString("* Acquiring TX device");
    tx = IIO_lib_itf.iio_context_find_device( ctx, "cf-ad9361-dds-core-lpc" );
    if (tx == NULL) {
    char buf[ 1024 ];
    IIO_lib_itf.iio_strerror(errno, buf, sizeof( buf ) );
    sprintf( str, "Error opening PLUTOSDR TX device: %s", buf );
    ListBox->AppendString( wxString( str ) );
    return;
    }
    else
    {
    ListBox->AppendString( wxString( "PLUTOSDR TX device open" ) );
    }
    IIO_lib_itf.iio_device_set_kernel_buffers_count(tx, 8);

    phydev = IIO_lib_itf.iio_context_find_device(ctx, "ad9361-phy");
    if ( phydev != NULL )
    {
    phy_chn_tx = IIO_lib_itf.iio_device_find_channel(phydev, "voltage0", true);
    if (phy_chn_tx == NULL)
    {
    ListBox->AppendString(wxString("voltage0 channel for TX NOT found"));
    return;
    }
    }
    else
    {
    ListBox->AppendString( wxString( "ad9361-phy dev for TX NOT found" ) );
    return;
    }
    ssize_t ret;
    /*
    ret = IIO_lib_itf.iio_channel_attr_write(phy_chn_tx, "rf_port_select", txcfg.rfport );
    if( ret < 0 )
    {
    ListBox->AppendString( wxString( "rf_port_select attribute for TX NOT written" ) );
    return;
    }
    */
    ret = IIO_lib_itf.iio_channel_attr_write_longlong(phy_chn_tx, "rf_bandwidth", txcfg.bw_hz );
    if (ret < 0)
    {
    ListBox->AppendString( wxString("rf_bandwidth attribute for TX NOT written"));
    return;
    }
    ret = IIO_lib_itf.iio_channel_attr_write_longlong( phy_chn_tx, "sampling_frequency", txcfg.fs_hz );
    if (ret < 0)
    {
    ListBox->AppendString( wxString("sampling_frequency attribute for TX NOT written"));
    return;
    }
    ret = IIO_lib_itf.iio_channel_attr_write_double( phy_chn_tx, "hardwaregain", txcfg.gain_db );
    if (ret < 0)
    {
    ListBox->AppendString( wxString( "hardwaregain attribute for TX NOT written" ) );
    return;
    }

    phy_chn_rx = IIO_lib_itf.iio_device_find_channel(phydev, "voltage0", false );
    if (phy_chn_rx == NULL)
    {
    ListBox->AppendString( wxString( "voltage0 channel for RX NOT found"));
    return;
    }

    /*
    ret = IIO_lib_itf.iio_channel_attr_write(phy_chn_rx, "rf_port_select", rxcfg.rfport);

    if (ret < 0)
    {
    ListBox->AppendString(wxString("rf_port_select attribute for RX NOT written"));
    return;
    }
    */

    ret = IIO_lib_itf.iio_channel_attr_write_longlong(phy_chn_rx, "rf_bandwidth", rxcfg.bw_hz);
    if (ret < 0)
    {
    ListBox->AppendString( wxString( "rf_bandwidth attribute for RX NOT written" ) );
    return;
    }
    ret = IIO_lib_itf.iio_channel_attr_write_longlong(phy_chn_rx, "sampling_frequency", rxcfg.fs_hz );
    if (ret < 0)
    {
    ListBox->AppendString(wxString( "sampling_frequency attribute for RX NOT written" ) );
    return;
    }
    ret = IIO_lib_itf.iio_channel_attr_write_double( phy_chn_rx, "hardwaregain", rxcfg.gain_db );
    if (ret < 0)
    {
    ListBox->AppendString(wxString("hardwaregain attribute for RX NOT written"));
    return;
    }

    ret = IIO_lib_itf.iio_channel_attr_write_bool(
    IIO_lib_itf.iio_device_find_channel(phydev, "altvoltage0", true)
    , "powerdown", true ); // Turn OFF RX LO
    if (ret < 0)
    {
    ListBox->AppendString( wxString("powerdown attribute on avoltage0 NOT written") );
    return;
    }

    ret = IIO_lib_itf.iio_channel_attr_write_longlong(
    IIO_lib_itf.iio_device_find_channel(phydev, "altvoltage1", true)
    , "frequency", txcfg.lo_hz ); // Set TX LO frequency
    if (ret < 0)
    {
    ListBox->AppendString(wxString("frequency attribute on avoltage1 NOT written"));
    return;
    }

    ListBox->AppendString( "* Initializing streaming channels" );

    tx0_i = IIO_lib_itf.iio_device_find_channel(tx, "voltage0", true);
    if (!tx0_i)
    {
    ListBox->AppendString(wxString("Tx0_i buffer NOT found"));
    return;ReadAllPlutoSettings

    }
    // tx0_i = IIO_lib_itf.iio_device_find_channel(tx, "altvoltage0", true);

    tx0_q = IIO_lib_itf.iio_device_find_channel(tx, "voltage1", true);
    if (!tx0_q)
    {
    ListBox->AppendString(wxString("Tx0_q buffer NOT found"));
    return;

    }
    // tx0_q = IIO_lib_itf.iio_device_find_channel(tx, "altvoltage1", true);

    ListBox->AppendString( "* Enabling IIO streaming channels\n" );
    IIO_lib_itf.iio_channel_enable(tx0_i);
    IIO_lib_itf.iio_channel_enable(tx0_q);

    int iret = AD9361_lib_itf.ad9361_set_bb_rate(IIO_lib_itf.iio_context_find_device(ctx, "ad9361-phy"), txcfg.fs_hz);
    if ( iret < 0 )
    {
    ListBox->AppendString( wxString( "ad9361-phy bb rate NOT written" ) );
    return;
    }

    ListBox->AppendString( "* Creating TX buffer" );

    tx_buffer = IIO_lib_itf.iio_device_create_buffer( tx, NUM_SAMPLES, false );
    if ( !tx_buffer ) {
    ListBox->AppendString( "Could not create TX buffer." );
    return;
    }

    // ntx = 0;
    iret = IIO_lib_itf.iio_channel_attr_write_bool(
    IIO_lib_itf.iio_device_find_channel( IIO_lib_itf.iio_context_find_device(ctx, "ad9361-phy"), "altvoltage1", true )
    , "powerdown", false); // Turn ON TX LO
    if (iret < 0)
    {
    ListBox->AppendString(wxString("altvoltage1 powerdown NOT written"));
    return;
    }

    ptx_buffer = (short*)IIO_lib_itf.iio_buffer_start(tx_buffer);
    ListBox->AppendString("* Transmit starts...\n");
    PlutoInitDone = true;

    ListBox->AppendString(" ");
    ListBox->AppendString(" ");

    ReadAllPlutoSettings( &txcfg, &rxcfg );

    //////     The ReadAllPlutoSettings(...) reread all of the settings. It is here  ///////////

    void CPlutoDlg::ReadAllPlutoSettings( struct stream_cfg * p_txcfg, struct stream_cfg * p_rxcfg )
    {
    // IIO_lib_itf.iio_device_find_channel( phydev, "voltage0", true);

    char buf[200];

    ssize_t sz = IIO_lib_itf.iio_channel_attr_read( phy_chn_tx, "rf_port_select", (char*)txcfg.rfport, 10 );
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror( sz, buf, 200 );
    ListBox->AppendString(wxString( buf ));
    // ListBox->AppendString(wxString("rf port TX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_tx, "rf_bandwidth", &txcfg.bw_hz );
    if (sz != 0)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString( wxString( "rf_bandwidth TX not correctly read " ) );
    }

    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_tx, "sampling_frequency", &txcfg.fs_hz );
    if (sz != 0)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString( wxString( "sampling_frequency TX not correctly read " ) );
    }

    sz = IIO_lib_itf.iio_channel_attr_read_double( phy_chn_tx, "hardwaregain", &txcfg.gain_db );
    if (sz != 0)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("hardwaregain TX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_tx, "frequency", &txcfg.lo_hz);
    if (sz != 0)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("frequency TX not correctly read "));
    }


    sz = IIO_lib_itf.iio_channel_attr_read( phy_chn_rx, "rf_port_select", (char*)rxcfg.rfport, 10 );
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("rf port RX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_rx, "rf_bandwidth", &rxcfg.bw_hz );
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("rf_bandwidth RX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_rx, "sampling_frequency", &rxcfg.fs_hz );
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("sampling_frequency RX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_double( phy_chn_rx, "hardwaregain", &rxcfg.gain_db );
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("hardwaregain RX not correctly read "));
    }
    sz = IIO_lib_itf.iio_channel_attr_read_longlong( phy_chn_rx, "frequency", &rxcfg.lo_hz);
    if (sz != 1)
    {
    IIO_lib_itf.iio_strerror(sz, buf, 200);
    ListBox->AppendString(wxString(buf));
    // ListBox->AppendString(wxString("frequency RX not correctly read "));
    }

    }

    Not one of the readout is correct,  

    Thank You

    Pietro

  • Can you provide a simple example in just C?

    -Travis

  • Hi Travis

    The initialization appears correct ..
    The readout is totally out of order.

    printf("* Initializing streaming channels\n");
    tx0_i = iio_device_find_channel(tx, "voltage0", true);
    if (!tx0_i)
    tx0_i = iio_device_find_channel(tx, "altvoltage0", true);

    tx0_q = iio_device_find_channel(tx, "voltage1", true);
    if (!tx0_q)
    tx0_q = iio_device_find_channel(tx, "altvoltage1", true);

    // Up to here it is correct

    // Now I want to read and nothing works

    struct stream_cfg txcfg_read;


    {
    txcfg_read.rfport = " ";
    txcfg_read.bw_hz = 0;
    txcfg_read.fs_hz = 0;
    txcfg_read.gain_db = 0;
    sz = iio_channel_attr_read(tx0_i, "rf_port_select", (char*)txcfg_read.rfport, 10);
    int err2 = iio_channel_attr_read_longlong(tx0_i, "rf_bandwidth", &txcfg_read.bw_hz);
    err2 = iio_channel_attr_read_longlong(tx0_i, "sampling_frequency", &txcfg_read.fs_hz);
    err2 = iio_channel_attr_read_double(tx0_i, "hardwaregain", &txcfg_read.gain_db);
    }

    Thank     You

    Pietro

  • It looks like you reading channels from the wrong device.

    For Pluto there are 3 relevant IIO devices...

    Can you start with the iio_info command?

  • Is this the outcome?

    This example is working for streaming it does the initialization without any problem. I just add the lines of code for reading what is already written. 

    Can You modify the example for streaming and show this  API work?

    Thank You

    Pietro