Ver Mensaje Individual
  #10 (permalink)  
Antiguo 04/01/2017, 08:23
REHome
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 17 años
Puntos: 8
Respuesta: Contar las tramas de byte recibidas

Buenas:

Antes debo solucionar lo de Read().
Código C:
Ver original
  1. private static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e)
  2.         {
  3.             SerialPort sp = (SerialPort)sender;
  4.             int indata = sp.Read();
  5.             Console.WriteLine("Dato recibido:");
  6.             Console.Write(indata);
  7.         }

Gravedad Código Descripción Proyecto Archivo Línea
Error CS1501 Ninguna sobrecarga para el método 'Read' toma 0 argumentos Puerto_Serie_Rread_consola c:\users\usuario\documents\visual studio 2015\Projects\Puerto_Serie_Rread_consola\Puerto_Se rie_Rread_consola\Program.cs 39


Intentando hacer esto.
Código:
using System;
using System.IO.Ports; // No olvidar.
using System.Text;

namespace Puerto_Serie_Rread_consola
{
    class Program
    {
        public static string Recibidos = "";
        public static byte[] datosArray = Encoding.ASCII.GetBytes(Recibidos);

        static void Main(string[] args)
        {
            SerialPort mySerialPort = new SerialPort("COM4");

            mySerialPort.BaudRate = 115200;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.Two;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.RtsEnable = true;

            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

            mySerialPort.Open();

            Console.WriteLine("Presione cualquier tecla para continuar...");
            Console.WriteLine();
            Console.ReadKey();
            mySerialPort.Close();
        }

        private static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                SerialPort sp = (SerialPort)sender;
                int indata = sp.Read(datosArray, 0, 1000);
                Console.WriteLine("Dato recibido:");
                Console.Write(indata);
            }

            catch (ArgumentException)
            {
                Console.WriteLine("El desplazamiento y la longitud están fuera de los límites para esta matriz o el recuento es superior al número de elementos desde el índice al final de la colección de origen.");
            }
        }
    }
}
Algo se me escapa.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar