Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúFormatException La cadena de entrada no tiene el formato correctousing System;
using System.IO.Ports; // No olvidar.
using System.IO;
namespace Porcentaje_Barra_P_Serie_Consola_3_CS
{
    class Program
    {
        public static string Recibidos = "";
        public static double Resultado_Porcentaje = 0;
        public static double Resultado_Voltios = 0;
        public static double Mitad_barra = 0;
        static void Main(string[] args)
        {
            string COM = "";
            // Tamaño ventana consola.
            Console.WindowWidth = 55; // X.
            Console.WindowHeight = 15; // Y.
            Console.Title = "Serial Port C# - v.02"; // Título de la ventana.
            SerialPort Puerto_serie;
            // Crear un nuevo objeto SerialPort con la configuración predeterminada.
            Puerto_serie = new SerialPort();
            // Configuración.
            Console.Write(@"
Introduzca un número para seleccionar puerto COM.
Por ejemplo el 4, sería COM4.
Puerto: ");
            COM = Console.ReadLine(); // Escribir el número del puerto.
            Console.Clear();
            Puerto_serie.PortName = "COM" + COM; // Número del puerto serie.
            Puerto_serie.BaudRate = 115200; // Baudios.
            Puerto_serie.Parity = Parity.None; // Paridad.
            Puerto_serie.DataBits = 8; // Bits de datos.
            Puerto_serie.StopBits = StopBits.Two; // Bits de parada.
            Puerto_serie.Handshake = Handshake.None; // Control de flujo.
            // Establecer la lectura / escritura de los tiempos de espera.
            Puerto_serie.ReadTimeout = 500;
            Puerto_serie.WriteTimeout = 500;
            try
            {
                Puerto_serie.Open(); // Abrir el puerto serie.
            }
            catch (IOException)
            {
                Console.ForegroundColor = ConsoleColor.Red; // Texto en rojo.
                Console.CursorVisible = false;
                Console.SetCursorPosition(16, 6);
                Console.WriteLine(@"El puerto " + Puerto_serie.PortName + @" no existe
                o no lo encuentra.");
            }
            Puerto_serie.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            Console.Read();
            Puerto_serie.Close(); // Cerrar puerto.
        }
        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                SerialPort sp = (SerialPort)sender;
                Recibidos = sp.ReadExisting();
                //Console.Clear();
                Recibidos = Recibidos.Replace("\n\r", "");
                int Variar_este_valor = Convert.ToInt32(Recibidos);
                Resultado_Porcentaje = Variar_este_valor * (100.00 / 1023.00);
                Resultado_Voltios = Variar_este_valor * (5.00 / 1023.00);
                
                Console.SetCursorPosition(0, 1);
                Console.Write("Datos recibidos: ");
                Console.SetCursorPosition(17, 1);
                Console.Write("    ");
                Console.SetCursorPosition(17, 1);
                Console.Write(Recibidos);
                
                Console.SetCursorPosition(0, 3);
                Console.Write("0 %                     50 %                   100 %");
                Console.SetCursorPosition(0, 4);
                Console.Write("┌────────────────────────┬───────────────────────┐");
                Console.Write("                                                  ");
                Console.ForegroundColor = ConsoleColor.Yellow;
                // Se dibide por dos la barra del porcentaje para que quepa decuadamente en la pantalla.
                Mitad_barra = Resultado_Porcentaje / 2;
                if (Mitad_barra > 50)
                {
                    Mitad_barra = 50;
                }
                // Console.SetCursorPosition(0, 5);
                ClearCurrentConsoleLine();
                // Barra de progreso.
                for (int i = 1; i <= Mitad_barra; i++)
                {
                    Console.Write("█"); // Muestra ASCII 219 Dec y DB en Hex.
                }
                // Si sobre pasa 100, muestra # al final de la barra del porcentaje de color rojo.
                if (Resultado_Porcentaje >= 100)
                {
                    Console.SetCursorPosition(50, 5);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("#");
                }
                Console.ForegroundColor = ConsoleColor.Gray; // Vuelve al color gris.
                // Línea 7.
                Console.SetCursorPosition(0, 7);
                Console.Write("Porcentaje: ");
                Console.SetCursorPosition(12, 7);
                Console.Write("            ");
                Console.SetCursorPosition(12, 7);
                Console.Write(Resultado_Porcentaje.ToString("N0") + " %.");
                // Línea 8.
                Console.SetCursorPosition(0, 8);
                Console.Write("Voltios: ");
                Console.SetCursorPosition(12, 8);
                Console.Write("            ");
                Console.SetCursorPosition(12, 8);
                Console.Write(Resultado_Voltios.ToString("N2") + " V.");
            }
            catch (FormatException)
            {
                // Console.WriteLine("La cadena de entrada no tiene el formato correcto.");
                return;
            }
        }
        public static void ClearCurrentConsoleLine()
        {
            int currentLineCursor = Console.CursorTop;
            Console.SetCursorPosition(0, Console.CursorTop);
            Console.Write(new string(' ', Console.WindowWidth));
            Console.SetCursorPosition(0, currentLineCursor);
        }
    }
}
using System;
using System.IO.Ports; // No olvidar.
using System.IO;
namespace Porcentaje_Barra_P_Serie_Consola_3_CS
{
    class Program
    {
        public static string Recibidos = "";
        public static double Resultado_Porcentaje = 0;
        public static double Resultado_Voltios = 0;
        public static double Mitad_barra = 0;
        static void Main(string[] args)
        {
            string COM = "";
            // Tamaño ventana consola.
            Console.WindowWidth = 55; // X.
            Console.WindowHeight = 15; // Y.
            Console.Title = "Serial Port C# - v.02"; // Título de la ventana.
            SerialPort Puerto_serie;
            // Crear un nuevo objeto SerialPort con la configuración predeterminada.
            Puerto_serie = new SerialPort();
            // Configuración.
            Console.Write(@"
Introduzca un número para seleccionar puerto COM.
Por ejemplo el 4, sería COM4.
Puerto: ");
            COM = Console.ReadLine(); // Escribir el número del puerto.
            Console.Clear();
            Puerto_serie.PortName = "COM" + COM; // Número del puerto serie.
            Puerto_serie.BaudRate = 115200; // Baudios.
            Puerto_serie.Parity = Parity.None; // Paridad.
            Puerto_serie.DataBits = 8; // Bits de datos.
            Puerto_serie.StopBits = StopBits.Two; // Bits de parada.
            Puerto_serie.Handshake = Handshake.None; // Control de flujo.
            // Establecer la lectura / escritura de los tiempos de espera.
            Puerto_serie.ReadTimeout = 500;
            Puerto_serie.WriteTimeout = 500;
            try
            {
                Puerto_serie.Open(); // Abrir el puerto serie.
            }
            catch (IOException)
            {
                Console.ForegroundColor = ConsoleColor.Red; // Texto en rojo.
                Console.CursorVisible = false;
                Console.SetCursorPosition(16, 6);
                Console.WriteLine(@"El puerto " + Puerto_serie.PortName + @" no existe
                o no lo encuentra.");
            }
            Puerto_serie.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            Console.Read();
            Puerto_serie.Close(); // Cerrar puerto.
        }
        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                SerialPort sp = (SerialPort)sender;
                Recibidos = sp.ReadExisting();
                //Console.Clear();
                Recibidos = Recibidos.Replace("\n\r", "");
                int Variar_este_valor = Convert.ToInt32(Recibidos);
                Resultado_Porcentaje = Variar_este_valor * (100.00 / 1023.00);
                Resultado_Voltios = Variar_este_valor * (5.00 / 1023.00);
                
                Console.SetCursorPosition(0, 1);
                Console.Write("Datos recibidos: ");
                Console.SetCursorPosition(17, 1);
                Console.Write("    ");
                Console.SetCursorPosition(17, 1);
                Console.Write(Recibidos);
                
                Console.SetCursorPosition(0, 3);
                Console.Write("0 %                     50 %                   100 %");
                Console.SetCursorPosition(0, 4);
                Console.Write("┌────────────────────────┬───────────────────────┐");
                Console.Write("                                                  ");
                Console.ForegroundColor = ConsoleColor.Yellow;
                // Se dibide por dos la barra del porcentaje para que quepa decuadamente en la pantalla.
                Mitad_barra = Resultado_Porcentaje / 2;
                if (Mitad_barra > 50)
                {
                    Mitad_barra = 50;
                }
                Console.SetCursorPosition(0, 5);
                // Barra de progreso.
                for (int i = 1; i <= Mitad_barra; i++)
                {
                    Console.Write("█"); // Muestra ASCII 219 Dec y DB en Hex.
                }
                //Console.SetCursorPosition(0, 5);
                //Console.Write("                                                  ");
                Console.SetCursorPosition(0, 5);
                Console.Write("--------------------------------------------------");
                // Si sobre pasa 100, muestra # al final de la barra del porcentaje de color rojo.
                if (Resultado_Porcentaje >= 100)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("#");
                }
                Console.ForegroundColor = ConsoleColor.Gray; // Vuelve al color gris.
                // Línea 7.
                Console.SetCursorPosition(0, 7);
                Console.Write("Porcentaje: ");
                Console.SetCursorPosition(12, 7);
                Console.Write("            ");
                Console.SetCursorPosition(12, 7);
                Console.Write(Resultado_Porcentaje.ToString("N0") + " %.");
                // Línea 8.
                Console.SetCursorPosition(0, 8);
                Console.Write("Voltios: ");
                Console.SetCursorPosition(12, 8);
                Console.Write("            ");
                Console.SetCursorPosition(12, 8);
                Console.Write(Resultado_Voltios.ToString("N2") + " V.");
            }
            catch (FormatException)
            {
                // Console.WriteLine("La cadena de entrada no tiene el formato correcto.");
                return;
            }
        }
    }
}
Cita de: dante93150 en 29 Mayo 2016, 04:09 AM
Hola bueno vengo aqui se alguien me puede ayudar a como suspender una thread desde el vb,con el process hacker como lo hago ??
Yo e intentado esto pero no funciona
thread.sleep(1000)
pero como agrego la id o addres del proceso???
Cita de: andavid en 28 Abril 2016, 17:17 PM
Fijate voh, te acordas de la vez que expusieron la informacion de Sony?
				using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO.Ports; // No olvidar.
