Código Python:
Ver original#Boa:Frame:Frame1
import wx
import serial
##PARA COM1 Puerto = 0
Puerto = 0
ser = serial.Serial(Puerto, 9600, timeout=1, stopbits=1)
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BOTAPAGAR, wxID_FRAME1BOTLED1, wxID_FRAME1BOTLED2,
wxID_FRAME1PANEL1,
] = [wx.NewId() for _init_ctrls in range(5)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(506, 173), size=wx.Size(214, 239),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(206, 205))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(206, 205),
style=wx.TAB_TRAVERSAL)
self.panel1.SetBackgroundColour(wx.Colour(0, 196, 196))
self.botLed1 = wx.Button(id=wxID_FRAME1BOTLED1, label=u'Led1 On',
name=u'botLed1', parent=self.panel1, pos=wx.Point(64, 24),
size=wx.Size(75, 23), style=0)
self.botLed1.Bind(wx.EVT_BUTTON, self.OnBotLed1Button,
id=wxID_FRAME1BOTLED1)
self.botLed2 = wx.Button(id=wxID_FRAME1BOTLED2, label=u'Led2 On',
name=u'botLed2', parent=self.panel1, pos=wx.Point(64, 64),
size=wx.Size(75, 23), style=0)
self.botLed2.Bind(wx.EVT_BUTTON, self.OnBotLed2Button,
id=wxID_FRAME1BOTLED2)
self.botApagar = wx.Button(id=wxID_FRAME1BOTAPAGAR,
label=u'Apagar Leds', name=u'botApagar', parent=self.panel1,
pos=wx.Point(64, 104), size=wx.Size(75, 23), style=0)
self.botApagar.Bind(wx.EVT_BUTTON, self.OnBotApagarButton,
id=wxID_FRAME1BOTAPAGAR)
self.txt = wx.TextCtrl(id=-1, parent=self.panel1, pos=wx.Point(64, 140))
self.btn = wx.Button(id=-1, label="Enviar", parent=self.panel1, pos=wx.Point(64, 165))
self.btn.Bind(wx.EVT_BUTTON, self.OnSend)
def __init__(self, parent):
self._init_ctrls(parent)
def OnBotLed1Button(self, event):
event.Skip()
ser.write("A") #ENVIA LA LETRA "A" AL MICROCONTROLADOR
def OnBotLed2Button(self, event):
event.Skip()
ser.write("B") #ENVIA LA LETRA "B" AL MICROCONTROLADOR
def OnBotApagarButton(self, event):
event.Skip()
ser.write("X") #ENVIA LA LETRA "X" AL MICROCONTROLADOR
def OnSend(self, event):
event.Skip()
txt = self.txt.GetValue()
md = wx.MessageDialog(self, txt, "Titulo", wx.OK)
md.ShowModal()
md.Destroy()
ser.write(txt)
class BoaApp(wx.App):
def OnInit(self):
self.main = create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()