Hi guys, i have a tricky problem with this wxgtk gui and thread nesting. As you can see i'm trying to collect data through a buffer ( self.data= dict() ) through the main gui. I need to get the data from the ComboBox and the three textfields then i need to pass them to a gnuradio flow graph ( i don't know if many of you are expertise with the gnuradio platform but here i'm doing a wxgtk flow graph ). Here's the code with the unnecessary modules disabled....
when i click on the Start ! button the miothread1 function collects the data from the GUI and calls the calculate function in which i recall the stored data in my buffer and pass them to the flow graphs. However the interpreter crashes giving me the error at bottom page.
could you help me to solve this problem ? thx in advance, Arturo.
#!/usr/bin/env python
# -*- coding: utf8 -*-
#from gnuradio import gr
#from gnuradio import audio
#from gnuradio import blks2
import random
#import wxversion
#wxversion.select('2.8.11')
import wx
import os # Operating System dependent call
import sys
#from source.modulazioni import bpsk, qpsk, psk8
#from source.modulazioni import bask, qask, ask8
#from source.modulazioni import qam16, qam64, qam256
import cPickle as p
import csv
#from source.modulazioni import sunde
import Image
#import stdgui2
#import visualizza_costfile, visualizza_framemod2, slider_ber2
import thread
#import bertool_rician_gnuradio
# Define dialog component
ID_EXIT = 98
ID_CALCULATE = 99
ID_PLOT = 100
ID_CLOSE = 101
ID_CLEAR_TERM = 102
ID_RESET = 103
ID_ORIG_2_RAW = 104
ID_RAW_2_ORIG = 105
ID_MODULATE = 106
def ReadFile (arrImg, fpR):
while True:
data = fpR.read(1) # Read data, 1 byte each time
if len(data) == 0: # If reach EOF, finish the loop
break
lData = ord(data) # Convert char to int
arrImg.append(lData) # Store data(int) into array
return arrImg
def Ber(sent, received, length):
try:
n = 0
for i in range(length-1):
if sent[i] != received[i]:
n+=1 # no n++ and ++n in Python
return (float(n)/float(length))
except IndexError:
sys.exit()
except ZeroDivisionError:
sys.exit()
def formatta(valore):
tmp = str("%.1f" % valore)
if tmp == "-0.0":
return tmp.replace("-","")
else:
return tmp
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(350, 400),pos = (200,100))
#Creates a menu
filemenu1=wx.Menu()
filemenu1.AppendSeparator()
filemenu1.Append(ID_EXIT, "&Exit", "Terminate the program")
# Creating the menubar
menuBar=wx.MenuBar()
menuBar.Append(filemenu1, "&File") #Adding the filemenu to the MenuBar
self.SetMenuBar(menuBar) #Adding the MenuBar to the Frame content
self.CreateStatusBar() # A statusbar in the bottom of the window
mod = ['BASK','4-ASK','8-ASK','BPSK','Q-PSK','8-PSK','Sunde FSK','QAM-16','QAM-64','QAM-256']
#mod = ['B-ASK','BPSK','Q-PSK','8-PSK','Sunde FSK']
#ext = ['.wav', '.mp3', '.ogg','.flac']
wx.StaticText(self, -1, "Scegliere la modulazione :",(50,30))
self.combo1 = wx.ComboBox(self, -1, pos=(50, 70), size=(150, -1), choices=mod, value='BASK',
style=wx.CB_READONLY)
wx.StaticText(self, -1, "Scegliere il valore di Eb :",(50,120))
wx.StaticText(self, -1, "Eb :",(50,155))
wx.StaticText(self, -1, "Inserire il valore di K (dB) e σ0 :",(50,185))
wx.StaticText(self, -1, "K :",(50,215))
wx.StaticText(self, -1, 'σ0 : ',(180,215))
self.txt1 = wx.TextCtrl(self, -1, '1.0',(90,150)) #eb
self.txt2 = wx.TextCtrl(self, -1, '5.0',(80,210)) # kdb
self.txt3 = wx.TextCtrl(self, -1, '1.0',(210,210)) # sigma
wx.StaticText(self, -1, "Visualizza Costellazione :",(50,250))
wx.Button(self, ID_MODULATE, 'Start !', (50, 280))
#wx.Button(self, ID_CLOSE, 'Close', (50, 300))
wx.EVT_MENU(self, ID_EXIT, self.OnClose)
wx.EVT_BUTTON(self, ID_MODULATE, self.miothread1)
def OnClose(self, e):
self.Close(True)
def calculate(self,e):
#name = self.combo1.GetValue()
#kappa = float(self.txt2.GetValue())
#sigma = float(self.txt3.GetValue())
#number = float(self.txt1.GetValue())
try:
name = self.data['name']
##ebno = float(self.txt1.GetValue())
number = self.data['number']
kappa = self.data['kappa']
sigma = self.data['sigma']
#self.data = dict()
##name = self.data['title'] = self.combo1.GetValue()
#thread.start_new_thread(self.calculate, (name,kappa,sigma,number,))
if name == 'BASK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_bask,"BASK Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == '4-ASK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_qask,"4-ASK Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == '8-ASK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_ask8,"8-ASK Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == 'BPSK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_bpsk,"BPSK Rician K = "+str(kappa)+"dB σ0= "+str(sigma))
fg.Show(True)
elif name == 'Q-PSK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_qpsk,"Q-PSK Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == '8-PSK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_psk8,"8-PSK Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == 'Sunde FSK':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_sunde,"Sunde Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == 'QAM-16':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_qam16,"QAM-16 Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == 'QAM-64':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_qam64,"QAM-64 Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
elif name == 'QAM-256':
#number = float(self.txt1.GetValue())
fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio.ber_rician_qam256,"QAM-256 Rician K = "+str(kappa)+"dB σ0 = "+str(sigma))
fg.Show(True)
except ValueError:
self.Close(True)
def reset(self,e):
#ext = self.extension
os.system('rm ./raw.rgb ./rx_unpack.rgb ./rx_unpack.* ./orig.*' )
def clear_term(self,e):
os.system('clear')
def frame_ber(self,m,d):
fg3 = slider_ber2.Slider(self,m,d)
fg3.Show(True)
def miothread1(self,e):
self.data = dict()
name = self.data['name'] = self.combo1.GetValue()
kappa = self.data['kappa'] = float(self.txt2.GetValue())
sigma = self.data['sigma'] = float(self.txt3.GetValue())
number = self.data['number'] = float(self.txt1.GetValue())
#name = self.data['title'] = self.combo1.GetValue()
#thread.start_new_thread(self.calculate, (name,kappa,sigma,number,))
thread.start_new_thread(self.calculate, (0,))
def miothread2(self,e,f):
thread.start_new_thread(self.frame_ber, (e,f,))
class MyApp(wx.App):
def OnInit(self):
frame=MainWindow(None, -1, "Constellations")
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp()
#ComboBox(None, -1, 'BER Tool')
app.MainLoop()
error :
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python: ../../src/xcb_io.c:178: dequeue_pending_request: asserzione "!xcb_xlib_unknown_req_in_deq" non riuscita.