using System.IO;
namespace Arduino_In_Analogico_prueba_01
{
    public partial class Form1 : Form
    {
        // Utilizaremos un string como buffer de recepción.
        string Recibidos;
        public Form1()
        {
            InitializeComponent();
            if (!serialPort1.IsOpen)
            {
                try
                {
                    serialPort1.Open();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
            }
            
        }
        // Al recibir datos.
        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // Acumula los caracteres recibidos a nuestro 'buffer' (string).
            try
            {
                Recibidos = serialPort1.ReadLine();
                Actualizar(null,null);
            }
            catch (IOException)
            {
                // Información adicional: La operación de E/S se anuló por una salida de subproceso o por una solicitud de aplicación.
            }
            // Invocar o llamar al proceso de tramas.
            //Invoke(new EventHandler(Actualizar));
            Actualizar();
        }
        // Como variables de clase
        private string[] Separador = new string[] { ",", "\r", "\n", "/n" };
        private List<string> Leo_Dato = new List<string>();
        // Procesar los datos recibidos en el bufer y extraer tramas completas.
        private void Actualizar(object sender, EventArgs e)
        {
            double Voltaje = 0;
            double Porcentaje = 0;
            // En el evento
            Leo_Dato.Clear();
            Leo_Dato.AddRange(Recibidos.Split(Separador, StringSplitOptions.RemoveEmptyEntries));
            //            Se produjo una excepción de tipo 'System.ArgumentOutOfRangeException' en mscorlib.dll pero no se controló en el código del usuario
            try
            {
                label_Lectura_Potenciometro.Text = Leo_Dato[0].ToString();
            }
            catch (ArgumentOutOfRangeException)
            {
                //Información adicional: El índice estaba fuera del intervalo. Debe ser un valor no negativo e inferior al tamaño de la colección.
            }
            progressBar1.Value = Convert.ToInt32(Leo_Dato[0].ToString());
            double Dato_Voltaje = Convert.ToDouble(Leo_Dato[0]);
            double Dato_Porcentaje = Convert.ToDouble(Leo_Dato[0]);
            Voltaje = Dato_Voltaje * (5.00 / 1023.00);
            Porcentaje = Dato_Porcentaje * (100.00 / 1023.00);
            label_Voltio.Text = Voltaje.ToString("N2") + " V."; // N2 tiene dos decimales.
            label_Portentaje.Text = Porcentaje.ToString("N2") + " %";
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) // ¿El puerto está abierto?
            {
                serialPort1.Close(); // Puerto cerrado.
            }
        }
    }
}
				Control.CheckForIllegalCrossThreadCalls = false;using System;
