elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Encontrar la solución de recibir datos.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Encontrar la solución de recibir datos.  (Leído 1,570 veces)
Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Encontrar la solución de recibir datos.
« en: 28 Febrero 2015, 02:13 am »

Hola:

Tengo este código con WPF C# 2013. Puedo enviar datos pero no recibirlos y se muestre en RichTextBox.
Código
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16.  
  17. using System.IO.Ports; // No olvidar.
  18. using System.Threading;
  19.  
  20. namespace WpfApplication1
  21. {
  22.    /// <summary>
  23.    /// Lógica de interacción para MainWindow.xaml
  24.    /// </summary>
  25.    public partial class MainWindow : Window
  26.    {
  27.        // Utilizaremos un string como buffer de recepción.
  28.        string Recibidos;
  29.  
  30.        SerialPort serialPort1 = new SerialPort();
  31.  
  32.        public MainWindow()
  33.        {
  34.            InitializeComponent();
  35.  
  36.            serialPort1.BaudRate = 115200;
  37.            serialPort1.PortName = "COM4";
  38.            serialPort1.Parity = Parity.None;
  39.            serialPort1.DataBits = 8;
  40.            serialPort1.StopBits = StopBits.Two;
  41.  
  42.            // Abrir puerto mientras se ejecute la aplicación.
  43.            if (!serialPort1.IsOpen)
  44.            {
  45.                try
  46.                {
  47.                    serialPort1.Open();
  48.                }
  49.                catch (System.Exception ex)
  50.                {
  51.                    MessageBox.Show(ex.ToString());
  52.                }
  53.  
  54.            }
  55.  
  56.            // Ejecutar la función REcepción por disparo del Evento ¡DataReived'.
  57.            //serialPort1.DataReceived += new SerialDataReceivedEventHandler(Recepcion);
  58.        }
  59.  
  60.        private void Recepcion(object sender, SerialDataReceivedEventHandler e)
  61.        {
  62.            // Acumular los caracteres recibidos a nuestro 'buffer' (string).
  63.            Recibidos += serialPort1.ReadExisting();
  64.  
  65.            // Invocar o llamar al proceso de tramas.
  66.            //this.Invoke(new EventHandler(Actualizar));
  67.  
  68.        }
  69.  
  70.  
  71.        // Procesar los datos recibidos en el buffer y estraer tramas completas.
  72.        private void Actualizar(object s, EventArgs e)
  73.        {
  74.            // Asignar el valor de la trama al RichTextBox.
  75.            RichTextBox_Mensajes.DataContext = Recibidos;
  76.        }
  77.  
  78.        private void Button_Led_8_ON_Click(object sender, RoutedEventArgs e)
  79.        {
  80.            byte[] mBuffer = Encoding.ASCII.GetBytes("Led_8_ON");
  81.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  82.        }
  83.  
  84.        private void Button_Led_8_OFF_Click(object sender, RoutedEventArgs e)
  85.        {
  86.            byte[] mBuffer = Encoding.ASCII.GetBytes("Led_8_OFF");
  87.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  88.            RichTextBox_Mensajes.DataContext = "Hola";
  89.        }
  90.  
  91.    }
  92. }
  93.  

Alguna solución donde está el problema.

Saludos.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Medir inclinacion y recibir datos en la PC
Electrónica
loelc 4 4,405 Último mensaje 17 Enero 2007, 09:06 am
por loelc
error al capturar pantalla (mucho tiempo sin encontrar solucion)
Programación Visual Basic
usuario oculto 1 2,238 Último mensaje 29 Octubre 2011, 20:10 pm
por ignorantev1.1
Sockets - linux - recibir datos
Programación C/C++
d00ze13 0 1,592 Último mensaje 14 Noviembre 2011, 19:02 pm
por d00ze13
Prueba misc_memoria y posible error para encontrar la solucion
WarZone
roilivethelife 3 3,928 Último mensaje 7 Abril 2018, 13:07 pm
por MACkina
[JSON] Recibir datos ? (solved)
PHP
Diabliyo 1 2,408 Último mensaje 6 Octubre 2012, 17:41 pm
por Diabliyo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines