Hello World with Windows and the DLL
From Tools4SDR
Tutorial: Using the USRP with Windows applications
|
| 1. Description of SDR4All toolbox |
| 2. Setup the toolbox |
| 3. Sent and received signals |
| 4. Hello world tutorial |
| 5. RX application |
| 6. TX application |
To use the SDR4All DLL, we recommand you to use the soft Microsoft Visual C++ 2008 - Express edition or Microsoft Visual C# 2008 - Express edition. Both softwares are free and distributed by Microsoft.
This tutorial use the first soft (Microsoft Visual C++ 2008 - Express edition), but other tutorials use the second one. Both programming langages are very similar nevertheless.
We assume in the following that you have properly installed this soft and that you use it to develop applications. If not, you should be able to adapt this tutorial to your own development environment.
The objectives of this tutorial are the following one:
- Compile a soft that is able to use the DLL
- Dialog with the USRP
- Read data from the USRP
- Send data to the USRP
Contents |
Compile a soft with the DLL
Start Microsoft Visual C++ 2008 and create a new project. Select:
- CLR as kind of project (left part)
- Application windows forms (right part)
Name your project as you wish. In the below example: MyFirstApp_WithSDR4All
Include the DLL into the project
Add the SDR4All DLL to the project as a reference. To do this, right click on the project name and select reference, as illustred below:
A menu open. Select the add a reference option:
Just select then the DLL file SDR4All_DLL that stands in your installation dir. In general: C:\Program Files\SDR4All Toolbox\
Create the DLL object
In the code of the form (that you can display if you right-click on the form and select show the code), add the line:
using namespace SDR4All_DLL;
below the other using namespace lines.
In the form1 object, declare a SDR4All variable:
SDR4All^ MySDR4AllObj;
And create the object in the Form1 constructor for example:
MySDR4AllObj = gcnew SDR4All();
You should be able to compile your project.
Interaction with the card
For the rest of the tutorial, we assume that you are able to develop your own IHM. If you are not confident yet with this point, you can download the tutorial solution here.
This solution looks like:
This tutorial solution calls many of the function listed below:
List USRP cards, get general information
The following method are used to get general informations. The command to get the number of USRP is:
MySDR4AllObj->GetNumberOfUSRP();
Commands to get general information about an USRP:
MySDR4AllObj->Get_USRP_DriverName(CardNumber); MySDR4AllObj->Get_USRP_FriendlyName(CardNumber); MySDR4AllObj->Get_USRP_hw_rev(CardNumber); MySDR4AllObj->Get_USRP_SerialNumber(CardNumber); MySDR4AllObj->Get_USRP_ProductName(CardNumber); MySDR4AllObj->Get_USRP_Manufacturer(CardNumber);
Commands to get information about the daughterboards:
MySDR4AllObj->GetDaughterBoardName(CardNumber,SlotNumber); MySDR4AllObj->Is_DB_Supported(CardNumber,SlotNumber);
The slot numbers are the following ones:
- 0 for RX A
- 1 for TX A
- 2 for RX B
- 3 for TX B
Note that if the card is working in transmission it uses the port TX/RX of the daughterboard. If you are using the toolbox with a version < 1.0.2, if the card is working in reception it uses the port RX2. With version >= 1.0.2, it works with the port TX/RX.
Use the USRP in RX
To use an USRP in RX, you have to connect to it:
MySDR4AllObj->ConnectToRX(CardNumber,Slot);
Where slot number is:
- 0 for side A
- 1 for side B
Commands to get daughterboard information:
MySDR4AllObj->GetRXGainRange(gainmin, gainmax, gainstep); MySDR4AllObj->GetRXFreqRange(gainmin, gainmax, gainstep);
Functions to change the reception parameters:
MySDR4AllObj->ChangeRXGain(gain); MySDR4AllObj->ChangeRXFreq(freq); MySDR4AllObj->ChangeDecimRate(new_rate);
where new_rate values correspond to the following sampling frequency:
- new_rate = 8, 8MHz
- new_rate = 16, 4MHz
- new_rate = 32, 2MHz
- new_rate = 64, 1MHz
- new_rate = 128, 500kHz
Finally, several functions are available to receive data. To receive a burst of data:
MySDR4AllObj->RXOnce(NbOfSymboles, Data_I, Data_Q);
Another tutorial on how to receive data in a continuous way will be published soon.
RX_to_file is another example of the use of these commands.
Use the USRP in TX
To use an USRP in TX, you have to connect to it:
MySDR4AllObj->ConnectToTX(CardNumber,Slot);
Where slot number is:
- 0 for side A
- 1 for side B
Commands to get daughterboard information:
MySDR4AllObj->GetTXGainRange(gainmin, gainmax, gainstep); MySDR4AllObj->GetTXFreqRange(gainmin, gainmax, gainstep);
Functions to change the reception parameters:
MySDR4AllObj->ChangeTXGain(gain); MySDR4AllObj->ChangeTXFreq(freq); MySDR4AllObj->ChangeInterpRate(new_rate);
where new_rate values correspond to the following sampling frequency (note the same values as for the decimation):
- new_rate = 16, 8MHz
- new_rate = 32, 4MHz
- new_rate = 64, 2MHz
- new_rate = 128, 1MHz
- new_rate = 256, 500kHz
Finally, to send data you can use the function:
MySDR4AllObj->TXOnce(Data_I,Data_Q)
TX_bursts is another example of the use of these commands.
