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

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: 1 ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [20] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ... 254
191  Programación / .NET (C#, VB.NET, ASP) / Leer bits de Byte en: 2 Abril 2021, 13:14 pm
Buenas camaradas:

Haciendo un programa hecho con Windows Form bajo .Net FrameWotk 4.7. Si envío un comando por el puerto serie que se llama X82, recibo un mensaje que en ASCII no se entiende porque usa caracteres raros.

Lo paso a hexadecimal y en binario.

Envío un comando, ocurre algún evento y en Windoes Form me aparece cógios en HEX y en BIN. Se puede cambiar varios bit en un único Byte.

Por ejemplo, si me llega este dato.

Hexadecimal: 23C797C0B00D

Binario: 00100011 11000111 10010111 11000000 10110000 00001101

Un ejemplo, es poner muchos labels en cada bits y una tabla de cada Byte recibido. Simpre son la misma cantidad de bytes ya que en realdiad hace de Flags.

Centrándonos en el binario, ya que hay 6 Bytes.

Código
  1. 00100011 11000111 10010111 11000000 10110000 00001101
  2. -------- -------- -------- -------- -------- --------
  3. Byte I  Byte a    Byte b   Byte c   Byte d   Byte F
  4.  

En el Byte c que corresponde al 11000000 quiero leer el bit 3 que corresponde al "Extractor" indicado en la tabla de abajo. Cada Byte tiene su tabla, ahora nos centramos en un Byte y ver los estados de los bits.

bit:c Dato        Función.
7 =   1            Motor A.
6 =   1            Motor B.
5 =   0            Luz A.
4 =   0            Luz B.
3 =   0            Extractor.
2 =   0            Alarma.
1 =   0            Persiana.
0 =   0            Ventilador

El Byte c que ahora contiene estos bits que son 11000000, me llega una nueva trama de Bytes y precisamente este, cambia de 11000000 a 11001000. Solo ha cambiado un bit que es el 3 en el Byte c.

Cada bit tiene su label para mostrarlo en el formulario de Windows. La tabla de abajo se actualiza.

bit:c Dato        Función.
7 =   1            Motor A.
6 =   1            Motor B.
5 =   0            Luz A.
4 =   0            Luz B.
3 =   1            Extractor.
2 =   0            Alarma.
1 =   0            Persiana.
0 =   0            Ventilador

Antes el Byte c del bit 3 que es el Extractor estaba a 0, ahora es 1.

En resumen. Quiero saber como se leen los bits que me llegan del puerto serie.

¿Existe la posibilidad de hacer un programa así?

Saludos.

PD: En esta clase de programas que no suelo usar, es como las aves, fáciles de ver, difíciles de alcanzar.
192  Programación / .NET (C#, VB.NET, ASP) / Re: Separar binario por cada byte en: 2 Abril 2021, 10:33 am
Buenas:

Como veo la base ya tienes una variable con 0 y 1.
Hice el foreach y for que indicaste. Me da problemas. Lo hice así para que lo pase a binario y elfor tuyo para que lo separe.


Ver zoom.

Código
  1.            // Pasar a binario.
  2.            string resultado = "";
  3.            foreach (string leer in recibidos.Select(c => Convert.ToString(c, 2)))
  4.            {
  5.                resultado += leer.ToString();
  6.            }    
  7.  
  8.            for (int i = 0; i < resultado.Length; i += 8)
  9.            {
  10.                richTextBox1.Text += resultado.Substring(i, 8) + " ";
  11.            }

Si lo hago solo así que se muestre en richTextBox me da el  mismo error.
Código
  1.            for (int i = 0; i < recibidos.Length; i += 8)
  2.            {
  3.                richTextBox1.Text += recibidos.Substring(i, 8) + " ";
  4.            }
193  Programación / .NET (C#, VB.NET, ASP) / Re: Separar binario por cada byte en: 2 Abril 2021, 05:33 am
Buenas mi muy distinguido amigo:

El problema que el código y variable recibidos me viene en string.

Lo he intentado poner en Byte y me da más problemas por todas partes. El código es enorme.

Dejo un ejemplo para que lo veas y te hagas una gran idea.


Código
  1. using System;
  2. using System.IO.Ports;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6.  
  7. namespace Ejemplo
  8. {
  9.    public partial class Form1 : Form
  10.    {
  11.        // Utilizaremos un string como buffer de recepción.
  12.        string recibidos;
  13.  
  14.        public Form1()
  15.        {
  16.            InitializeComponent();
  17.        }
  18.  
  19.  
  20.        private void Form1_Load(object sender, EventArgs e)
  21.        {
  22.            try
  23.            {
  24.                // Codificación.
  25.                //serialPort1.Encoding = Encoding.GetEncoding(437);
  26.                //serialPort1.Encoding = Encoding.GetEncoding(28591); // 28591 es lo mismo que ISO-8859-1.
  27.                serialPort1.Encoding = Encoding.GetEncoding("ISO-8859-1");
  28.  
  29.                // Añado los puertos disponible en el PC con SerialPort.GetPortNames() al comboBox_Puerto.
  30.                comboBox_Puerto.DataSource = SerialPort.GetPortNames();
  31.  
  32.                // Añade puertos disponibles físicos  y virtuales.
  33.                serialPort1.PortName = comboBox_Puerto.Text.ToString();
  34.  
  35.                // Añadir datos recibidos en el evento.
  36.                serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
  37.            }
  38.  
  39.            catch (Exception error)
  40.            {
  41.                MessageBox.Show(error.Message, "Aviso:",
  42.                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
  43.            }
  44.        }
  45.  
  46.        // Detecta USB o puerto serie virtual cuando lo conecta y desconecta del cable.
  47.        protected override void WndProc(ref Message USB)
  48.        {
  49.            if (USB.Msg == 0x219)
  50.            {
  51.                comboBox_Puerto.DataSource = SerialPort.GetPortNames();
  52.            }
  53.  
  54.            // Detecta si hay cambios en el usb y si los hay los refleja.
  55.            base.WndProc(ref USB);
  56.        }
  57.  
  58.        private void button_Conectar_Click(object sender, EventArgs e)
  59.        {
  60.            try
  61.            {
  62.                serialPort1.PortName = comboBox_Puerto.Text.ToString(); // Puerto seleccionado previamente.
  63.                serialPort1.BaudRate = Convert.ToInt32(comboBox_Baudios.Text); // Baudios.
  64.                serialPort1.Open(); // Abrir puerto.
  65.                comboBox_Puerto.Enabled = false;
  66.                comboBox_Baudios.Enabled = false;
  67.                button_Conectar.Enabled = false;
  68.                button_Desconectar.Enabled = true;
  69.                groupBox_Control_Zumbador.Enabled = true;
  70.            }
  71.            catch (Exception error)
  72.            {
  73.                MessageBox.Show(error.Message, "Aviso:",
  74.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  75.            }
  76.        }
  77.  
  78.        private void button_Desconectar_Click(object sender, EventArgs e)
  79.        {
  80.            try
  81.            {
  82.                serialPort1.Close(); // Cerrar puerto.
  83.                comboBox_Puerto.Enabled = true;
  84.                comboBox_Baudios.Enabled = true;
  85.                button_Conectar.Enabled = true;
  86.                button_Desconectar.Enabled = false;
  87.                groupBox_Control_Zumbador.Enabled = false;
  88.            }
  89.  
  90.            catch (Exception error)
  91.            {
  92.                MessageBox.Show(error.Message, "Aviso:",
  93.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  94.            }
  95.        }
  96.  
  97.        // Al cerrar el formulario, cierra el puerto si está abierto.
  98.        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  99.        {
  100.            try
  101.            {
  102.                serialPort1.Close(); // Cerrar puerto.
  103.            }
  104.  
  105.            catch (Exception error)
  106.            {
  107.                MessageBox.Show(error.Message, "Aviso:",
  108.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  109.            }
  110.        }
  111.  
  112.        // Al recibir datos.
  113.        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  114.        {
  115.            // Acumula los caracteres recibidos a nuestro 'buffer' (string).
  116.            recibidos += serialPort1.ReadExisting();
  117.  
  118.            // Invocar o llamar al proceso de tramas.
  119.            Invoke(new EventHandler(Actualizar));
  120.        }
  121.  
  122.        // Procesar los datos recibidos en el bufer y extraer tramas completas.
  123.        private void Actualizar(object sender, EventArgs e)
  124.        {
  125.  
  126.            // Asignar el valor de la trama al richTextBox.
  127.            richTextBox1.Text += recibidos;
  128.  
  129.            // Pasar a hexadecimal.
  130.            foreach (byte b in recibidos)
  131.            {
  132.                // x = minúscula, X = mayúscula.
  133.                richTextBox1.Text += b.ToString("X2");
  134.            }
  135.  
  136.            // Nueva línea.
  137.            richTextBox1.Text += Environment.NewLine;
  138.  
  139.            // Pasar a binario.
  140.            foreach (string leer in recibidos.Select(c => Convert.ToString(c, 2)))
  141.            {
  142.                richTextBox1.Text += leer.ToString();
  143.            }
  144.  
  145.            // Nueva línea.
  146.            richTextBox1.Text += Environment.NewLine;
  147.            richTextBox1.Text += Environment.NewLine;
  148.  
  149.            // Selecciona la posición final para leer los mensajes entrantes.
  150.            richTextBox1.SelectionStart = richTextBox1.Text.Length;
  151.  
  152.            // Mantiene el scroll en la entrada de cada mensaje.
  153.            richTextBox1.ScrollToCaret();
  154.  
  155.            // Limpiar.
  156.            recibidos = "";
  157.        }
  158.  
  159.        private void button_Activar_Click(object sender, EventArgs e)
  160.        {
  161.            //byte[] mBuffer = Encoding.ASCII.GetBytes("K60:1\r"); // Comando K60:1 activar.
  162.            byte[] mBuffer = Encoding.ASCII.GetBytes("X87\r"); // Comando X87 Flags.
  163.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  164.        }
  165.  
  166.        private void button_Desactivar_Click(object sender, EventArgs e)
  167.        {
  168.            byte[] mBuffer = Encoding.ASCII.GetBytes("K60:0\r"); // Comando K60:0 desactivar.
  169.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  170.        }
  171.  
  172.        private void button_Mute_temporal_Click(object sender, EventArgs e)
  173.        {
  174.            byte[] mBuffer = Encoding.ASCII.GetBytes("B\r"); // Comando K60:2 Mute temporal.
  175.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  176.        }
  177.  
  178.        private void button_Limpiar_Click(object sender, EventArgs e)
  179.        {
  180.            // Limpiar.
  181.            richTextBox1.Clear();
  182.        }
  183.    }
  184. }
194  Programación / .NET (C#, VB.NET, ASP) / Separar binario por cada byte en: 1 Abril 2021, 19:15 pm
Hola:

Al mostrar una trama de bytes, lo presento en binario y me muestra esto.

001000111100011110010111110000001011000000001101

Hay 6 Bytes que en realidad en hexadecimal es 23 C7 97 C0 B0 0D

Quiero que se me separe así en cada byte o cada 8 bit.

00100011 11000111 10010111 11000000 10110000 00001101

He intentado hacerlo con este código:
Código
  1.            // Pasar a binario.
  2.            foreach (string leer in recibidos.Select(c => Convert.ToString(c, 2)))
  3.  
  4.            {
  5.                richTextBox1.Text += leer.ToString();
  6.            }

Me pasa dos cosas.
Como en el ejemplo de arriba, si los bits empieza por cero y encuentro un uno, por ejemplo. 00000001, en la pantalla me aparece solo el 1 ignorando los sietes primeros 0. Me gusta más que se muestre así 00000001 en vez de tipo ahorrador con solo un 1.

La otra cosa, que por cada 8 bytes en binario se muestre separado como indicado arriba.

¿Es posible hacerlo?

Gracias.
195  Programación / .NET (C#, VB.NET, ASP) / Re: Leer información de una SAI / UPS en: 1 Abril 2021, 05:28 am
Buenas:

Me está dando resultados diferentes de un terminal que el propio mio en hexadecimal y no se el motivo. Cuando los datos recibidos son los mismos.


Ver Zoom.

Quiero saber el motivo. Muchas gracias.

Configuración puerto serie.

Ver zoom.

Código C#:
Código
  1. using System;
  2. using System.IO.Ports;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6.  
  7. namespace Terminal_UPS_SAI_02
  8. {
  9.    public partial class Form1 : Form
  10.    {
  11.        // Utilizaremos un string como buffer de recepción.
  12.        string recibidos;
  13.  
  14.        public Form1()
  15.        {
  16.            InitializeComponent();
  17.        }
  18.  
  19.        private void Form1_Load(object sender, EventArgs e)
  20.        {
  21.            try
  22.            {
  23.                // Añado los puertos disponible en el PC con SerialPort.GetPortNames() al comboBox_Puerto.
  24.                comboBox_Puerto.DataSource = SerialPort.GetPortNames();
  25.  
  26.                // Añade puertos disponibles físicos  y virtuales.
  27.                serialPort1.PortName = comboBox_Puerto.Text.ToString();
  28.  
  29.                // Añadir en la variable recibidos datos codificados.
  30.                recibidos += serialPort1.Encoding = Encoding.GetEncoding(437);
  31.  
  32.                // Añadir datos recibidos en el evento.
  33.                serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
  34.            }
  35.  
  36.            catch
  37.            {
  38.                MessageBox.Show("No encuentra ningún puerto físico ni virtual.", "Aviso:",
  39.                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
  40.            }
  41.        }
  42.  
  43.        // Detecta USB o puerto serie virtual cuando lo conecta y desconecta del cable.
  44.        protected override void WndProc(ref Message USB)
  45.        {
  46.            if (USB.Msg == 0x219)
  47.            {
  48.                comboBox_Puerto.DataSource = SerialPort.GetPortNames();
  49.            }
  50.  
  51.            // Detecta si hay cambios en el usb y si los hay los refleja.
  52.            base.WndProc(ref USB);
  53.        }
  54.  
  55.        private void button_Conectar_Click(object sender, EventArgs e)
  56.        {
  57.            try
  58.            {
  59.                serialPort1.PortName = comboBox_Puerto.Text.ToString(); // Puerto seleccionado previamente.
  60.                serialPort1.BaudRate = Convert.ToInt32(comboBox_Baudios.Text); // Baudios.
  61.                serialPort1.Open(); // Abrir puerto.
  62.                comboBox_Puerto.Enabled = false;
  63.                comboBox_Baudios.Enabled = false;
  64.                button_Conectar.Enabled = false;
  65.                button_Desconectar.Enabled = true;
  66.                groupBox_Control_Zumbador.Enabled = true;
  67.            }
  68.            catch (Exception error)
  69.            {
  70.                MessageBox.Show(error.Message, "Aviso:",
  71.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  72.            }
  73.        }
  74.  
  75.        private void button_Desconectar_Click(object sender, EventArgs e)
  76.        {
  77.            try
  78.            {
  79.                serialPort1.Close(); // Cerrar puerto.
  80.                comboBox_Puerto.Enabled = true;
  81.                comboBox_Baudios.Enabled = true;
  82.                button_Conectar.Enabled = true;
  83.                button_Desconectar.Enabled = false;
  84.                groupBox_Control_Zumbador.Enabled = false;
  85.            }
  86.  
  87.            catch (Exception error)
  88.            {
  89.                MessageBox.Show(error.Message, "Aviso:",
  90.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  91.            }
  92.        }
  93.  
  94.        // Al cerrar el formulario, cierra el puerto si está abierto.
  95.        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  96.        {
  97.            try
  98.            {
  99.                serialPort1.Close(); // Cerrar puerto.
  100.            }
  101.  
  102.            catch (Exception error)
  103.            {
  104.                MessageBox.Show(error.Message, "Aviso:",
  105.                MessageBoxButtons.OK, MessageBoxIcon.Warning);
  106.            }
  107.        }
  108.  
  109.        // Al recibir datos.
  110.        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  111.        {
  112.            // Acumula los caracteres recibidos a nuestro 'buffer' (string).
  113.            recibidos += serialPort1.ReadExisting();
  114.  
  115.            // Invocar o llamar al proceso de tramas.
  116.            Invoke(new EventHandler(Actualizar));
  117.        }
  118.  
  119.        // Procesar los datos recibidos en el bufer y extraer tramas completas.
  120.        private void Actualizar(object sender, EventArgs e)
  121.        {
  122.  
  123.            // Asignar el valor de la trama al richTextBox.
  124.            richTextBox1.Text += recibidos;
  125.  
  126.            // Pasar a hexadecimal.
  127.            foreach (byte b in recibidos)
  128.            {
  129.                // x = minúscula, X = mayúscula.
  130.                richTextBox1.Text += b.ToString("X2");
  131.            }
  132.  
  133.            // Nueva línea.
  134.            richTextBox1.Text += Environment.NewLine;
  135.  
  136.            // Pasar a binario.
  137.            foreach (string leer in recibidos.Select(c => Convert.ToString(c, 2)))
  138.  
  139.            {
  140.                richTextBox1.Text += leer.ToString();
  141.            }
  142.  
  143.            // Nueva línea.
  144.            richTextBox1.Text += Environment.NewLine;
  145.            richTextBox1.Text += Environment.NewLine;
  146.  
  147.            // Selecciona la posición final para leer los mensajes entrantes.
  148.            richTextBox1.SelectionStart = richTextBox1.Text.Length;
  149.  
  150.            // Mantiene el scroll en la entrada de cada mensaje.
  151.            richTextBox1.ScrollToCaret();
  152.  
  153.            // Limpiar.
  154.            recibidos = "";
  155.        }
  156.  
  157.        private void button_Activar_Click(object sender, EventArgs e)
  158.        {
  159.            //byte[] mBuffer = Encoding.ASCII.GetBytes("K60:1\r"); // Comando K60:1 activar.
  160.            byte[] mBuffer = Encoding.ASCII.GetBytes("X87\r"); // Comando X87 Flags.
  161.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  162.        }
  163.  
  164.        private void button_Desactivar_Click(object sender, EventArgs e)
  165.        {
  166.            byte[] mBuffer = Encoding.ASCII.GetBytes("K60:0\r"); // Comando K60:0 desactivar.
  167.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  168.        }
  169.  
  170.        private void button_Mute_temporal_Click(object sender, EventArgs e)
  171.        {
  172.            byte[] mBuffer = Encoding.ASCII.GetBytes("K60:2\r"); // Comando K60:2 Mute temporal.
  173.            serialPort1.Write(mBuffer, 0, mBuffer.Length);
  174.        }
  175.  
  176.        private void button_Limpiar_Click(object sender, EventArgs e)
  177.        {
  178.            // Limpiar.
  179.            richTextBox1.Clear();
  180.        }
  181.    }
  182. }

¿Alguna idea?

Saludos camaradas. ;)
196  Programación / .NET (C#, VB.NET, ASP) / Re: Leer información de una SAI / UPS en: 31 Marzo 2021, 00:59 am
Hola:

Haciendo experimento, aunque no me sale del todo bien, probando la página 15 / 21 del documento. Si me funciona el Activar y Desactivar el Zumbador de la UPS y en el display me muestra que si funcina.

Aquí les dejo avances.


197  Programación / .NET (C#, VB.NET, ASP) / Re: Añadir elementos al comboBox en: 29 Marzo 2021, 21:25 pm
Buenas:

Lo he intentado hacerlo en Windows Form con.Net 5.0.




Código fuente C#
:

Código
  1. using System;
  2. using System.Management; // No olvidar y añadir en Dependencias, NuGet.
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Windows.Forms;
  6.  
  7. namespace Lector_discos_Net_5_01_cs
  8. {
  9.    public partial class Form1 : Form
  10.    {
  11.        public Form1()
  12.        {
  13.            InitializeComponent();
  14.        }
  15.  
  16.        // Variable.
  17.        public static string datos = "";
  18.  
  19.        [DllImport("winmm.dll")]
  20.        public static extern Int32 mciSendString(string lpstrCommand,
  21.            StringBuilder lpstrReturnString,
  22.            int uReturnLength,
  23.            IntPtr hwndCallback);
  24.  
  25.        StringBuilder rt = new StringBuilder(127);
  26.  
  27.        private void button_Abrir_Click(object sender, EventArgs e)
  28.        {
  29.            label_Mensaje.Text = "Abriendo...";
  30.            Application.DoEvents();
  31.            discoSiNo();
  32.            mciSendString("set CDAudio!" + comboBox_Unidad.Text + " door open", rt, 127, IntPtr.Zero);
  33.  
  34.            /*
  35.                Si quieres por ejemplo elegir la unidad que quieras, en este caso la H, se le asigana !H
  36.                como indica abajo. En vez de CDAudio, CDAudio!H.
  37.                mciSendString("set CDAudio!H door open", rt, 127, IntPtr.Zero);
  38.             */
  39.  
  40.            label_Mensaje.Text = "Abierto.";
  41.  
  42.        }
  43.  
  44.        private void button_Cerrar_Click(object sender, EventArgs e)
  45.        {
  46.            label_Mensaje.Text = "Cerrando...";
  47.            Application.DoEvents();
  48.            mciSendString("set CDAudio!" + comboBox_Unidad.Text + " door closed", rt, 127, IntPtr.Zero);
  49.            label_Mensaje.Text = "Cerrado.";
  50.            label_Mensaje_disco.Text = "Disco en el lector: Leyendo...";
  51.            discoSiNo();
  52.        }
  53.  
  54.        // Lectura de dispositivos.
  55.        void ConsigueComponentes(string hwclass, string syntax)
  56.        {
  57.            ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM " + hwclass);
  58.            foreach (ManagementObject mj in mos.Get())
  59.            {
  60.                if (Convert.ToString(mj[syntax]) != "")
  61.                {
  62.                    datos = Convert.ToString(mj[syntax]);
  63.                }
  64.            }
  65.        }
  66.  
  67.        // Comprobar si hay disco en el lector.
  68.        void discoSiNo()
  69.        {
  70.            // Disco en la unidad del lector.
  71.            ConsigueComponentes("Win32_CDROMDrive", "MediaLoaded");
  72.  
  73.            // ¿Disco en el lector?
  74.            if (datos == "True")
  75.            {
  76.                label_Mensaje_disco.Text = "Disco en el lector: Sí.";
  77.            }
  78.  
  79.            else
  80.            {
  81.                label_Mensaje_disco.Text = "Disco en el lector: No.";
  82.            }
  83.  
  84.            // Limpiar.
  85.            datos = "";
  86.  
  87.        }
  88.  
  89.        private void Form1_Load(object sender, EventArgs e)
  90.        {
  91.            discoSiNo();
  92.  
  93.            // Nombre de la unidad.
  94.            ConsigueComponentes("Win32_CDROMDrive", "Id");
  95.  
  96.            comboBox_Unidad.Items.Add(datos);
  97.            comboBox_Unidad.Text = datos.ToString();
  98.        }
  99.    }
  100. }


Código WindowsForm .Net 5.0
:

Código
  1. namespace Lector_discos_Net_5_01_cs
  2. {
  3.    partial class Form1
  4.    {
  5.        /// <summary>
  6.        ///  Required designer variable.
  7.        /// </summary>
  8.        private System.ComponentModel.IContainer components = null;
  9.  
  10.        /// <summary>
  11.        ///  Clean up any resources being used.
  12.        /// </summary>
  13.        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  14.        protected override void Dispose(bool disposing)
  15.        {
  16.            if (disposing && (components != null))
  17.            {
  18.                components.Dispose();
  19.            }
  20.            base.Dispose(disposing);
  21.        }
  22.  
  23.        #region Windows Form Designer generated code
  24.  
  25.        /// <summary>
  26.        ///  Required method for Designer support - do not modify
  27.        ///  the contents of this method with the code editor.
  28.        /// </summary>
  29.        private void InitializeComponent()
  30.        {
  31.            this.button_Abrir = new System.Windows.Forms.Button();
  32.            this.button_Cerrar = new System.Windows.Forms.Button();
  33.            this.groupBox_Bandeja = new System.Windows.Forms.GroupBox();
  34.            this.label_Mensaje = new System.Windows.Forms.Label();
  35.            this.comboBox_Unidad = new System.Windows.Forms.ComboBox();
  36.            this.label_Unidad = new System.Windows.Forms.Label();
  37.            this.label_Mensaje_disco = new System.Windows.Forms.Label();
  38.            this.groupBox_Bandeja.SuspendLayout();
  39.            this.SuspendLayout();
  40.            //
  41.            // button_Abrir
  42.            //
  43.            this.button_Abrir.Location = new System.Drawing.Point(32, 146);
  44.            this.button_Abrir.Name = "button_Abrir";
  45.            this.button_Abrir.Size = new System.Drawing.Size(92, 47);
  46.            this.button_Abrir.TabIndex = 0;
  47.            this.button_Abrir.Text = "&Abrir";
  48.            this.button_Abrir.UseVisualStyleBackColor = true;
  49.            this.button_Abrir.Click += new System.EventHandler(this.button_Abrir_Click);
  50.            //
  51.            // button_Cerrar
  52.            //
  53.            this.button_Cerrar.Location = new System.Drawing.Point(155, 146);
  54.            this.button_Cerrar.Name = "button_Cerrar";
  55.            this.button_Cerrar.Size = new System.Drawing.Size(92, 47);
  56.            this.button_Cerrar.TabIndex = 1;
  57.            this.button_Cerrar.Text = "&Cerrar";
  58.            this.button_Cerrar.UseVisualStyleBackColor = true;
  59.            this.button_Cerrar.Click += new System.EventHandler(this.button_Cerrar_Click);
  60.            //
  61.            // groupBox_Bandeja
  62.            //
  63.            this.groupBox_Bandeja.Controls.Add(this.label_Mensaje);
  64.            this.groupBox_Bandeja.Location = new System.Drawing.Point(12, 12);
  65.            this.groupBox_Bandeja.Name = "groupBox_Bandeja";
  66.            this.groupBox_Bandeja.Size = new System.Drawing.Size(249, 117);
  67.            this.groupBox_Bandeja.TabIndex = 2;
  68.            this.groupBox_Bandeja.TabStop = false;
  69.            this.groupBox_Bandeja.Text = "Bandeja:";
  70.            //
  71.            // label_Mensaje
  72.            //
  73.            this.label_Mensaje.AutoSize = true;
  74.            this.label_Mensaje.Font = new System.Drawing.Font("Segoe UI", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
  75.            this.label_Mensaje.Location = new System.Drawing.Point(20, 40);
  76.            this.label_Mensaje.Name = "label_Mensaje";
  77.            this.label_Mensaje.Size = new System.Drawing.Size(54, 50);
  78.            this.label_Mensaje.TabIndex = 0;
  79.            this.label_Mensaje.Text = "¿?";
  80.            //
  81.            // comboBox_Unidad
  82.            //
  83.            this.comboBox_Unidad.FormattingEnabled = true;
  84.            this.comboBox_Unidad.Location = new System.Drawing.Point(310, 159);
  85.            this.comboBox_Unidad.Name = "comboBox_Unidad";
  86.            this.comboBox_Unidad.Size = new System.Drawing.Size(121, 23);
  87.            this.comboBox_Unidad.TabIndex = 3;
  88.            //
  89.            // label_Unidad
  90.            //
  91.            this.label_Unidad.AutoSize = true;
  92.            this.label_Unidad.Location = new System.Drawing.Point(310, 132);
  93.            this.label_Unidad.Name = "label_Unidad";
  94.            this.label_Unidad.Size = new System.Drawing.Size(48, 15);
  95.            this.label_Unidad.TabIndex = 4;
  96.            this.label_Unidad.Text = "Unidad:";
  97.            //
  98.            // label_Mensaje_disco
  99.            //
  100.            this.label_Mensaje_disco.AutoSize = true;
  101.            this.label_Mensaje_disco.Font = new System.Drawing.Font("Segoe UI", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
  102.            this.label_Mensaje_disco.Location = new System.Drawing.Point(12, 198);
  103.            this.label_Mensaje_disco.Name = "label_Mensaje_disco";
  104.            this.label_Mensaje_disco.Size = new System.Drawing.Size(269, 40);
  105.            this.label_Mensaje_disco.TabIndex = 5;
  106.            this.label_Mensaje_disco.Text = "Disco en el lector: ";
  107.            //
  108.            // Form1
  109.            //
  110.            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
  111.            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  112.            this.ClientSize = new System.Drawing.Size(463, 247);
  113.            this.Controls.Add(this.label_Mensaje_disco);
  114.            this.Controls.Add(this.label_Unidad);
  115.            this.Controls.Add(this.comboBox_Unidad);
  116.            this.Controls.Add(this.button_Abrir);
  117.            this.Controls.Add(this.groupBox_Bandeja);
  118.            this.Controls.Add(this.button_Cerrar);
  119.            this.Name = "Form1";
  120.            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  121.            this.Text = "Lector disco C# 2019 - .Net 5.0";
  122.            this.Load += new System.EventHandler(this.Form1_Load);
  123.            this.groupBox_Bandeja.ResumeLayout(false);
  124.            this.groupBox_Bandeja.PerformLayout();
  125.            this.ResumeLayout(false);
  126.            this.PerformLayout();
  127.  
  128.        }
  129.  
  130.        #endregion
  131.  
  132.        private System.Windows.Forms.Button button_Abrir;
  133.        private System.Windows.Forms.Button button_Cerrar;
  134.        private System.Windows.Forms.GroupBox groupBox_Bandeja;
  135.        private System.Windows.Forms.Label label_Mensaje;
  136.        private System.Windows.Forms.ComboBox comboBox_Unidad;
  137.        private System.Windows.Forms.Label label_Unidad;
  138.        private System.Windows.Forms.Label label_Mensaje_disco;
  139.    }
  140. }

Aquí se trata que no me sale. Es que tengo dos unidades de disco CD-ROM / DVD-ROM.
Se me agrega solo la F:, Falta la G:, pero siempre que sea sea unidad de disco.

Saludos.
198  Programación / .NET (C#, VB.NET, ASP) / Re: ¿Cómo listar solo unidades DVD y ver su información? en: 29 Marzo 2021, 21:07 pm
Muchísimas gracias. Voy a experimentar.

  ;-) ;-) ;-)
199  Programación / Scripting / Recibir mensajes en: 28 Marzo 2021, 14:39 pm
Quiero recibir mensajes desde el puerto serie usando CMD de Windwos.

Creo un Script gracias a los compañeros de este foro en su día.
Código
  1.    @Echo OFF
  2.    title Arduino CMD y puerto serie
  3.  
  4.    CHCP 1252 >Nul
  5.    MODE.com COM4 BAUD=115200 PARITY=n DATA=8 STOP=1
  6.    :Menu
  7.        CLS
  8.        echo.
  9.        echo.
  10.        echo.                   1.- Luz  ON
  11.        echo.
  12.        echo.                   2.- Luz  OFF
  13.        echo.
  14.        echo.                   3.- Salir
  15.        echo.
  16.        echo.
  17.        echo.
  18.  
  19.        CHOICE.exe /C "123" /M "                   Escoge una opción "
  20.        echo.
  21.        echo.
  22.        echo.
  23.  
  24.        If %ErrorLevel% EQU 1 (
  25.            copy puerto_Luz_ON.txt  COM1:
  26.            echo Puerto COM1: B
  27.            timeout 5 >nul
  28.            goto Menu
  29.        )
  30.  
  31.        If %ErrorLevel% EQU 2 (
  32.            copy puerto_Luz_OFF.txt COM1:
  33.            echo Puerto COM1: X72
  34.            timeout 5 >nul
  35.            goto Menu
  36.        )
  37.  
  38.        Pause
  39.  
  40.        Exit /B

La cuestión es.

¿Cómo se recibe un mensaje desde el otro lado del puerto serie?

Saludos.
200  Programación / .NET (C#, VB.NET, ASP) / ¿Cómo listar solo unidades DVD y ver su información? en: 28 Marzo 2021, 12:12 pm
Quiero hacer un programa en consola C#, en el cual me muestre cuantas hay y su información. Solo quiero que me muestre unidades de discos DVD, aunque sean SATA, IDE o por USB.

Por ejemplo:
Citar
Unidad F:
     Etiqueta de volumen : 58 Fotos 2020 Tamaño total de la unidad: 4,26 GB.

Unidad G:
     Etiqueta de volumen : Visual Tamaño total de la unidad: 3,09 GB.

Quiero hacerlo así y ya está. El ejemplo que he visto te cuenta todas las unidades como indica abajo y no me interesa.
Código
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Informacion_lector_Consola_01
  5. {
  6.    class Program
  7.    {
  8.        static void Main(string[] args)
  9.        {
  10.            #region Configuración ventana.
  11.            // Título de la ventana.
  12.            Console.Title = "Información lector.";
  13.  
  14.            // Tamaño de la ventana, x, y.
  15.            Console.SetWindowSize(80, 35);
  16.  
  17.            // Color de fondo.
  18.            Console.BackgroundColor = ConsoleColor.White;
  19.  
  20.            // Color de las letras.
  21.            Console.ForegroundColor = ConsoleColor.Black;
  22.  
  23.            // Limpiar pantalla y dejarlo todo en color de fondo.
  24.            Console.Clear();
  25.  
  26.            // Visible el cursor.
  27.            Console.CursorVisible = true;
  28.            #endregion
  29.  
  30.            DriveInfo[] allDrives = DriveInfo.GetDrives();
  31.  
  32.            foreach (DriveInfo d in allDrives)
  33.            {
  34.                Console.WriteLine("Unidad {0}", d.Name);
  35.                Console.WriteLine("  Tipo de unidad:                 {0}", d.DriveType);
  36.                if (d.IsReady == true)
  37.                {
  38.                    Console.WriteLine("  Etiqueta de volumen :       {0}", d.VolumeLabel);
  39.                    Console.WriteLine("  Sistema de archivo:         {0}", d.DriveFormat);
  40.                    Console.WriteLine(
  41.                        "  Espacio disponible para el usuario actual:{0, 15} bytes",
  42.                        d.AvailableFreeSpace);
  43.  
  44.                    Console.WriteLine(
  45.                        "  Espacio total disponible:                 {0, 15} bytes",
  46.                        d.TotalFreeSpace);
  47.  
  48.                    Console.WriteLine(
  49.                        "  Tamaño total de la unidad:                {0, 15} bytes ",
  50.                        d.TotalSize);
  51.                }
  52.            }
  53.  
  54.            // Pulse cualquier tecla para continuar.
  55.            Console.ReadKey();
  56.        }
  57.    }
  58. }

¿Alguna idea?

Saludos.
Páginas: 1 ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [20] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ... 254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines