[USRP-users] problems with UHD and Visual Studio Express 2013

massimo zampetti massimo.zampetti at leonardo-si.it
Wed Oct 22 07:01:50 EDT 2014


Dear Sir,
I'm writing to you regarding a problem with uhd.
I have an *Ettus B200* connected to the *USB 3.0* port (*Intel Z7*7) of 
my PC.
The main features of my PC are:
- motherboard: *ASRock Z77 Extreme 11*.
- operating system: *Microsoft Windows 7 (64 bit)*.

I downloaded the UHD software installer from 
http://code.ettus.com/redmine/ettus/projects/uhd/wiki/UHD_Windows: 
*uhd-stable-debug_Win64.exe*.

I tried to execute *uhd_find_devices* (UHD\bin) and *uhd_usrp_proble* 
(UHD\bin) and both worked successfully.
Then I created a simple GNURadio project and also in this case it worked 
without any problem.

Now I'm using *Visual Studio Express 2013* and I'm trying to modify the 
code of '*tx_waveforms.exe*' (UHD\lib\uhd\utils). I'm trying to do this 
because I want to learn how can I write C++ code to communicate with my 
ETTUS B200.

I installed boost (1.56) libraries on my PC and I set all required paths 
in the project properties.
I tried to run the project but it crashed. So I commented all lines of 
the code and I tried to uncomment line by line to find instruction that 
causes the error.

In attachment there is the code.
If I uncomment line 110 (*uhd::usrp::multi_usrp::sptr usrp = 
uhd::usrp::multi_usrp::make(args);*), there's no problem with the 
compiler but if I run debug I obtain the following error:



First of all, the path doesn't exist. 'xstring' is in the directory 
'Microsoft Visual Studio *12.0*\VC\include'. In any case it seems that 
xstring is found but something in it that crashes the program.

I'm looking for this error on internet but I don't find a solution.

Would you send me any suggestions to solve my problem?

Thank you for your help
Yours sincerely

Massimo Zampetti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20141022/553446ce/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 19142 bytes
Desc: not available
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20141022/553446ce/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 26610 bytes
Desc: not available
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20141022/553446ce/attachment-0001.png>
-------------- next part --------------
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/exception.hpp>

#include <boost/program_options.hpp>
#include <boost/math/special_functions/round.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>

