Hello GNU Radio community! I am a Midshipman working on PSK31, but I have a slightly different approach than Louis Brown: I am creating a single custom block that will spawn a GUI to take keyboard input and then output the ASCII bit representation of the keystroke. I used a lot of the code for the Logitech transceiver on CGRAN as my starting point.
Right now, the user hits a submit button on the GUI which then writes any text to a file. The work function then reads through the file to determine if there is a new character to submit. Global variables are used to index progress through the file. Eventually, I want to use a better system than FIFO, but I am using this a proof of concept.
Testing my block by running it straight into a file sink, I get 32,769 copies of each character. If I add a throttle block, then I don't get any data in my file sink. My work function runs a while loop because I need something to keep the program in the work function instead of the MainLoop function of the GUI. If I call MainLoop in the __init__ function, then I never get into the work function.
Thanks for any help that you can offer!
-Matt Lanoue
MIDN USN
#Define Global Variables
last_tx = 0
size = 0
################################################################################
### GRC Block Class
################################################################################
class keyboard2_b(gr.sync_block):
" Keyboard Source Block "
def __init__(self):
gr.sync_block.__init__(
self,
name = "keyboard_b",
in_sig = None, # Input signature: n/a
out_sig = [numpy.int8], # Output signature: 8 digit integer as a byte (-127 to 128)
)
app = wx.App(False)
frame = wx.Frame(None,wx.ID_ANY,title="Episode IV: A New Hope for Matt's Trident",size=(850,150))
panel = LanoueGUI(frame)
frame.Center()
frame.Show(True)
#app.MainLoop()
def work(self, input_items, output_items):
while (1 == 1):
#Read from the key_src file
#print "I got to the work function of the block!"
file1 = open('/tmp/key_src.txt', 'r')
#Find the length of the file
global size
file1.seek(0, os.SEEK_END)
size = file1.tell()
print "Size: %s" % (str(size))
#time.sleep(0.2) #This was used to slow down the spew of terminal output
#Branching statement
global last_tx
print "Last: %s" % (str(last_tx))
if (last_tx < size):
file1.seek(last_tx, 0)
next_char = file1.read(1)
file1.close()
output_items[0][:] = ord(next_char[0])
print "Outputting %s" % (next_char)
last_tx = last_tx + 1
return len(output_items[0])
else:
file1.close()
output_items[0][:] = 95
#print "Outputting '_'"
return len(output_items[0])
return len(output_items[0])
No comments:
Post a Comment