# RFID library issues - Popping from TX?

**URL:** https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291
**Category:** LimeSDR
**Created:** [30 May 2017 23:36 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291 "2017-05-30T23:36:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tungstenlightbulb](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@tungstenlightbulb](https://discourse.myriadrf.org/u/tungstenlightbulb)
#### Post date: [30 May 2017 23:36 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/1 "2017-05-30T23:36:21Z")

</div>

Over the last several weeks I’ve been trying to adapt a [Gen 2 UHF RFID library](https://github.com/nikosl21/Gen2-UHF-RFID-Reader) that was originally made for the USRPN200/N210 and I’ve at least been able to partially adapt the library, after installing it, for the LimeSDR with the code below:

```
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import blocks
from gnuradio import filter
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from gnuradio import analog
from gnuradio import digital
import osmosdr
import sip
import sys
import time
import rfid

class reader_top_block(gr.top_block):

  def __init__ (self):
    gr.top_block. __init__ (self)

    rt = gr.enable_realtime_scheduling()

    ######## Variables #########
    self.dac_rate = 1e6 # DAC rate
    self.adc_rate = 100e6/50 # ADC rate (2MS/s complex samples)
    self.decim = 5 # Decimation (downsampling factor)
    self.ampl = 0.1 # Output signal amplitude (signal power vary for different RFX900 cards)
    self.freq = 915e6 # Modulation frequency (can be set between 902-920)
    self.rx_gain = 20 # RX Gain (gain at receiver)
    self.tx_gain = 0 # RFX900 no Tx gain option

    # Each FM0 symbol consists of ADC_RATE/BLF samples (2e6/40e3 = 50 samples)
    # 10 samples per symbol after matched filtering and decimation
    self.num_taps = [1] * 25 # matched to half symbol period

    self.file_sink_decoder = blocks.file_sink(gr.sizeof_gr_complex*1, "data/decoder", False)
   

    ######## Blocks #########
    self.matched_filter = filter.fir_filter_ccf(self.decim, self.num_taps)
    self.gate = rfid.gate(int(self.adc_rate/self.decim))
    self.tag_decoder = rfid.tag_decoder(int(self.adc_rate/self.decim))
    self.reader = rfid.reader(int(self.adc_rate/self.decim),int(self.dac_rate))
    self.amp = blocks.multiply_const_ff(self.ampl)
    self.to_complex = blocks.float_to_complex(1)

    # Osmocom blocks
    self.u_source = osmosdr.source(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0' )
    self.u_source.set_sample_rate(self.adc_rate)
    self.u_source.set_center_freq(self.freq, 0)
    self.u_source.set_freq_corr(0, 0)
    self.u_source.set_dc_offset_mode(0, 0)
    self.u_source.set_iq_balance_mode(0, 0)
    self.u_source.set_gain_mode(True, 0)
    self.u_source.set_gain(self.rx_gain, 0)
    self.u_source.set_if_gain(10, 0)
    self.u_source.set_bb_gain(10, 0)
    self.u_source.set_antenna("LNAL", 0)
    self.u_source.set_bandwidth(0, 1000000)

    self.u_sink = osmosdr.sink(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0' )
    self.u_sink.set_sample_rate(self.dac_rate)
    self.u_sink.set_center_freq(self.freq, 0)
    self.u_sink.set_freq_corr(0, 0)
    self.u_sink.set_gain(self.tx_gain, 0)
    self.u_sink.set_if_gain(15, 0)
    self.u_sink.set_bb_gain(15, 0)
    self.u_sink.set_antenna("BAND1", 0)
    self.u_sink.set_bandwidth(0, 1000000)

    ######## Connections #########
    self.connect(self.u_source, self.matched_filter)
    self.connect(self.matched_filter, self.gate)
    self.connect(self.gate, self.tag_decoder)
    self.connect((self.tag_decoder,0), self.reader)
    self.connect(self.reader, self.amp)
    self.connect(self.amp, self.to_complex)
    self.connect(self.to_complex, self.u_sink)

    #self.connect(self.gate, self.file_sink_gate)
    self.connect((self.tag_decoder,1), self.file_sink_decoder) # (Do not comment this line)
    #self.connect(self.file_sink_reader, self.file_sink_reader)
    #self.connect(self.matched_filter, self.file_sink_matched_filter)

if __name__ == ' __main__':

  main_block = reader_top_block()
  main_block.start()

  while(1):
    inp = raw_input("'Q' to quit \n")
    if (inp == "q" or inp == "Q"):
      break

  main_block.reader.print_results()
  main_block.stop()

```

And when I run it I get the following output:

```
/usr/bin/python2.7 /home/logic/SDR/LimeReader.py
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release

gr::log :INFO: gate0 - T1 samples : 96
gr::log :INFO: gate0 - PW samples : 4
gr::log :INFO: gate0 - Samples of Tag bit : 10
gr::log :INFO: gate0 - Size of window : 100
gr::log :INFO: gate0 - Size of window for dc offset estimation : 48
gr::log :INFO: gate0 - Duration of window for dc offset estimation : 120 us
gr::log :INFO: gate0 - Initializing reader state...
gr::log :INFO: tag_decoder0 - Number of samples of Tag bit : 10
gr::log :INFO: reader0 - Block initialized
gr::log :INFO: reader0 - Number of samples data 0 : 24
gr::log :INFO: reader0 - Number of samples data 1 : 48
gr::log :INFO: reader0 - Number of samples cw : 250
gr::log :INFO: reader0 - Number of samples delim : 12
gr::log :INFO: reader0 - Number of slots : 1
gr::log :INFO: reader0 - Carrier wave after a query transmission in samples : 1295
gr::log :INFO: reader0 - Carrier wave after ACK transmission in samples : 4575
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy soapy redpitaya 
[INFO] Make connection: 'LimeSDR-USB [USB 3.0] 9060A02592E12'
Estimated reference clock 30.7197 MHz
Selected reference clock 30.720 MHz
LMS7002M values cache at /home/logic/.limesuite/LMS7002M_cache_values.db
[INFO] Device name: LimeSDR-USB
[INFO] Reference: 30.72 MHz
[INFO] Init LMS7002M(0)
[INFO] Ver=7, Rev=1, Mask=1
CGEN: Freq=80 MHz, VCO=2.56 GHz, INT=82, FRAC=349525, DIV_OUTCH_CGEN=15
[INFO] LMS7002M calibration values caching Enable
[INFO] SoapyLMS7::setFrequency(Rx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setFrequency(Tx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setAntenna(Rx, 0, LNAL)
[INFO] SoapyLMS7::setAntenna(Tx, 0, BAND1)
[INFO] SoapyLMS7::setGain(Rx, 0, PGA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, LNA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, TIA, 0 dB)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, -50 dB)
[INFO] SoapyLMS7::setSampleRate(Rx, 0, 10 MHz), CGEN=80 MHz, ADC=20 MHz, decim=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=20MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=182, N=7, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 100.4 (steps 58)
[INFO] SoapyLMS7::setSampleRate(Tx, 0, 10 MHz), CGEN=80 MHz, DAC=20 MHz, interp=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=10MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 95.2 (steps 110)
[INFO] SoapyLMS7::setBandwidth(Rx, 0, 30 MHz)
[INFO] Rx Filter calibrated from cache
[INFO] SoapyLMS7::setBandwidth(Tx, 0, 30 MHz)
[INFO] Tx Filter calibrated from cache
[INFO] SoapyLMS7::setFrequency(Rx, 1, BB, 0 MHz)
[INFO] SoapyLMS7::setFrequency(Tx, 1, BB, 0 MHz)
[INFO] SoapyLMS7::setAntenna(Rx, 1, LNAL)
[INFO] SoapyLMS7::setAntenna(Tx, 1, BAND1)
[INFO] SoapyLMS7::setGain(Rx, 1, PGA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 1, LNA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 1, TIA, 0 dB)
[INFO] SoapyLMS7::setGain(Tx, 1, PAD, -50 dB)
[INFO] SoapyLMS7::setSampleRate(Rx, 1, 10 MHz), CGEN=80 MHz, ADC=20 MHz, decim=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=20MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=182, N=7, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 100.4 (steps 58)
[INFO] SoapyLMS7::setSampleRate(Tx, 1, 10 MHz), CGEN=80 MHz, DAC=20 MHz, interp=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=10MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 95.2 (steps 110)
[INFO] SoapyLMS7::setBandwidth(Rx, 1, 30 MHz)
[INFO] Rx Filter calibrated from cache
[INFO] SoapyLMS7::setBandwidth(Tx, 1, 30 MHz)
[INFO] Tx Filter calibrated from cache
[INFO] SoapyLMS7::setSampleRate(Rx, 0, 2 MHz), CGEN=256 MHz, ADC=64 MHz, decim=32
CGEN: Freq=256 MHz, VCO=2.56 GHz, INT=82, FRAC=349525, DIV_OUTCH_CGEN=4
ConnectionSTREAM::ConfigureFPGA_PLL(tx=2MHz, rx=2MHz)
SetFrequency using cache values vco:2, csw:181
[INFO] SoapyLMS7::setFrequency(Rx, 0, RF, 915 MHz)
[WARNING] GetDC_IQ_Interp(915 MHz, ch=0, tx=0): no matches between [914, 916] MHz
[INFO] SoapyLMS7::setFrequency(Rx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setGain(Rx, 0, LNA, 20 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, TIA, 2 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, PGA, 2 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, LNA, 10 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, PGA, 10 dB)
[INFO] SoapyLMS7::setAntenna(Rx, 0, LNAL)
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in sink types: uhd hackrf bladerf soapy redpitaya file 
CGEN: Freq=128 MHz, VCO=2.56 GHz, INT=82, FRAC=349525, DIV_OUTCH_CGEN=9
[INFO] SoapyLMS7::setSampleRate(Tx, 0, 1 MHz), CGEN=128 MHz, DAC=32 MHz, interp=32
ConnectionSTREAM::ConfigureFPGA_PLL(tx=1MHz, rx=2MHz)
SetFrequency using cache values vco:2, csw:182
[INFO] SoapyLMS7::setFrequency(Tx, 0, RF, 915 MHz)
[WARNING] GetDC_IQ_Interp(915 MHz, ch=0, tx=1): no matches between [914, 916] MHz
[INFO] SoapyLMS7::setFrequency(Tx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, 15 dB)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, 15 dB)
[INFO] SoapyLMS7::setAntenna(Tx, 0, BAND1)
'Q' to quit 
Warning popping from TX, samples popped 1314/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 1083/1360
Warning popping from TX, samples popped 0/1360
L 1392640
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Rx: 6.029 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Tx: 0.000 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Rx: 6.023 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360

```

And that message continually repeats itself. I’ve narrowed it down [this file on github in LimeSuite](https://github.com/myriadrf/LimeSuite/blob/master/src/ConnectionSTREAM/ConnectionSTREAMing.cpp), that is continuously printing that message for a popping of the TX stream. I know some [guys working with OpenBTS](https://discourse.myriadrf.org/t/openbts-1st-test/823/20) had a similar problem with this on that setup and a BLE sniffer setup too, but I’m not entirely sure how they fixed it. Is there anyway to mitigate TX popping?

---

<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: [31 May 2017 06:49 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/2 "2017-05-31T06:49:17Z")

</div>

That message appears because there are no samples in TX FIFO to transmit. I am not sure how Soapy handles things but generally to stop it from appearing you need to either keep feeding samples to TX stream or stop TX stream.

---

<div class="post-metadata">

### Author: ![tungstenlightbulb](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@tungstenlightbulb](https://discourse.myriadrf.org/u/tungstenlightbulb)
#### Post date: [31 May 2017 23:12 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/3 "2017-05-31T23:12:25Z")

</div>

From what I’ve been reading, I think you’re on point. When I multiply or add a DC signal sources with the same sample rate, I know that there are more samples in the FIFO, but it’s still popping. It almost sounds like some of the guys using the USRP had the same problem back in 2013-2014, but they may have resolved it and Nikols Kargas, who made the RFID library, got it to work on the USRP back in 2015.

I suppose it’s time to figure out a gnuradio block to pad in zeros, unless anyone else has any other suggestions or knows of a block that already does this. I’ll also double check that all of the dependencies are fulfilled like @cswiger was suggesting in that [OpenBTS post](https://discourse.myriadrf.org/t/openbts-1st-test/823/32).

---

<div class="post-metadata">

### Author: ![hTo137](https://avatars.discourse-cdn.com/v4/letter/h/ba8739/32.png) [@hTo137](https://discourse.myriadrf.org/u/hTo137)
#### Post date: [31 May 2017 23:43 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/4 "2017-05-31T23:43:49Z")

</div>

I followed that github link and in there I followed the fork-\>network link and there is a fork that is ahead in commits. I have no idea if it helps you. But once in a while I find a fork that works in my favor.

Here’s the repo:

[https://github.com/rupumped/Gen2-UHF-RFID-Reader/commit/3f5876ee930bd9950c8db2aa9e3563e1735fa8c7](https://github.com/rupumped/Gen2-UHF-RFID-Reader/commit/3f5876ee930bd9950c8db2aa9e3563e1735fa8c7)

---

<div class="post-metadata">

### Author: ![tungstenlightbulb](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@tungstenlightbulb](https://discourse.myriadrf.org/u/tungstenlightbulb)
#### Post date: [2 June 2017 23:33 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/5 "2017-06-02T23:33:39Z")

</div>

I’ve started to minimize some of the popping issues, but it still occasionally pops by adding the . I also need to figure out why the reader doesn’t pick up the tag right next to it (I checked it with another RFID reader and the tag isn’t dead). It might simply be because it can’t pick up the whisper of the tag with the screaming TX, so I might have to put together a diy directional coupler for a monostatic mode or I’ll need to try more directional antennas so that it’s a more isolated bistatic mode. It might also be one of the rates or another variable inside the reader.

I changed the number of max queries in the reader in global\_vars.h to 10000 instead of 1000 and have the following reader code below with a QT time sink:

```
#!/usr/bin/env python2

from PyQt4 import Qt
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import qtgui
from gnuradio import blocks
from gnuradio import filter
from gnuradio import digital
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from gnuradio import analog
from gnuradio import channels
import osmosdr
import sip
import sys
import time
import rfid

class reader_top_block(gr.top_block, Qt.QWidget):

  def __init__ (self):
    gr.top_block. __init__ (self)
    Qt.QWidget. __init__ (self)
    self.setWindowTitle("Top Block")
    try:
        self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
    except:
        pass
    self.top_scroll_layout = Qt.QVBoxLayout()
    self.setLayout(self.top_scroll_layout)
    self.top_scroll = Qt.QScrollArea()
    self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
    self.top_scroll_layout.addWidget(self.top_scroll)
    self.top_scroll.setWidgetResizable(True)
    self.top_widget = Qt.QWidget()
    self.top_scroll.setWidget(self.top_widget)
    self.top_layout = Qt.QVBoxLayout(self.top_widget)
    self.top_grid_layout = Qt.QGridLayout()
    self.top_layout.addLayout(self.top_grid_layout)

    self.settings = Qt.QSettings("GNU Radio", "top_block")
    self.restoreGeometry(self.settings.value("geometry").toByteArray())

    rt = gr.enable_realtime_scheduling()

    ######## Variables #########
    self.adc_rate = 8e6 # ADC rate (2MS/s complex samples)
    self.dac_rate = self.adc_rate/16 # DAC rate
    self.decim = 32 # Decimation (downsampling factor)
    self.ampl = 0.75 # Output signal amplitude (signal power vary for different RFX900 cards)
    self.freq = 915e6 # Modulation frequency (can be set between 902-920)
    blf = 100e3
    self.fft = 2**10

    # Each FM0 symbol consists of ADC_RATE/BLF samples (2e6/40e3 = 50 samples)
    # 10 samples per symbol after matched filtering and decimation
    self.num_taps = [1]*int(self.adc_rate/blf/2) # matched to half symbol period

    self.file_sink_source = blocks.file_sink(gr.sizeof_gr_complex*1, "data/source", False)
    self.file_sink_matched_filter = blocks.file_sink(gr.sizeof_gr_complex*1, "data/matched_filter", False)
    self.file_sink_gate = blocks.file_sink(gr.sizeof_gr_complex*1, "data/gate", False)
    self.file_sink_decoder = blocks.file_sink(gr.sizeof_gr_complex*1, "data/decoder", False)
    self.file_sink_reader = blocks.file_sink(gr.sizeof_gr_complex*1, "data/reader", False)

    ######## Blocks #########
    self.qtgui_time_sink = qtgui.time_sink_c(
        1024, # size
        self.adc_rate, # samp_rate
        "", # name
        1 # number of inputs
    )
    self.qtgui_time_sink.set_update_time(0.10)
    self.qtgui_time_sink.set_y_axis(-1, 1)

    self.qtgui_time_sink.set_y_label('Amplitude', "")

    self.qtgui_time_sink.enable_tags(-1, True)
    self.qtgui_time_sink.set_trigger_mode(qtgui.TRIG_MODE_AUTO, qtgui.TRIG_SLOPE_POS, 1, 0, 0, "")
    self.qtgui_time_sink.enable_autoscale(False)
    self.qtgui_time_sink.enable_grid(False)
    self.qtgui_time_sink.enable_axis_labels(True)
    self.qtgui_time_sink.enable_control_panel(True)

    if not True:
        self.qtgui_time_sink.disable_legend()

    labels = ['', '', '', '', '',
              '', '', '', '', '']
    widths = [1, 1, 1, 1, 1,
              1, 1, 1, 1, 1]
    colors = ["blue", "red", "green", "black", "cyan",
              "magenta", "yellow", "dark red", "dark green", "blue"]
    styles = [1, 1, 1, 1, 1,
              1, 1, 1, 1, 1]
    markers = [-1, -1, -1, -1, -1,
               -1, -1, -1, -1, -1]
    alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
              1.0, 1.0, 1.0, 1.0, 1.0]

    for i in xrange(2 * 1):
        if len(labels[i]) == 0:
            if (i % 2 == 0):
                self.qtgui_time_sink.set_line_label(i, "Re{{Data {0}}}".format(i / 2))
            else:
                self.qtgui_time_sink.set_line_label(i, "Im{{Data {0}}}".format(i / 2))
        else:
            self.qtgui_time_sink.set_line_label(i, labels[i])
        self.qtgui_time_sink.set_line_width(i, widths[i])
        self.qtgui_time_sink.set_line_color(i, colors[i])
        self.qtgui_time_sink.set_line_style(i, styles[i])
        self.qtgui_time_sink.set_line_marker(i, markers[i])
        self.qtgui_time_sink.set_line_alpha(i, alphas[i])

    self._qtgui_time_sink_win = sip.wrapinstance(self.qtgui_time_sink.pyqwidget(), Qt.QWidget)
    self.top_layout.addWidget(self._qtgui_time_sink_win)

    self.matched_filter = filter.fir_filter_ccc(self.decim, self.num_taps)
    self.gate = rfid.gate(int(self.adc_rate/self.decim))
    self.tag_decoder = rfid.tag_decoder(int(self.adc_rate/self.decim))
    self.reader = rfid.reader(int(self.adc_rate/self.decim), int(self.dac_rate))
    self.amp = blocks.multiply_const_ff(self.ampl)
    self.to_complex = blocks.float_to_complex(1)
    self.blank_signal = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 0)
    self.add = blocks.add_vcc(1)

    # Osmocom blocks
    self.u_source = osmosdr.source(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0' )
    self.u_source.set_sample_rate(self.adc_rate)
    self.u_source.set_center_freq(self.freq, 0)
    self.u_source.set_freq_corr(0, 0)
    self.u_source.set_dc_offset_mode(0, 0)
    self.u_source.set_iq_balance_mode(0, 0)
    self.u_source.set_gain_mode(False, 0)
    self.u_source.set_gain(20, 0)
    self.u_source.set_if_gain(0, 0)
    self.u_source.set_bb_gain(0, 0)
    self.u_source.set_antenna("LNAL", 0)
    self.u_source.set_bandwidth(0, 6000000)

    self.u_sink = osmosdr.sink(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0' )
    self.u_sink.set_sample_rate(self.dac_rate)
    self.u_sink.set_center_freq(self.freq, 0)
    self.u_sink.set_freq_corr(0, 0)
    self.u_sink.set_gain(0, 0)
    self.u_sink.set_if_gain(10, 0)
    self.u_sink.set_bb_gain(5, 0)
    self.u_sink.set_antenna("BAND1", 0)
    self.u_sink.set_bandwidth(0, 1000000)

    ######## Connections #########
    self.connect(self.u_source, self.matched_filter)
    self.connect(self.matched_filter, self.gate)
    self.connect(self.gate, self.tag_decoder)
    self.connect((self.tag_decoder, 0), self.reader)
    self.connect(self.reader, self.amp)
    # self.connect(self.amp, self.to_complex)
    self.connect(self.amp, self.to_complex)
    self.connect(self.to_complex, (self.add, 0))
    self.connect(self.blank_signal, (self.add, 1))
    self.connect((self.add, 0), (self.u_sink, 0))
    self.connect((self.matched_filter, 0), (self.qtgui_time_sink, 0))

    # self.connect(self.gate, self.file_sink_gate)
    self.connect((self.tag_decoder, 1), self.file_sink_decoder) # (Do not comment this line)
    self.connect(self.to_complex, self.file_sink_reader)
    # self.connect(self.matched_filter, self.file_sink_matched_filter)

    def closeEvent(self, event):
        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.settings.setValue("geometry", self.saveGeometry())
        event.accept()

if __name__ == ' __main__':
    from distutils.version import StrictVersion

    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
        Qt.QApplication.setGraphicsSystem(style)
    qapp = Qt.QApplication(sys.argv)

    main_block = reader_top_block()
    main_block.start()
    main_block.show()

    def quitting():
        main_block.reader.print_results()
        main_block.stop()
        main_block.wait()

    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    qapp.exec_()

    while (1):
        inp = raw_input("'Q' to quit \n")
        if (inp == "q" or inp == "Q"):
            break
    quitting()

```

I also received the following output:

```
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release

gr::log :INFO: gate0 - T1 samples : 62
gr::log :INFO: gate0 - PW samples : 3
gr::log :INFO: gate0 - Samples of Tag bit : 6
gr::log :INFO: gate0 - Size of window : 62
gr::log :INFO: gate0 - Size of window for dc offset estimation : 30
gr::log :INFO: gate0 - Duration of window for dc offset estimation : 120 us
gr::log :INFO: gate0 - Initializing reader state...
gr::log :INFO: tag_decoder0 - Number of samples of Tag bit : 6.25
gr::log :INFO: reader0 - Block initialized
gr::log :INFO: reader0 - Number of samples data 0 : 12
gr::log :INFO: reader0 - Number of samples data 1 : 24
gr::log :INFO: reader0 - Number of samples cw : 125
gr::log :INFO: reader0 - Number of samples delim : 6
gr::log :INFO: reader0 - Number of slots : 1
gr::log :INFO: reader0 - Carrier wave after a query transmission in samples : 1037
gr::log :INFO: reader0 - Carrier wave after ACK transmission in samples : 4087
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy soapy redpitaya 
[INFO] Make connection: 'LimeSDR-USB [USB 3.0] 9060A02592E12'
Estimated reference clock 30.7197 MHz
Selected reference clock 30.720 MHz
[INFO] Device name: LimeSDR-USB
[INFO] Reference: 30.72 MHz
[INFO] Init LMS7002M(0)
LMS7002M values cache at /home/logic/.limesuite/LMS7002M_cache_values.db
[INFO] Ver=7, Rev=1, Mask=1
[INFO] LMS7002M calibration values caching Enable
CGEN: Freq=80 MHz, VCO=2.56 GHz, INT=82, FRAC=349525, DIV_OUTCH_CGEN=15
[INFO] SoapyLMS7::setFrequency(Rx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setFrequency(Tx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setAntenna(Rx, 0, LNAL)
[INFO] SoapyLMS7::setAntenna(Tx, 0, BAND1)
[INFO] SoapyLMS7::setGain(Rx, 0, PGA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, LNA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, TIA, 0 dB)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, -50 dB)
[INFO] SoapyLMS7::setSampleRate(Rx, 0, 10 MHz), CGEN=80 MHz, ADC=20 MHz, decim=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=20MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=182, N=7, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 100.4 (steps 58)
[INFO] SoapyLMS7::setSampleRate(Tx, 0, 10 MHz), CGEN=80 MHz, DAC=20 MHz, interp=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=10MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 95.2 (steps 110)
[INFO] SoapyLMS7::setBandwidth(Rx, 0, 30 MHz)
[INFO] Rx Filter calibrated from cache
[INFO] SoapyLMS7::setBandwidth(Tx, 0, 30 MHz)
[INFO] Tx Filter calibrated from cache
[INFO] SoapyLMS7::setFrequency(Rx, 1, BB, 0 MHz)
[INFO] SoapyLMS7::setFrequency(Tx, 1, BB, 0 MHz)
[INFO] SoapyLMS7::setAntenna(Rx, 1, LNAL)
[INFO] SoapyLMS7::setAntenna(Tx, 1, BAND1)
[INFO] SoapyLMS7::setGain(Rx, 1, PGA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 1, LNA, 0 dB)
[INFO] SoapyLMS7::setGain(Rx, 1, TIA, 0 dB)
[INFO] SoapyLMS7::setGain(Tx, 1, PAD, -50 dB)
[INFO] SoapyLMS7::setSampleRate(Rx, 1, 10 MHz), CGEN=80 MHz, ADC=20 MHz, decim=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=20MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=182, N=7, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 100.4 (steps 58)
[INFO] SoapyLMS7::setSampleRate(Tx, 1, 10 MHz), CGEN=80 MHz, DAC=20 MHz, interp=2
ConnectionSTREAM::ConfigureFPGA_PLL(tx=10MHz, rx=10MHz)
----- FPGA PLL #1 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 114.2 (steps 132)
----- FPGA PLL #0 CONFIG -----
M=156, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 95.2 (steps 110)
[INFO] SoapyLMS7::setBandwidth(Rx, 1, 30 MHz)
[INFO] Rx Filter calibrated from cache
[INFO] SoapyLMS7::setBandwidth(Tx, 1, 30 MHz)
[INFO] Tx Filter calibrated from cache
[INFO] SoapyLMS7::setSampleRate(Rx, 0, 8 MHz), CGEN=512 MHz, ADC=128 MHz, decim=16
CGEN: Freq=512 MHz, VCO=2.048 GHz, INT=65, FRAC=699050, DIV_OUTCH_CGEN=1
ConnectionSTREAM::ConfigureFPGA_PLL(tx=8MHz, rx=8MHz)
----- FPGA PLL #1 CONFIG -----
M=195, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 109.4 (steps 158)
----- FPGA PLL #0 CONFIG -----
M=195, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 94.2 (steps 136)
[INFO] SoapyLMS7::setFrequency(Rx, 0, RF, 915 MHz)
SetFrequency using cache values vco:2, csw:181
[WARNING] GetDC_IQ_Interp(915 MHz, ch=0, tx=0): no matches between [914, 916] MHz
[INFO] SoapyLMS7::setFrequency(Rx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setGain(Rx, 0, LNA, 20 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, TIA, 2 dB)
[INFO] SoapyLMS7::setGain(Rx, 0, PGA, 2 dB)
[INFO] SoapyLMS7::setAntenna(Rx, 0, LNAL)
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in sink types: uhd hackrf bladerf soapy redpitaya file 
[INFO] SoapyLMS7::setSampleRate(Tx, 0, 0.5 MHz), CGEN=64 MHz, DAC=16 MHz, interp=32
CGEN: Freq=64 MHz, VCO=2.432 GHz, INT=78, FRAC=174761, DIV_OUTCH_CGEN=18
ConnectionSTREAM::ConfigureFPGA_PLL(tx=0.5MHz, rx=8MHz)
----- FPGA PLL #1 CONFIG -----
M=195, N=3, Fvco=1040.000 MHz
Configured phase: 0.0 (steps 0)
Configured phase: 109.4 (steps 158)
[INFO] SoapyLMS7::setFrequency(Tx, 0, RF, 915 MHz)
SetFrequency using cache values vco:2, csw:182
[WARNING] GetDC_IQ_Interp(915 MHz, ch=0, tx=1): no matches between [914, 916] MHz
[INFO] SoapyLMS7::setFrequency(Tx, 0, BB, 0 MHz)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, 10 dB)
[INFO] SoapyLMS7::setGain(Tx, 0, PAD, 5 dB)
[INFO] SoapyLMS7::setAntenna(Tx, 0, BAND1)
Warning popping from TX, samples popped 162/1360
L 1392640
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 483/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 949/1360
Tx: 0.177 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 695/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.063 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 1255/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.093 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.224 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 1344/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.058 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.500 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.084 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.508 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.503 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.519 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 1044/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Tx: 1.133 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.516 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.507 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.093 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 695/1360
Warning popping from TX, samples popped 0/1360
Tx: 1.221 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.494 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.513 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.506 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.093 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.481 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 670/1360
Warning popping from TX, samples popped 0/1360
Tx: 1.199 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.494 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.504 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 402/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.220 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.507 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.487 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 994/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 1179/1360
Warning popping from TX, samples popped 0/1360
Tx: 0.934 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.093 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.511 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 855/1360
Warning popping from TX, samples popped 0/1360
Tx: 1.208 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.508 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.506 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.510 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.503 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Tx: 1.500 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 828/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 981/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 552/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Tx: 0.522 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 540/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 540/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Rx: 24.093 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 552/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Tx: 0.080 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
Warning popping from TX, samples popped 528/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 528/1360
Rx: 24.117 MB/s, Fs: 0.000 MHz, overrun: 0, loss: 0 
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 0/1360
Warning popping from TX, samples popped 552/1360
Warning popping from TX, samples popped 0/1360

 --------------------------
| Number of queries/queryreps sent : 2388
| Current Inventory round : 2393
 --------------------------
| Correctly decoded EPC : 0
| Number of unique tags : 0
 --------------------------
Warning popping from TX, samples popped 0/1360
Tx: 0.087 MB/s, Fs: 0.000 MHz, failures: 0, ts:0
'Q' to quit 
q

 --------------------------
| Number of queries/queryreps sent : 2388
| Current Inventory round : 2393
 --------------------------
| Correctly decoded EPC : 0
| Number of unique tags : 0
 --------------------------

 --------------------------
| Number of queries/queryreps sent : 2388
| Current Inventory round : 2393
 --------------------------
| Correctly decoded EPC : 0
| Number of unique tags : 0
 --------------------------

```

I’m honestly glad the TX actually outputs the approximately correct sample rate (1.5 MB/s which is 1/16 of 24 MB/s). Here’s the output from the filter that is connected to the receiver:per of the tag with the screaming TX, so I might have to put together a diy directional coupler for a monostatic mode or I’ll need to try more directional antennas so that it’s a more isolated bistatic mode.

I changed the number of max queries in the reader in global\_vars.h to 10000 instead of 1000 and have the following reader code below with a QT time sink, but it still is finicky if I change any of the variables, where it won’t transmit at all:

 ![](https://canada1.discourse-cdn.com/flex034/uploads/myriadrf/original/1X/309a6c2f40389b13ff91097dc6e3d617efcc9a65.png)

---

<div class="post-metadata">

### Author: ![tungstenlightbulb](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@tungstenlightbulb](https://discourse.myriadrf.org/u/tungstenlightbulb)
#### Post date: [8 June 2017 18:39 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/6 "2017-06-08T18:39:13Z")

</div>

After messing with another [RFID library](https://github.com/brunoprog64/rfid-gen2) that also claims that it works on the bladeRF, I had more popping issues. However when I pulled LimeSuite from the [osmotrx fork](https://github.com/myriadrf/LimeSuite/tree/osmotrx) (from @IgnasJ)and built it, I’m not seeing the popping error. I’m still not able to read the RFID tag completely (although it is able to acknowledge the tag sometimes) with the following file:

```
#!/usr/bin/env python
# Developed by: Michael Buettner (buettner@cs.washington.edu)
# Modified by: Bruno Espinoza (bruno.espinozaamaya@uqconnect.edu.au)
# Modified for LimeSDR by: Jordan Treiwtt (jot437@utulsa.edu)

from gnuradio import gr, gru
from PyQt4 import Qt
from gnuradio import eng_notation
from gnuradio import qtgui
from gnuradio import analog, blocks, digital, filter
from gnuradio.eng_option import eng_option
from string import split
from string import strip
from string import atoi
import time
import os
import math
import sys
import rfid
import optparse
import osmosdr
import sip

# parser for frequency and other options
parser = optparse.OptionParser();
parser.add_option('--f', action="store", dest="center_freq", default="910e6", help="Center Frequency", type="float");
parser.add_option('--g', action="store", dest="rx_gain", default="20", help="RX Gain", type="float");
parser.add_option('--l', action="store", dest="log_file", default="log_out.log", help="Log file name");
parser.add_option('--d', action="store", dest="dump_file", default="none", help="[none|matched|full]");
parser.add_option('--s', action="store", dest="device", default="uhd", help="[uhd|bladerf]");
parser.add_option('--q', action="store", dest="q_value", default="0", help="Q value from 0 to 8");
parser.add_option('--m', action="store", dest="modul_type", default="1",
                  help="Modulation Type from 0 to 3 -> 0: FM Encoding, 1: Miller M=2, 2: Miller M=4, 3: Miller M=8");
parser.add_option('--c', action="store", dest="cycles_num", default="5", help="Number of Reader Cycles (def. 5)");
parser.add_option('--r', action="store", dest="round_num", default="10", help="Number of Rounds per Cycle (def. 10)");

options, args = parser.parse_args()

log_file = open(options.log_file, "a")
dump_type = options.dump_file
mtype = int(options.modul_type)
qval = int(options.q_value)
n_cycle = int(options.cycles_num)
n_round = int(options.round_num)

if dump_type == "none":
    print "* Alert: Skipping dumping of the rx block..."
elif dump_type == "full":
    print "** Using a full dump of the RX block!!"
elif dump_type == "matched":
    print "** Using dump of the match_filter block!!"
else:
    print "Unknown dump_type flag!! Set to 'none'"
    dump_type = 'none'

if options.device == "uhd":
    print "Using USRP devices..."
else:
    print "Using bladeRF device..."

modul_msg = ["FM0", "Miller M=2", "Miller M=4", "Miller M=8"];

if mtype > 3 or mtype < 0:
    mtype = 1;

if (qval > 8 or qval < 0):
    qval = 0

slots = pow(2, qval);

print "* Using", modul_msg[mtype], "modulation for tags..."
print "* Q Value of", str(qval), "so", str(slots), "slots assigned for tags..."
print "* Reader using", str(n_cycle), "cycles with", str(n_round), "rounds per cycle..."

class my_top_block(gr.top_block, Qt.QWidget):
    def __init__ (self):
        gr.top_block. __init__ (self)
        Qt.QWidget. __init__ (self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        # Constants

        amplitude = 5000
        sw_dec = 5 # For reduce the sample rate after the filtering. (4MS / 5 = 800 KS/s)
        samp_rate = 4e6 # corresponds to dec_rate 16. (64M/16)
        tx_sample = .5e6

        # Filter mathced to 1/4 of 40 KHz tag cycle.
        # 40 KHz = 100 samples, so 1/4 is 25 samples.
        # num_taps = int(64000 / ( (dec_rate * 4) * 40 )) #Filter matched to 1/4 of the 40 kHz tag cycle
        num_taps = 25
        taps = [complex(1, 1)] * num_taps

        # Blocks

        matched_filt = filter.fir_filter_ccc(sw_dec, taps);

        agc = analog.agc2_cc(0.3, 1e-3, 1, 1)
        agc.set_max_gain(100)

        to_mag = blocks.complex_to_mag()
        center = rfid.center_ff(10)

        omega = 5
        mu = 0.25
        gain_mu = 0.25
        gain_omega = .25 * gain_mu * gain_mu
        omega_relative_limit = .05

        # clock recovery
        mm = digital.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit)

        mtype = int(options.modul_type)
        qval = int(options.q_value)

        if (mtype > 3 or mtype < 0):
            mtype = 1 # Miller M=2 by default

        # qval = int(options.q_value)
        if qval > 8 or qval < 0:
            qval = 0;

        n_cycle = int(options.cycles_num)
        n_round = int(options.round_num)

        self.reader = rfid.reader_f(int(tx_sample), mtype, qval, n_cycle, n_round)
        tag_decoder = rfid.tag_decoder_f()

        # The parameters for command_gate_cc are:
        # - PW: 12 us. (Negative part of the PIE pulses)
        # - T1: 250 us (Maximium timeout for the tag to reply).
        # - Sample Rate. (800 KS/s after the matched filter)
        command_gate = rfid.command_gate_cc(12, 250, int(800e3)) # 800 KS/s.
        dc_block = filter.dc_blocker_cc(64, True)

        to_complex = blocks.float_to_complex()
        amp = blocks.multiply_const_ff(amplitude)
        # TX
        freq = options.center_freq # 915e6
        rx_gain = options.rx_gain # 20
        if (options.device == "uhd"):
            tx = osmosdr.sink("uhd,type=usrp1")
            tx.set_gain(0, 'DAC-pga') # range -20 to 0.
            tx.set_antenna('TX/RX')
        else:
            # LimeSDR
            tx = osmosdr.sink(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0')
            tx.set_gain(30, 0)
            tx.set_if_gain(10, 0)
            tx.set_bb_gain(10, 0)
            tx.set_antenna("BAND1", 0)
            tx.set_bandwidth(0, 1000000)

            # Settings for Backscatter = VGA1 = -4 / VGA2 = 20

        tx.set_sample_rate(tx_sample)
        tx.set_center_freq(freq)

        if not tx:
            print "Couldn't set tx freq"

        # End TX

        # RX
        if (options.device == "uhd"):
            rx = osmosdr.source("uhd,type=usrp1")
            rx.set_gain(20, 'PGA0')
            rx.set_gain(15, 'ADC-pga')
            rx.set_antenna('RX2')
        else:
            # LimeSDR
            rx = osmosdr.source(args="numchan=" + str(1) + " " + 'driver=lime,soapy=0')
            rx.set_gain_mode(False, 0)
            rx.set_gain(20, 0)
            rx.set_if_gain(10, 0)
            rx.set_bb_gain(10, 0)
            rx.set_antenna("LNAL", 0)
            rx.set_bandwidth(0, 6000000)

        rx.set_sample_rate(samp_rate)
        rx.set_center_freq(freq)
        # rx.set_iq_balance_mode(0, 0)
        # rx.set_dc_offset_mode(0, 0)

        if not rx:
            print "Couldn't set rx freq"

        # End RX
        command_gate.set_ctrl_out(self.reader.ctrl_q())
        tag_decoder.set_ctrl_out(self.reader.ctrl_q())

        # QT setup

        self.qtgui_time_sink = qtgui.time_sink_c(
            1024, # size
            samp_rate, # samp_rate
            "", # name
            1 # number of inputs
        )
        self.qtgui_time_sink.set_update_time(0.10)
        self.qtgui_time_sink.set_y_axis(-5, 5)

        self.qtgui_time_sink.set_y_label('Amplitude', "")

        self.qtgui_time_sink.enable_tags(-1, True)
        self.qtgui_time_sink.set_trigger_mode(qtgui.TRIG_MODE_AUTO, qtgui.TRIG_SLOPE_POS, 1, 0, 0, "")
        self.qtgui_time_sink.enable_autoscale(False)
        self.qtgui_time_sink.enable_grid(False)
        self.qtgui_time_sink.enable_axis_labels(True)
        self.qtgui_time_sink.enable_control_panel(True)

        if not True:
            self.qtgui_time_sink.disable_legend()

        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]

        for i in xrange(2 * 1):
            if len(labels[i]) == 0:
                if (i % 2 == 0):
                    self.qtgui_time_sink.set_line_label(i, "Re{{Data {0}}}".format(i / 2))
                else:
                    self.qtgui_time_sink.set_line_label(i, "Im{{Data {0}}}".format(i / 2))
            else:
                self.qtgui_time_sink.set_line_label(i, labels[i])
            self.qtgui_time_sink.set_line_width(i, widths[i])
            self.qtgui_time_sink.set_line_color(i, colors[i])
            self.qtgui_time_sink.set_line_style(i, styles[i])
            self.qtgui_time_sink.set_line_marker(i, markers[i])
            self.qtgui_time_sink.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_win = sip.wrapinstance(self.qtgui_time_sink.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_win)

        #########Build Graph
        self.connect(rx, dc_block)
        self.connect(dc_block, matched_filt)
        self.connect(matched_filt, self.qtgui_time_sink)
        self.connect(matched_filt, command_gate)
        self.connect(command_gate, agc)
        self.connect(agc, to_mag)
        self.connect(to_mag, center, mm, tag_decoder)
        self.connect(tag_decoder, self.reader, amp, to_complex, tx)
        #################

        # Output dumps for debug

        # self.connect(to_complex, f_txout);
        if dump_type == "matched":
            f_rxout = blocks.file_sink(gr.sizeof_gr_complex, 'f_rxout.out');
            self.connect(matched_filt, f_rxout)
            # f_rxout = blocks.file_sink(gr.sizeof_float, 'f_rxout.out');
            # self.connect(mm, f_rxout)

        if dump_type == "full":
            f_rxout = blocks.file_sink(gr.sizeof_gr_complex, 'f_rxout.out');
            self.connect(rx, f_rxout)

    def closeEvent(self, event):
        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.settings.setValue("geometry", self.saveGeometry())
        event.accept()

def main():
    from distutils.version import StrictVersion

    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
        Qt.QApplication.setGraphicsSystem(style)
    qapp = Qt.QApplication(sys.argv)

    tb = my_top_block()

    tb.start()
    tb.show()

    qapp.exec_()

    while 1:

        c = raw_input("'Q' to quit. L to get log.\n")
        if c == "q":
            break

        if c == "L" or c == "l":
            log_file.write("T,CMD,ERROR,BITS,SNR\n")
            log = tb.reader.get_log()
            print "Log has %s Entries" % (str(log.count()))
            i = log.count();

            for k in range(0, i):
                msg = log.delete_head_nowait()
                print_log_msg(msg, log_file)

    tb.stop()

def print_log_msg(msg, log_file):
    LOG_START_CYCLE, LOG_QUERY, LOG_ACK, LOG_QREP, LOG_NAK, LOG_REQ_RN, LOG_READ, LOG_RN16, LOG_EPC, LOG_HANDLE, LOG_DATA, LOG_EMPTY, LOG_COLLISION, LOG_OKAY, LOG_ERROR = range(
        15)

    fRed = chr(27) + '[31m'
    fBlue = chr(27) + '[34m'
    fReset = chr(27) + '[0m'

    if msg.type() == LOG_START_CYCLE:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t Started Cycle" % (fields[-1])
        log_file.write(fields[-1] + ",START_CYCLE,0,0,0\n");

    if msg.type() == LOG_QUERY:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t Query" % (fields[-1])
        log_file.write(fields[-1] + ",QUERY,0,0,0\n");

    if msg.type() == LOG_QREP:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t QRep" % (fields[-1])
        log_file.write(fields[-1] + ",QREP,0,0,0\n");

    if msg.type() == LOG_ACK:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t ACK" % (fields[-1])
        log_file.write(fields[-1] + ",ACK,0,0,0\n");

    if msg.type() == LOG_NAK:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t NAK" % (fields[-1])
        log_file.write(fields[-1] + ",NAK,0,0,0\n");

    if msg.type() == LOG_RN16:
        fields = split(strip(msg.to_string()), " ")
        rn16 = fields[0].split(",")[0]
        snr = strip(fields[0].split(",")[1])
        tmp = int(rn16, 2)

        if msg.arg2() == LOG_ERROR:

            print "%s\t %s RN16 w/ Error: %04X%s" % (fields[-1], fRed, tmp, fReset)
            log_file.write(fields[-1] + ",RN16,1," + "%04X" % tmp + "," + snr + "\n");
        else:
            print "%s\t %s RN16: %04X%s" % (fields[-1], fBlue, tmp, fReset)
            log_file.write(fields[-1] + ",RN16,0," + "%04X" % tmp + "," + snr + "\n");

    if msg.type() == LOG_EPC:
        fields = split(strip(msg.to_string()), " ")
        epc = fields[0].split(",")[0]
        snr = strip(fields[0].split(",")[1])
        epc = epc[16:112]

        tmp = int(epc, 2)
        if msg.arg2() == LOG_ERROR:
            print "%s\t %s EPC w/ Error: %024X%s" % (fields[-1], fRed, tmp, fReset)
            log_file.write(fields[-1] + ",EPC,1," + "%024X" % tmp + "," + snr + "\n");
        else:
            print "%s\t %s EPC: %024X%s" % (fields[-1], fBlue, tmp, fReset)
            log_file.write(fields[-1] + ",EPC,0," + "%024X" % tmp + "," + snr + "\n");

    if msg.type() == LOG_EMPTY:
        fields = split(strip(msg.to_string()), " ")
        snr = strip(fields[0])
        print "%s\t - Empty Slot - " % (fields[-1])
        log_file.write(fields[-1] + ",EMPTY,0,0," + snr + "\n");

    if msg.type() == LOG_COLLISION:
        fields = split(strip(msg.to_string()), " ")
        print "%s\t - Collision - " % (fields[-1])
        log_file.write(fields[-1] + ",COLLISION,0,0,0\n");

if __name__ == ' __main__':
    main()

```

With the following output:

```
logic@logic-ThinkPad-X260:~/PycharmProjects/LimeReader$ python LimeReader2.py --s akdf --r 100 --c 100 --m 8
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release

* Alert: Skipping dumping of the rx block...
Using bladeRF device...
* Using Miller M=2 modulation for tags...
* Q Value of 0 so 1 slots assigned for tags...
* Reader using 100 cycles with 100 rounds per cycle...
us Per Sample: 1.250000 Num samples per pulse:9 T1:200
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in sink types: uhd hackrf bladerf soapy redpitaya file 
[INFO] Make connection: 'LimeSDR-USB [USB 2.0] 9060A02592E12'
[INFO] Estimated reference clock 30.7197 MHz
[INFO] Selected reference clock 30.720 MHz
[INFO] Device name: LimeSDR-USB
[INFO] Reference: 30.72 MHz
[INFO] Init LMS7002M(0)
[INFO] LMS7002M cache /home/logic/.limesuite/LMS7002M_cache_values.db
[INFO] Ver=7, Rev=1, Mask=1
[INFO] LMS7002M calibration values caching Enable
[INFO] Rx Filter calibrated from cache
[INFO] Tx Filter calibrated from cache
[INFO] Rx Filter calibrated from cache
[INFO] Tx Filter calibrated from cache
SetFrequency using cache values vco:2, csw:175
gr-osmosdr v0.1.x-xxx-xunknown (0.1.5git) gnuradio 3.7.10
built-in source types: file osmosdr fcd rtl rtl_tcp uhd miri hackrf bladerf rfspace airspy soapy redpitaya 
SetFrequency using cache values vco:2, csw:173
############################################################
Tx calibration values found in cache:
   | DC | GAIN | PHASE
---+-----+------+------
I: | 626 | 1974 | -17
Q: | 114 | 2047 |
############################################################
############################################################
Rx calibration using RSSI INTERNAL ON BOARD loopback
Rx ch.A @ 910 MHz, BW: 30 MHz, RF input: LNAL, PGA: 22, LNA: 4, TIA: 1
Rx calibration: using cached values
Rx calibration values found in cache:
   | DC | GAIN | PHASE
---+-----+------+------
I: | 0 | 2047 | 0
Q: | 0 | 2047 |
############################################################
Timer fired starting cycle
Timer fired starting cycle
[INFO] L
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 10
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
[INFO] L
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 20
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 30
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 40
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 50
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Starting cycle 60
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
Timer fired starting cycle
'Q' to quit. L to get log.
Timer fired starting cycle
Starting cycle 70
Timer fired starting cycle
Timer fired starting cycle
lTimer fired starting cycle

Log has 479 Entries
66804.589 Started Cycle
66804.589 Query
66804.636 Started Cycle
66804.636 Query
66805.137 Started Cycle
66805.137 Query
66805.637 Started Cycle
66805.637 Query
66806.136 Started Cycle
66806.136 Query
66806.637 Started Cycle
66806.637 Query
66807.136 Started Cycle
66807.136 Query
66807.637 Started Cycle
66807.637 Query
66808.137 Started Cycle
66808.137 Query
66808.576 - Empty Slot - 
66808.576 Query
66808.636 Started Cycle
66808.636 Query
66808.837 - Empty Slot - 
66808.837 Query
66809.137 Started Cycle
66809.137 Query
66809.152 - Empty Slot - 
66809.152 Query
66809.442 - Empty Slot - 
66809.442 Query
66809.619 - Empty Slot - 
66809.619 Query
66809.637 Started Cycle
66809.637 Query
66810.136 Started Cycle
66810.136 Query
66810.637 Started Cycle
66810.637 Query
66811.136 Started Cycle
66811.136 Query
66811.618 - Empty Slot - 
66811.618 Query
66811.636 Started Cycle
66811.636 Query
66811.799 - Empty Slot - 
66811.799 Query
66811.879 - Empty Slot - 
66811.879 Query
66811.883 RN16: E856
66811.883 ACK
66812.137 Started Cycle
66812.137 Query
66812.553 - Empty Slot - 
66812.553 Query
66812.636 Started Cycle
66812.636 Query
66812.667 - Empty Slot - 
66812.667 Query
66812.784 - Empty Slot - 
66812.785 Query
66812.838 - Empty Slot - 
66812.838 Query
66812.935 - Empty Slot - 
66812.935 Query
66812.963 - Empty Slot - 
66812.963 Query
66813.067 - Empty Slot - 
66813.067 Query
66813.136 Started Cycle
66813.136 Query
66813.144 - Empty Slot - 
66813.144 Query
66813.250 - Empty Slot - 
66813.250 Query
66813.262 - Empty Slot - 
66813.262 Query
66813.393 - Empty Slot - 
66813.393 Query
66813.420 - Empty Slot - 
66813.420 Query
66813.506 - Empty Slot - 
66813.506 Query
66813.555 - Empty Slot - 
66813.555 Query
66813.625 - Empty Slot - 
66813.625 Query
66813.637 Started Cycle
66813.637 Query
66814.136 Started Cycle
66814.136 Query
66814.563 - Empty Slot - 
66814.563 Query
66814.577 - Empty Slot - 
66814.577 Query
66814.628 - Empty Slot - 
66814.628 Query
66814.636 Started Cycle
66814.636 Query
66814.681 - Empty Slot - 
66814.681 Query
66814.715 - Empty Slot - 
66814.715 Query
66814.740 - Empty Slot - 
66814.740 Query
66814.804 RN16 w/ Error: 0980
66814.804 Query
66814.922 - Empty Slot - 
66814.922 Query
66814.941 - Empty Slot - 
66814.941 Query
66815.014 - Empty Slot - 
66815.014 Query
66815.039 - Empty Slot - 
66815.039 Query
66815.137 Started Cycle
66815.137 Query
66815.188 - Empty Slot - 
66815.188 Query
66815.636 Started Cycle
66815.636 Query
66815.720 - Empty Slot - 
66815.720 Query
66815.800 - Empty Slot - 
66815.800 Query
66815.965 - Empty Slot - 
66815.965 Query
66816.137 Started Cycle
66816.137 Query
66816.397 - Empty Slot - 
66816.397 Query
66816.637 Started Cycle
66816.637 Query
66817.136 Started Cycle
66817.136 Query
66817.170 - Empty Slot - 
66817.170 Query
66817.577 - Empty Slot - 
66817.577 Query
66817.636 Started Cycle
66817.636 Query
66817.680 - Empty Slot - 
66817.680 Query
66817.817 - Empty Slot - 
66817.817 Query
66817.937 - Empty Slot - 
66817.937 Query
66818.059 - Empty Slot - 
66818.059 Query
66818.136 Started Cycle
66818.136 Query
66818.297 - Empty Slot - 
66818.297 Query
66818.439 - Empty Slot - 
66818.439 Query
66818.636 Started Cycle
66818.636 Query
66818.651 - Empty Slot - 
66818.651 Query
66818.679 - Empty Slot - 
66818.679 Query
66819.137 Started Cycle
66819.137 Query
66819.637 Started Cycle
66819.637 Query
66820.136 Started Cycle
66820.136 Query
66820.637 Started Cycle
66820.637 Query
66821.136 Started Cycle
66821.136 Query
66821.637 Started Cycle
66821.637 Query
66821.789 - Empty Slot - 
66821.789 Query
66822.138 Started Cycle
66822.138 Query
66822.571 - Empty Slot - 
66822.571 Query
66822.574 - Empty Slot - 
66822.574 Query
66822.636 Started Cycle
66822.636 Query
66822.689 - Empty Slot - 
66822.689 Query
66822.695 - Empty Slot - 
66822.695 Query
66822.701 - Empty Slot - 
66822.701 Query
66822.806 - Empty Slot - 
66822.806 Query
66822.822 - Empty Slot - 
66822.822 Query
66822.830 - Empty Slot - 
66822.830 Query
66822.896 - Empty Slot - 
66822.896 Query
66822.900 - Empty Slot - 
66822.900 Query
66823.039 - Empty Slot - 
66823.039 Query
66823.079 - Empty Slot - 
66823.079 Query
66823.080 - Empty Slot - 
66823.080 Query
66823.089 - Empty Slot - 
66823.089 Query
66823.136 Started Cycle
66823.136 Query
66823.637 Started Cycle
66823.637 Query
66824.137 Started Cycle
66824.137 Query
66824.341 - Empty Slot - 
66824.341 Query
66824.351 - Empty Slot - 
66824.351 Query
66824.364 - Empty Slot - 
66824.364 Query
66824.396 - Empty Slot - 
66824.396 Query
66824.461 - Empty Slot - 
66824.461 Query
66824.476 - Empty Slot - 
66824.476 Query
66824.480 - Empty Slot - 
66824.480 Query
66824.485 - Empty Slot - 
66824.486 Query
66824.627 - Empty Slot - 
66824.627 Query
66824.632 - Empty Slot - 
66824.632 Query
66824.637 Started Cycle
66824.637 Query
66824.652 - Empty Slot - 
66824.652 Query
66824.741 - Empty Slot - 
66824.741 Query
66824.747 - Empty Slot - 
66824.747 Query
66824.756 - Empty Slot - 
66824.756 Query
66825.137 Started Cycle
66825.137 Query
66825.151 - Empty Slot - 
66825.151 Query
66825.636 Started Cycle
66825.636 Query
66825.653 - Empty Slot - 
66825.653 Query
66825.895 - Empty Slot - 
66825.895 Query
66825.931 - Empty Slot - 
66825.931 Query
66826.040 - Empty Slot - 
66826.040 Query
66826.139 Started Cycle
66826.139 Query
66826.139 - Empty Slot - 
66826.139 Query
66826.179 - Empty Slot - 
66826.179 Query
66826.400 - Empty Slot - 
66826.400 Query
66826.523 - Empty Slot - 
66826.523 Query
66826.636 Started Cycle
66826.636 Query
66826.766 - Empty Slot - 
66826.766 Query
66826.826 - Empty Slot - 
66826.826 Query
66826.846 - Empty Slot - 
66826.846 Query
66827.136 Started Cycle
66827.136 Query
66827.211 - Empty Slot - 
66827.211 Query
66827.251 - Empty Slot - 
66827.251 Query
66827.255 - Empty Slot - 
66827.255 Query
66827.258 - Empty Slot - 
66827.258 Query
66827.474 RN16: D0DC
66827.474 ACK
66827.492 EPC w/ Error: A030B048433200C606019D46
66827.492 NAK
66827.492 Query
66827.503 - Empty Slot - 
66827.503 Query
66827.507 - Empty Slot - 
66827.507 Query
66827.540 - Empty Slot - 
66827.540 Query
66827.579 RN16 w/ Error: D0F0
66827.579 Query
'Q' to quit. L to get log.

```

Again I probably need to add filters to the TX, but at least it’s able to ACK the RN.

---

<div class="post-metadata">

### Author: ![DasSidG](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DasSidG](https://discourse.myriadrf.org/u/DasSidG)
#### Post date: [5 November 2017 20:34 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/7 "2017-11-05T20:34:43Z")

</div>

Hi tungstenlightbulb,

I’m currently also trying to get LimeSDR working with RFID through GNU Radio; just wondering if you had made any further progress/observations since the above discussion? I’m going to try out some of what you’ve tried above tomorrow.

---

<div class="post-metadata">

### Author: ![tungstenlightbulb](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@tungstenlightbulb](https://discourse.myriadrf.org/u/tungstenlightbulb)
#### Post date: [17 November 2017 05:01 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/8 "2017-11-17T05:01:57Z")

</div>

Sorry I haven’t gotten back to you. I haven’t tried the library in months and the last time I used it I was only receiving partial reads as detailed in that latest post. I should probably try it again to see if any of the newer firmware updates fixed anything, but I was talking to another more experienced SDR programmer and he was saying that this type of issue could commonly be fixed if you add a delay right after the source in order to fix some of the buffering problems. I have yet to try that, so I can’t really say.

Have you had any success so far with your current configuration?

---

<div class="post-metadata">

### Author: ![DasSidG](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DasSidG](https://discourse.myriadrf.org/u/DasSidG)
#### Post date: [17 November 2017 13:10 UTC](https://discourse.myriadrf.org/t/rfid-library-issues-popping-from-tx/1291/9 "2017-11-17T13:10:39Z")

</div>

So the stage I’m at currently is that I can get the LimeSDR to transmit the query, and the tag successfully responds with the RN16. After that however, there is a long delay (~7ms) before the LimeSDR attempts to reply with an ACK, and so the tag stops listening (at the 40 kHz BLF we’re using the reader needs to start responding within 500 us), so the communication stops there. See the figure below.

I’ve been using the same [Gen 2 UFH RFID library](https://github.com/nikosl21/Gen2-UHF-RFID-Reader) that you were trying originally, but I never seemed to get the TX popping issues that you mentioned above. I also used the same code that you originally posted (with some slight modifications to put back in the other file sink blocks and change the file locations slightly).

I don’t seem to get nearly as much output on my screen as you do; this is all I get when I run the script:

```
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.002.000-3-g122bfae1

gr-osmosdr v0.1.4-98-gc653754d (0.1.5git) gnuradio 3.7.11.1
built-in source types: file fcd rtl rtl_tcp uhd hackrf bladerf rfspace airspy soapy redpitaya 
[INFO] Make connection: 'LimeSDR-USB [USB 3.0] 9062000C41E13'
[INFO] Reference clock 30.720 MHz
[INFO] Device name: LimeSDR-USB
[INFO] Reference: 30.72 MHz
[INFO] Init LMS7002M(0)
[INFO] Ver=7, Rev=1, Mask=1
[INFO] LMS7002M calibration values caching Disable
gr-osmosdr v0.1.4-98-gc653754d (0.1.5git) gnuradio 3.7.11.1
built-in sink types: uhd hackrf bladerf soapy redpitaya file 
'Q' to quit 
[INFO] L
q

 --------------------------
| Number of queries/queryreps sent : 8
| Current Inventory round : 9
 --------------------------
| Correctly decoded EPC : 0
| Number of unique tags : 0
 --------------------------

```

Is there some kind of logging parameter that I need to enable somewhere to get the more verbose output? The output pauses at ‘[INFO] L’ until either I press q or it tries 1000 attempts (as defined in global\_vars.h), which takes about 20 minutes.

 ![7_ms_delay_pic](https://yyz2.discourse-cdn.com/flex034/uploads/myriadrf/original/2X/9/9c62901466617683c5fb316c3175b9489c543bfa.png)

With regards to the latency issue, I suspect it’s to do with the USB transfer packet size - see the post I just made [here](https://discourse.myriadrf.org/t/reducing-usb3-latency-for-rfid-reader-application/2021) for more specific details.

I also seem to get a weird unwanted sawtooth waveform in the RX, the frequency of which is affected by the sampling rate; it this something you’ve experienced? More detailed post is [here](https://discourse.myriadrf.org/t/discontinuities-in-rx-signal/1838/23) ; the picture shown above is taken in the first 50ms or so of the signal where the sawtooth hasn’t started up yet.

Thanks,

DasSidG
