# Problems closing a valve block with a Python Block

**URL:** <https://www.ruby-forum.com/t/problems-closing-a-valve-block-with-a-python-block/243297>\
**Category:** GNU Radio\
**Created:** [September 8, 2015, 7:15pm UTC](https://www.ruby-forum.com/t/problems-closing-a-valve-block-with-a-python-block/243297 "2015-09-08T19:15:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [September 8, 2015, 7:15pm UTC](https://www.ruby-forum.com/t/problems-closing-a-valve-block-with-a-python-block/243297/1 "2015-09-08T19:15:39Z")

</div>

Hello:  
We have successfully used a GUI block to open (or close) a valve by  
pressing the mouse button.  
Now we want to open (or close) the valve from a Python block that we  
are writing after comparing two messages. If the messages are the same,  
we want to open the valve, otherwise the valve should remain closed.

Below is the xml definition of our Python block as well as the Python  
code. The problem we are having is that GRC does not allow us to compile  
the code. The variable beacon\_tx is not recognized by the valve block.

Can somebody help u with this issue?

Thanks.

XML FILE

* * *
\<?xml version="1.0"?\> compare conditions\_compare conditions import conditions conditions.compare() in int 

beacon\_tx  
in  
int

* * *

PYTHON CODE

* * *

import numpy  
import smbus  
import time  
import subprocess  
beacon\_tx  
from gnuradio import gr

class compare(gr.sync\_block):  
“”"  
docstring for block compare  
“”"  
def **init** (self):  
gr.sync\_block. **init** (self,  
name=“compare”,beacon\_tx  
in\_sig=[numpy.int,numpy.int],beacon\_tx  
out\_sig=None)

```
def work(self, input_items, output_items):
    in0 = input_items[0]
    in1 = input_items[1]

    if numpy.array_equal(in0,in1):
        self.beacon_tx = True
        pr.sync_block):
"""
docstring for block compare
"""
def __init__ (self):
    gr.sync_block. __init__ (self,
        name="compare",
        in_sig=[numpy.int,numpy.int],
        out_sig=None)

def work(self, input_items, output_items):
    in0 = input_items[0]
    in1 = input_items[1]

    if numpy.array_equal(in0,in1):
        self.beacon_tx = True
        print True
    else:
        self.beacon_tx = False
        print False
    # <+signal processing here+>
    return len(self.beacon_tx)
```
