Hi all,
I am working on developing a OOT module. It is a source block which reads
the data from a virtual usb com port.

This block is connected to a file sink through a throttle block
______________       _________         _____________
|             |     |         |       |             |
|usb read OOT |-----| Throttle|-------| File sink   |
|_____________|     |_________|       |_____________|

The problem here is that the file sink is not writing the data to the file
or may be usb read OOT is not sending the data fine.

Below is code in brief:
rx_work is a thread that is spawned in the __init__ function. This thread
reads the USB com port and puts into into a buffer guarded with a mutex.
This data is then copied to output_items[0] whenever the scheduler calls
the work() function.
Note:
Data from USB is pretty slow. Approximately, 2 data items per second.

In the work() function, I acquire the mutex and then copy the self.buff
contents to output_items[0] array. I make sure i return only the number of
items that were actually copied.

def __init__(self,
device,parity,baudrate,stopbits,bytesize,wait_for_newline):

gr.sync_block.__init__(self,

name="usb_com_read",

in_sig=None,

out_sig=[numpy.int32])

"""

code to initialise serial port and create self.buff

"""


def rx_work(self, buff, buff_lock, ser):

"""
Lock mutex
read from the serial port.
write the data into self.buff[]
Unlock mutex
"""


def work(self, input_items, output_items):

# Acquire the lock
# copy buffer to out
# delete the self.buff contents
# Release the lock


out = output_items[0]
out_len = len(out)
buff_len = len(self.buff)
# take care of overflow
if out_len < buff_len:
copy_len = out_len
else:
copy_len = buff_len
with self.buff_lock:
out[0:copy_len] = self.buff[0:copy_len]

# debug prints
if copy_len:
print(self.buff[:])
print(out[:copy_len])
# empty the buffer
del self.buff[:]
return copy_len
# return len(out)


Debugging done:
In the work() function, I have verified that the data is indeed avaiable in
self.buff and also in output_items[0] after the copy is done.
If I return the len(output_items[0]), the file is getting updated with
zeroes rapidly and the file size is increasing rapidly.
Also, not sure if the throttle block is required here. Data rate from USB
is pretty slow.

References found:
https://lists.gnu.org/archive/html/discuss-gnuradio/2012-07/msg00217.html

Needed some help badly on debugging this.

Regards,
Pradeep M C
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to