#include <iostream>
#include <complex>
#include <csignal>
#include <cmath>
namespace po = boost::program_options;
/***********************************************************************
* Signal handlers
**********************************************************************/
static bool stop_signal_called = false;
void sig_int_handler(int){stop_signal_called = true;}
/***********************************************************************
* Waveform generators
**********************************************************************/
static const size_t wave_table_len = 8192;
class wave_table_class{
public:
wave_table_class(const std::string &wave_type, const float ampl):
_wave_table(wave_table_len)
{
//compute real wave table with 1.0 amplitude
std::vector<double> real_wave_table(wave_table_len);
if (wave_type == "CONST"){
for (size_t i = 0; i < wave_table_len; i++)
real_wave_table[i] = 1.0;
}
else if (wave_type == "SQUARE"){
for (size_t i = 0; i < wave_table_len; i++)
real_wave_table[i] = (i < wave_table_len/2)? 0.0 : 1.0;
}
else if (wave_type == "RAMP"){
for (size_t i = 0; i < wave_table_len; i++)
real_wave_table[i] = 2.0*i/(wave_table_len-1) - 1.0;
}
else if (wave_type == "SINE"){
static const double tau = 2*std::acos(-1.0);
for (size_t i = 0; i < wave_table_len; i++)
real_wave_table[i] = std::sin((tau*i)/wave_table_len);
}
else throw std::runtime_error("unknown waveform type: " + wave_type);
//compute i and q pairs with 90% offset and scale to amplitude
for (size_t i = 0; i < wave_table_len; i++){
const size_t q = (i+(3*wave_table_len)/4)%wave_table_len;
_wave_table[i] = std::complex<float>(ampl*real_wave_table[i], ampl*real_wave_table[q]);
}
}
inline std::complex<float> operator()(const size_t index) const{
return _wave_table[index % wave_table_len];
}
private:
std::vector<std::complex<float> > _wave_table;
};
/***********************************************************************
* Main function
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[])
{
	uhd::set_thread_priority_safe();
	//variables to be set by po
	std::string args, wave_type, ant, subdev, ref, otw, channel_list;
	size_t spb;
	double rate, freq, gain, wave_freq, bw;
	float ampl;
	//setup the program options
	po::options_description desc("Allowed options");
	desc.add_options()
	("help", "help message")
	("args", po::value<std::string>(&args)->default_value(""), "single uhd device address args")
	("spb", po::value<size_t>(&spb)->default_value(0), "samples per buffer, 0 for default")
	("rate", po::value<double>(&rate), "rate of outgoing samples")
	("freq", po::value<double>(&freq), "RF center frequency in Hz")
	("ampl", po::value<float>(&ampl)->default_value(float(0.3)), "amplitude of the waveform [0 to 0.7]")
	("gain", po::value<double>(&gain), "gain for the RF chain")
	("ant", po::value<std::string>(&ant), "daughterboard antenna selection")
	("subdev", po::value<std::string>(&subdev), "daughterboard subdevice specification")
	("bw", po::value<double>(&bw), "daughterboard IF filter bandwidth in Hz")
	("wave-type", po::value<std::string>(&wave_type)->default_value("CONST"), "waveform type (CONST, SQUARE, RAMP, SINE)")
	("wave-freq", po::value<double>(&wave_freq)->default_value(0), "waveform frequency in Hz")
	("ref", po::value<std::string>(&ref)->default_value("internal"), "clock reference (internal, external, mimo)")
	("otw", po::value<std::string>(&otw)->default_value("sc16"), "specify the over-the-wire sample mode")
	("channels", po::value<std::string>(&channel_list)->default_value("0"), "which channels to use (specify \"0\", \"1\", \"0,1\", etc)")
	("int-n", "tune USRP with integer-N tuning")
	;
	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
	//print the help message
	if (vm.count("help"))
	{
		std::cout << boost::format("UHD TX Waveforms %s") % desc << std::endl;
		return ~0;
	}
	//create a usrp device
	std::cout << std::endl;
	std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl;

	uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);
	////detect which channels to use
	//std::vector<std::string> channel_strings;
	//std::vector<size_t> channel_nums;
	//boost::split(channel_strings, channel_list, boost::is_any_of("\"',"));
	//for(size_t ch = 0; ch < channel_strings.size(); ch++)
	//{
	//	size_t chan = boost::lexical_cast<int>(channel_strings[ch]);

	//	if(chan >= usrp->get_tx_num_channels()) 
	//	throw std::runtime_error("Invalid channel(s) specified."); 
	//	else
	//		channel_nums.push_back(boost::lexical_cast<int>(channel_strings[ch]));
	//} 
	//	
	////Lock mboard clocks
	//usrp->set_clock_source(ref);
	////always select the subdevice first, the channel mapping affects the other settings
	//if (vm.count("subdev")) usrp->set_tx_subdev_spec(subdev); 
	//std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; 
	//
	//	//set the sample rate
	//if (not vm.count("rate"))
	//{
	//	std::cerr << "Please specify the sample rate with --rate" << std::endl;
	//	return ~0;
	//}
	//std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate/1e6) << std::endl;
	////usrp->set_tx_rate(rate); //sm
	////std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; //sm
	////set the center frequency
	//if (not vm.count("freq"))
	//{
	//	std::cerr << "Please specify the center frequency with --freq" << std::endl;
	//	return ~0;
	//}
	//
	//for(size_t ch = 0; ch < channel_nums.size(); ch++) 
	//{
	//	std::cout << boost::format("Setting TX Freq: %f MHz...") % (freq/1e6) << std::endl;
	//	//uhd::tune_request_t tune_request(freq); //sm
	//	//if(vm.count("int-n")) tune_request.args = uhd::device_addr_t("mode_n=integer"); //sm
	//	//usrp->set_tx_freq(tune_request, channel_nums[ch]); //sm
	//	//std::cout << boost::format("Actual TX Freq: %f MHz...") % (usrp->get_tx_freq(channel_nums[ch])/1e6) << std::endl << std::endl; //sm
	//
	//	//set the rf gain
	//	if (vm.count("gain"))
	//	{
	//	std::cout << boost::format("Setting TX Gain: %f dB...") % gain << std::endl;
	//	//usrp->set_tx_gain(gain, channel_nums[ch]); //sm
	//	//std::cout << boost::format("Actual TX Gain: %f dB...") % usrp->get_tx_gain(channel_nums[ch]) << std::endl << std::endl; //sm
	//	}

	//	//set the IF filter bandwidth
	//	if (vm.count("bw"))
	//	{
	//		std::cout << boost::format("Setting TX Bandwidth: %f MHz...") % bw << std::endl;
	//		//usrp->set_tx_bandwidth(bw, channel_nums[ch]); //sm
	//		//std::cout << boost::format("Actual TX Bandwidth: %f MHz...") % usrp->get_tx_bandwidth(channel_nums[ch]) << std::endl << std::endl; //sm
	//	}

	////set the antenna
	////if (vm.count("ant")) usrp->set_tx_antenna(ant, channel_nums[ch]); //sm
	//}

	//boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time
	////for the const wave, set the wave freq for small samples per period
	//if (wave_freq == 0 and wave_type == "CONST")
	//{
	//	//wave_freq = usrp->get_tx_rate()/2; //sm
	//}

	////error when the waveform is not possible to generate
	////if (std::abs(wave_freq) > usrp->get_tx_rate()/2) // sm
	//{ 
	//	//throw std::runtime_error("wave freq out of Nyquist zone"); //sm
	//} 

	////if (usrp->get_tx_rate()/std::abs(wave_freq) > wave_table_len/2)
	//{
	//	//throw std::runtime_error("wave freq too small for table"); //sm
	//} 

	////pre-compute the waveform values
	//const wave_table_class wave_table(wave_type, ampl);
	////const size_t step = boost::math::iround(wave_freq/usrp->get_tx_rate() * wave_table_len); //sm
	//size_t index = 0;
	////create a transmit streamer
	////linearly map channels (index0 = channel0, index1 = channel1, ...)
	////uhd::stream_args_t stream_args("fc32", otw); //sm
	////stream_args.channels = channel_nums; //sm
	//// uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args); //sm
	////allocate a buffer which we re-use for each channel
	////if (spb == 0) spb = tx_stream->get_max_num_samps()*10; //sm
	//std::vector<std::complex<float> > buff(spb);
	//std::vector<std::complex<float> *> buffs(channel_nums.size(), &buff.front());
	////setup the metadata flags
	////uhd::tx_metadata_t md; //sm
	////md.start_of_burst = true; //sm
	//// md.end_of_burst = false; //sm
	////md.has_time_spec = true; //sm
	////md.time_spec = uhd::time_spec_t(0.1);
	//std::cout << boost::format("Setting device timestamp to 0...") << std::endl;
	////usrp->set_time_now(uhd::time_spec_t(0.0)); //sm
	////Check Ref and LO Lock detect
	//std::vector<std::string> sensor_names;
	////sensor_names = usrp->get_tx_sensor_names(0); //sm

	//if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end())
	//{
	//	//uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked",0); //sm
	//	//std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string() << std::endl; //sm
	//	//UHD_ASSERT_THROW(lo_locked.to_bool()); //sm
	//}

	////sensor_names = usrp->get_mboard_sensor_names(0); //sm
	//if ((ref == "mimo") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) 
	//{
	//	//uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); //sm
	//	//std::cout << boost::format("Checking TX: %s ...") % mimo_locked.to_pp_string() << std::endl; //sm
	//	//UHD_ASSERT_THROW(mimo_locked.to_bool()); //sm
	//}

	//if ((ref == "external") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) 
	//{
	//	//uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); //sm
	//	//std::cout << boost::format("Checking TX: %s ...") % ref_locked.to_pp_string() << std::endl; //sm
	//	//UHD_ASSERT_THROW(ref_locked.to_bool()); //sm
	//}

	//std::signal(SIGINT, &sig_int_handler);
	//std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
	////send data until the signal handler gets called
	//while(not stop_signal_called)
	//{
	//	//fill the buffer with the waveform
	//	for (size_t n = 0; n < buff.size(); n++)
	//	{
	//	//buff[n] = wave_table(index += step); //sm
	//	}
	//
	//	//send the entire contents of the buffer
	////tx_stream->send(buffs, buff.size(), md); //sm
	////md.start_of_burst = false; //sm
	////md.has_time_spec = false; //sm
	//}

	////send a mini EOB packet
	////md.end_of_burst = true; //sm
	////tx_stream->send("", 0, md); //sm	
	//finished
	std::cout << std::endl << "Done!" << std::endl << std::endl;

	system("pause");

	return EXIT_SUCCESS;
}


More information about the USRP-users mailing list