diff options
author | manojgudi | 2014-02-07 16:23:36 +0530 |
---|---|---|
committer | manojgudi | 2014-02-07 16:23:36 +0530 |
commit | 9f1489439f891a5c82b3d48999d70ac64a592488 (patch) | |
tree | 4d7216b031a56bdf76862ef80a4b9f868662df0a /gr-serial/python | |
parent | 324438b65f3a2c58227fb0a304ba36e57a8a1b01 (diff) | |
download | gnuradio-9f1489439f891a5c82b3d48999d70ac64a592488.tar.gz gnuradio-9f1489439f891a5c82b3d48999d70ac64a592488.tar.bz2 gnuradio-9f1489439f891a5c82b3d48999d70ac64a592488.zip |
Made Serial block as Hierarchical Block with Constant Source embedded
Diffstat (limited to 'gr-serial/python')
-rw-r--r-- | gr-serial/python/CMakeLists.txt | 8 | ||||
-rw-r--r-- | gr-serial/python/gr_serial.py | 57 | ||||
-rw-r--r-- | gr-serial/python/ser_functions.py | 45 |
3 files changed, 71 insertions, 39 deletions
diff --git a/gr-serial/python/CMakeLists.txt b/gr-serial/python/CMakeLists.txt index e0f33d9b1..71f19c9c3 100644 --- a/gr-serial/python/CMakeLists.txt +++ b/gr-serial/python/CMakeLists.txt @@ -34,6 +34,14 @@ GR_PYTHON_INSTALL( COMPONENT "serial_python" ) +GR_PYTHON_INSTALL( + FILES + ser_functions.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/serial + COMPONENT "serial_python" +) + + ######################################################################## diff --git a/gr-serial/python/gr_serial.py b/gr-serial/python/gr_serial.py index 00b70c0d8..a7c60469e 100644 --- a/gr-serial/python/gr_serial.py +++ b/gr-serial/python/gr_serial.py @@ -1,45 +1,24 @@ -#!/usr/bin/python - import gras import numpy -# Serial is imported in __init__ -class ser(gras.Block): - +from gnuradio import gr +from gnuradio import blocks - def __init__(self): - gras.Block.__init__(self, - name="ser", - in_sig=[numpy.float32], - out_sig=[numpy.float32]) - self.n = 1 - def set_parameters(self, port, baud, bytesize, parity, stopbits): - - try: - print port - self.ser_obj = serial.Serial(port, baud, bytesize, parity, stopbits) - print("serial found on " + port ) - self.ser_obj.open() - except: - print "Couldn't Open Serial Port " + port + " Failed" - +# Source block1 import +import ser_functions +from gnuradio import blocks - def work(self, input_items, output_items): - - self.n = input_items[0][0] - out = output_items[0][:self.n] - # Input is size of output_items to be returned +class HierBlock(gr.hier_block2): + def __init__(self, port, baud, bytesize, parity, stopbits): + gr.hier_block2.__init__(self, "HierBlock", + gr.io_signature(1,1,gr.sizeof_float), + gr.io_signature(1,2,gr.sizeof_float)) - for i in range(self.n): - - # Try catch block to avoid Error - # ValueError: invalid literal for int() with base 10: '\xfe354\r\n' - try: - out[i] = int(self.ser_obj.readline()) - except: - pass - - print "OUT", out[:self.n] - - self.produce(0,len(out)) # Produce from port 0 output_items - self.consume(0,1) # Consume from port 0 input_items + # constant_block initialized + self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE,0,0,1) + # step_source block initialized + self.serial_source = ser_functions.ser() + self.serial_source.set_parameters(port, baud, bytesize, parity, stopbits) + + # Connect Block1 and Block2 + self.connect(self, (self.constant_block,0) , (self.serial_source,0), self) diff --git a/gr-serial/python/ser_functions.py b/gr-serial/python/ser_functions.py new file mode 100644 index 000000000..68ea18875 --- /dev/null +++ b/gr-serial/python/ser_functions.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +import gras +import numpy +import serial +class ser(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.n = 1 + def set_parameters(self, port, baud, bytesize, parity, stopbits): + + try: + print port + self.ser_obj = serial.Serial(port, baud, bytesize, parity, stopbits) + print("serial found on " + port ) + self.ser_obj.open() + except: + print "Couldn't Open Serial Port " + port + " Failed" + + + def work(self, input_items, output_items): + + self.n = input_items[0][0] + out = output_items[0][:self.n] + # Input is size of output_items to be returned + + for i in range(self.n): + + # Try catch block to avoid Error + # ValueError: invalid literal for int() with base 10: '\xfe354\r\n' + try: + out[i] = int(self.ser_obj.readline()) + except: + pass + + print "OUT", out[:self.n] + + self.produce(0,len(out)) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + |