Advertisement
Guest User

File Source

a guest
May 6th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import numpy as np
  2. from gnuradio import gr
  3. import pmt
  4. import threading
  5.  
  6. class blk(gr.basic_block):
  7.     def __init__(self):  # only default arguments here
  8.         gr.basic_block.__init__(
  9.             self,
  10.             name='File Source',    
  11.             in_sig=None,          
  12.             out_sig=None)      
  13.         # create an output port  
  14.         self.message_port_register_out(pmt.intern('out'))
  15.         # Start a thread
  16.         self.do_exit = threading.Event()
  17.         self.thread = threading.Thread(target = self.callback)
  18.         self.thread.start()
  19.  
  20.     def callback(self):
  21.         while not self.do_exit.is_set():
  22.             # read file
  23.             arr = np.fromfile("data.dat", dtype=np.complex64)
  24.             # output file on msg port "out"
  25.             self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.make_dict(), pmt.to_pmt(arr)))
  26.             print("File Source done")
  27.             # close the thread
  28.             self.do_exit.set()
  29.         return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement