尝试在c++中创建USRP对象时分配错误

Bad Allocation while trying to create USRP Object in c++

本文关键字:对象 分配 错误 USRP 创建 c++      更新时间:2023-10-16

在使用UHD库时,我收到一个错误-"分配错误"。

我正在尝试编译一些基本代码,以了解更多关于UHD库的信息。编译完程序后,我出现了一个错误。

代码:

int UHD_SAFE_MAIN(int argc, char *argv[]) {
uhd::set_thread_priority_safe();
std::string device_args("addr=192.168.10.2");
std::string subdev("A:0");
std::string ant("TX/RX");
std::string ref("internal");
double rate(1e6);
double freq(915e6);
double gain(10);
double bw(1e6);
//create a usrp device
std::cout << std::endl;
std::cout << boost::format("Creating the usrp device with: %s...") %device_args << std::endl;
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(device_args);

// Lock mboard clocks
std::cout << boost::format("Lock mboard clocks: %f") % ref << std::endl;
usrp->set_clock_source(ref);
//always select the subdevice first, the channel mapping affects the other settings
std::cout << boost::format("subdev set to: %f") % subdev << std::endl;
usrp->set_rx_subdev_spec(subdev);
std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
//set the sample rate
if (rate <= 0.0) {
std::cerr << "Please specify a valid sample rate" << std::endl;
return ~0;
}
// set sample rate
std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl;
usrp->set_rx_rate(rate);
std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate() / 1e6) << std::endl << std::endl;
// set freq
std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq / 1e6) << std::endl;
uhd::tune_request_t tune_request(freq);
usrp->set_rx_freq(tune_request);
std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq() / 1e6) << std::endl << std::endl;
// set the rf gain
std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl;
usrp->set_rx_gain(gain);
std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl;
// set the IF filter bandwidth
std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw / 1e6) << std::endl;
usrp->set_rx_bandwidth(bw);
std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth() / 1e6) << std::endl << std::endl;
// set the antenna
std::cout << boost::format("Setting RX Antenna: %s") % ant << std::endl;
usrp->set_rx_antenna(ant);
std::cout << boost::format("Actual RX Antenna: %s") % usrp->get_rx_antenna() << std::endl << std::endl;
return EXIT_SUCCESS;

}

发生错误的代码部分:

//create a usrp device
std::cout << std::endl;
std::cout << boost::format("Creating the usrp device with: %s...") %device_args << std::endl;
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(device_args);

错误:在此处输入图像描述

我正在使用:

  • Microsoft Visual C++学习版2010
  • C++语言
  • UHD库,Win32_VS2010.exe,003.007.003-release
  • 提升库1_63_0
  • 我没有将任何URSP设备连接到我的计算机

我不知道这个错误是与UHD库有关还是与C++语言有关。我试图使用不同版本的Microsoft Visual Studio和不同版本的UHD库(包括最新版本)编译这个程序。我甚至试图在不同的电脑上编译这个,但结果是相似的,没有出现中断程序的错误,但我在控制台中得到了字符串"error:分配错误",程序在同一个位置停止了工作。

当我第一次开始编译这个程序时,我没有遇到"错误的分配错误"(UHD_003.004.000-发布)。我收到一个错误,上面写着-">错误:LookupError:KeyError:No device found for----->。在那之后,我决定将我的UHD库版本升级到较新的版本(003.007.003),然后坏分配错误开始发生。我试图安装回以前的版本,但没有帮助。

我试图将device_args的类型字符串更改为uhd::device_addr_t,就像在http://files.ettus.com/manual,但错误并没有消失。

如有任何帮助,我们将不胜感激。

"我没有将任何URSP设备连接到我的计算机。">

如果没有USRP连接到运行它的计算机,你就无法执行此代码。

当您调用uhd::usrp::multi_usrp::make(device_args)时;uhd正试图使用您在设备args中指定的IP地址连接到USRP。

尝试将usrp连接到您的计算机,然后重试