# Is there any LimeSuite TX example in cpp? (using LimeSuite.h api )

**URL:** <https://discourse.myriadrf.org/t/is-there-any-limesuite-tx-example-in-cpp-using-limesuite-h-api/2098>\
**Category:** Lime Suite\
**Created:** [5 December 2017 10:04 UTC](https://discourse.myriadrf.org/t/is-there-any-limesuite-tx-example-in-cpp-using-limesuite-h-api/2098 "2017-12-05T10:04:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![changyul](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@changyul](https://discourse.myriadrf.org/u/changyul)\
**Post date:** [5 December 2017 10:04 UTC](https://discourse.myriadrf.org/t/is-there-any-limesuite-tx-example-in-cpp-using-limesuite-h-api/2098/1 "2017-12-05T10:04:10Z")

</div>

HI. I am trying to sending any signal (sine or just 0, 1) through my LimeSDR.

I’m programming in cpp mode, using LimeSuite.h & LMS7.

I was looking for any tutorial for single tx…, but there was only one tx example (repeat received signal).  
( [https://github.com/myriadrf/LimeSuite/blob/master/docs/lms7\_api\_quick\_start\_guide.pdf](https://github.com/myriadrf/LimeSuite/blob/master/docs/lms7_api_quick_start_guide.pdf) )

Is there any other tx project, tutorial, or examples?

This is what I am doing now.  
I am using LimeSDR, and HackRF both.  
I want to sending signal from LImeSDR with c++ program, and receiving signal to HackRF with gnuradio-companion.  
(I already done receiving signal to LimeSDR from HackRF with c++ code )

I would really appreciate hearing your any advices or help.

---

<div class="post-metadata">

**Author:** ![IgnasJ](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@IgnasJ](https://discourse.myriadrf.org/u/IgnasJ)\
**Post date:** [5 December 2017 13:46 UTC](https://discourse.myriadrf.org/t/is-there-any-limesuite-tx-example-in-cpp-using-limesuite-h-api/2098/3 "2017-12-05T13:46:31Z")

</div>

There is no example for Tx only in LimeSuite repository. You can try the code below. It should set center frequency to 500 MHz, TX1\_1 port and transmit single tone.

```
#include <iostream>
#include "lime/LimeSuite.h"
#include <thread>
#include <chrono>
#include <math.h>

using namespace std;

lms_device_t* device;
const double sampleRate = 5e6;
bool running;
const int tx_size = 1024*16;
float tx_buffer[2*tx_size];

int error()
{
  cout << "ERROR: " << LMS_GetLastErrorMessage() << endl;
  LMS_Close(device);
  exit(-1);
}

void StreamTest()
{
    lms_stream_t tx_stream;
    tx_stream.channel = 0;
    tx_stream.fifoSize = 256*1024;
    tx_stream.throughputVsLatency = 0.5;
    tx_stream.dataFmt = lms_stream_t::LMS_FMT_F32;
    tx_stream.isTx = true;

    lms_stream_meta_t meta_tx;   
    meta_tx.waitForTimestamp = false;
    meta_tx.flushPartialPacket = false;
    meta_tx.timestamp = 0;

    for (int i = 0; i <tx_size; i++)
    {
        tx_buffer[2*i] = cos(2*M_PI*i/16.0);
        tx_buffer[2*i+1] = sin(2*M_PI*i/16.0);
    }

    LMS_SetupStream(device, &tx_stream);
    LMS_StartStream(&tx_stream);

    while (running)
    {
        int ret = LMS_SendStream(&tx_stream,tx_buffer,tx_size,&meta_tx,1000);
        if (ret != tx_size)
            cout << "error: samples sent: " << ret << "/" << tx_size << endl;;
    }

    LMS_StopStream(&tx_stream);
    LMS_DestroyStream(device,&tx_stream); 
}

int main(int argc, char** argv)
{
    int n= LMS_GetDeviceList(nullptr);
    if (n > 0)
    {
        if (LMS_Open(&device,NULL,NULL)!=0) //open first device
            error();

        if (LMS_Init(device)!=0)
            error();

        if (LMS_EnableChannel(device,LMS_CH_TX,0,true)!=0) 
            error();

        if (LMS_SetSampleRate(device,sampleRate,0)!=0)
            error();

        if (LMS_SetLOFrequency(device,LMS_CH_TX, 0, 500e6)!=0)
            error();
    
        if (LMS_SetAntenna(device, LMS_CH_TX, 0, LMS_PATH_TX1)!=0) //TX1_1        
            error();

        running = true;
        std::thread thread = std::thread(StreamTest);
        this_thread::sleep_for(chrono::seconds(10));
        running = false;
        thread.join();

        if (LMS_Close(device)==0)
            cout << "Closed" << endl;
    }
    return 0;
}
```

---

<div class="post-metadata">

**Author:** ![changyul](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@changyul](https://discourse.myriadrf.org/u/changyul)\
**Post date:** [6 December 2017 01:22 UTC](https://discourse.myriadrf.org/t/is-there-any-limesuite-tx-example-in-cpp-using-limesuite-h-api/2098/5 "2017-12-06T01:22:30Z")

</div>

Thanks a lot!

This code is exactly what I want to know!

basic & simple!