using System.IO.Ports; // No olvidar.
using System.Collections.Generic;
namespace Porcentaje_Barra_P_Serie_Consola_2_CS
{
    class Program
    {
        public static string Recibidos = "";
        public static int Variar_este_valor = 0; // De 0 a 1023.
        // public static int numVal = Int32.Parse(Recibidos);
        // public static int numVal = Convert.ToInt32(Recibidos);
        public static double Resultado_Porcentaje = 0;
        public static double Resultado_Voltios = 0;
        public static double Mitad_barra = 0;
        // Como variables de clase
        public static string[] Separador = new string[] { ",", "\r", "\n", "/n" };
        public static List<string> Leo_Dato = new List<string>();
        static void Main(string[] args)
        {
            Console.WindowWidth = 55;
            Console.WindowHeight = 15;
            Console.Title = "Serial Port C#";
            SerialPort Puerto_serie;
            // Crear un nuevo objeto SerialPort con la configuración predeterminada.
            Puerto_serie = new SerialPort();
            // Configuración.
            Puerto_serie.PortName = "COM4"; // Número del puerto serie.
            Puerto_serie.BaudRate = 115200; // Baudios.
            Puerto_serie.Parity = Parity.None; // Paridad.
            Puerto_serie.DataBits = 8; // Bits de datos.
            Puerto_serie.StopBits = StopBits.Two; // Bits de parada.
            Puerto_serie.Handshake = Handshake.None; // Control de flujo.
            // Establecer la lectura / escritura de los tiempos de espera.
            Puerto_serie.ReadTimeout = 500;
            Puerto_serie.WriteTimeout = 500;
                
            Puerto_serie.Open(); // Abre el puerto serie.
            Puerto_serie.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            Console.Read();
        }
        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            
            SerialPort sp = (SerialPort)sender;
            Recibidos = sp.ReadLine();
            Console.Clear();
            Recibidos = Recibidos.Replace("\r", "");
            int Variar_este_valor = Convert.ToInt32(Recibidos);
            // En el evento.
            //Leo_Dato.Clear();
            //Leo_Dato.AddRange(Recibidos.Split(Separador, StringSplitOptions.RemoveEmptyEntries));
            Console.WriteLine();
            Resultado_Porcentaje = Variar_este_valor * (100.00 / 1023.00);
            Resultado_Voltios = Variar_este_valor * (5.00 / 1023.00);
            Console.Clear();
            Console.WriteLine("Valor introducido: {0}", Recibidos);
            Console.CursorVisible = false;
            // Mostrar barra de porcentaje en pantalla.
            Console.WriteLine();
            Console.WriteLine("0 %                     50 %                   100 %");
            Console.WriteLine("┌────────────────────────┬───────────────────────┐");
            Console.ForegroundColor = ConsoleColor.Yellow;
            // Se dibide por dos la barra del porcentaje para que quepa decuadamente en la pantalla.
            Mitad_barra = Resultado_Porcentaje / 2;
            if (Mitad_barra > 50)
            {
                Mitad_barra = 50;
            }
            for (int i = 1; i <= Mitad_barra; i++)
            {
                Console.Write("█"); // Muestra ASCII 219 Dec y DB en Hex.
            }
            // Si sobre pasa 100, muestra # al final de la barra del porcentaje de color rojo.
            if (Resultado_Porcentaje > 100)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("#");
            }
            Console.ForegroundColor = ConsoleColor.Gray; // Vuelve al color gris.
            Console.WriteLine("\n");
            Console.Write("Percentage: " + Resultado_Porcentaje.ToString("N2") + " %.");
            Console.WriteLine();
            Console.Write("Voltage:     " + Resultado_Voltios.ToString("N2") + " V.");
            Console.WriteLine("\n");
            // Console.Write(Recibidos.PadRight(4));
        }
    }
}