Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/11/2010, 09:32
davidmuri18
 
Fecha de Ingreso: noviembre-2010
Mensajes: 1
Antigüedad: 13 años, 6 meses
Puntos: 0
Comunicacion Serial Inquietudes

Hola amigos. Tengo dos inquietudes sobre transmision y recepcion de datos por el bus serial RS232. Utilizando Windows, Boa Constructor y la libreria pyserial hice una pequeña aplicacion con tres botones. Con cada boton envio un caracter diferente a un microcontrolador conectado al puerto serial COM1. Este microcontrolador esta programado para responder al evento de llegada de datos por USART.

La primera inquietud es:
Si agrego una caja de texto, Cómo hago para transmitir por serial un caracter o un texto introducido en la caja de texto cada vez que presione un boton determinado ?

La segunda inquietud es:
Como hago para recibir datos por el puerto serial y el programa responda a ese evento ?

Estos son los archivos:



Código Python:
Ver original
  1. #!/usr/bin/env python
  2. #Boa:App:BoaApp
  3.  
  4. import wx
  5.  
  6. import FrameTxSerial1
  7.  
  8. modules ={u'FrameTxSerial1': [1, 'Main frame of Application', u'FrameTxSerial1.py']}
  9.  
  10. class BoaApp(wx.App):
  11.     def OnInit(self):
  12.         self.main = FrameTxSerial1.create(None)
  13.         self.main.Show()
  14.         self.SetTopWindow(self.main)
  15.         return True
  16.  
  17. def main():
  18.     application = BoaApp(0)
  19.     application.MainLoop()
  20.  
  21. if __name__ == '__main__':
  22.     main()


--------------------------------
Este es el otro:

Código Python:
Ver original
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4. import serial
  5.  
  6. ##PARA COM1 Puerto = 0
  7. Puerto = 0
  8. ser = serial.Serial(Puerto, 9600, timeout=1, stopbits=1)
  9.  
  10. def create(parent):
  11.     return Frame1(parent)
  12.  
  13. [wxID_FRAME1, wxID_FRAME1BOTAPAGAR, wxID_FRAME1BOTLED1, wxID_FRAME1BOTLED2,
  14.  wxID_FRAME1PANEL1,
  15. ] = [wx.NewId() for _init_ctrls in range(5)]
  16.  
  17. class Frame1(wx.Frame):
  18.     def _init_ctrls(self, prnt):
  19.         # generated method, don't edit
  20.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  21.               pos=wx.Point(506, 173), size=wx.Size(214, 239),
  22.               style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  23.         self.SetClientSize(wx.Size(206, 205))
  24.  
  25.         self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
  26.               pos=wx.Point(0, 0), size=wx.Size(206, 205),
  27.               style=wx.TAB_TRAVERSAL)
  28.         self.panel1.SetBackgroundColour(wx.Colour(0, 196, 196))
  29.  
  30.         self.botLed1 = wx.Button(id=wxID_FRAME1BOTLED1, label=u'Led1 On',
  31.               name=u'botLed1', parent=self.panel1, pos=wx.Point(64, 24),
  32.               size=wx.Size(75, 23), style=0)
  33.         self.botLed1.Bind(wx.EVT_BUTTON, self.OnBotLed1Button,
  34.               id=wxID_FRAME1BOTLED1)
  35.  
  36.         self.botLed2 = wx.Button(id=wxID_FRAME1BOTLED2, label=u'Led2 On',
  37.               name=u'botLed2', parent=self.panel1, pos=wx.Point(64, 64),
  38.               size=wx.Size(75, 23), style=0)
  39.         self.botLed2.Bind(wx.EVT_BUTTON, self.OnBotLed2Button,
  40.               id=wxID_FRAME1BOTLED2)
  41.  
  42.         self.botApagar = wx.Button(id=wxID_FRAME1BOTAPAGAR,
  43.               label=u'Apagar Leds', name=u'botApagar', parent=self.panel1,
  44.               pos=wx.Point(64, 104), size=wx.Size(75, 23), style=0)
  45.         self.botApagar.Bind(wx.EVT_BUTTON, self.OnBotApagarButton,
  46.               id=wxID_FRAME1BOTAPAGAR)
  47.  
  48.     def __init__(self, parent):
  49.         self._init_ctrls(parent)
  50.        
  51.  
  52.     def OnBotLed1Button(self, event):
  53.         event.Skip()
  54.         ser.write("A")  #ENVIA LA LETRA "A" AL MICROCONTROLADOR
  55.        
  56.  
  57.     def OnBotLed2Button(self, event):
  58.         event.Skip()
  59.         ser.write("B")  #ENVIA LA LETRA "B" AL MICROCONTROLADOR
  60.  
  61.     def OnBotApagarButton(self, event):
  62.         event.Skip()
  63.         ser.write("X")  #ENVIA LA LETRA "X" AL MICROCONTROLADOR

GRACIAS POR SU COLABORACION.

Última edición por AlvaroG; 09/11/2010 a las 10:16 Razón: resaltado de código