Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:45:00+00:00 2026-05-20T12:45:00+00:00

I’m developing an application in C# to capture info from the serial port. The

  • 0

I’m developing an application in C# to capture info from the serial port. The problem that I have is that the application is not reading exactly the same information that I’m reading from the hyperterminal.

My question is, has anyone have this problem?, what properties can II check from my app that can be generating this problem?. I want to make a copy of the port configuration that I have in the hyperterminal, onto my application.

Thanks you for your help.

    void recibir(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        Thread.Sleep(0250);
        string crudo = sptSerial.ReadExisting();
        if (crudo.Equals("\0\0\0\0\0\0\0\0"))
        {
            MessageBox.Show("ERROR DE LECTURA","Control Toyota",MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        else
        {
            string binario = "";
            string binarioFinal = "";
            string binarioProcesado = "";
            int numero = 0;
            string info = convertAsciiTextToHex(crudo);
            binario = hex2binary(info);
            binarioProcesado = completarPaquete(binario);
            //binarioFinal = binarioProcesado.Substring(10, 16);
            if (flagCompletado == 1)
            {
                binarioFinal = binarioProcesado.Substring(5);
            }
            else
            {
                if (binarioProcesado.Length > 20)
                {
                    binarioFinal = binarioProcesado.Substring(5);
                }
                else
                {
                    binarioFinal = binarioProcesado.Substring(4);
                }
            }

            numero = ToDecimal(binarioFinal);
            csTarjeta tarjeta = new csTarjeta();
            string x = "";
            string y = "";
            try
            {
                tarjeta = csMTRSerial.armarPersona(numero);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR COMUNICANDO CON LA BASE DE DATOS\n" + ex.Message);
            }
            try
            {
                tarjeta.sUbicacion = csMTRSerial.devolverPosicion();
                x = tarjeta.sUbicacion.Substring(11, 10);
                x = x.Replace(",", ".");
                y = tarjeta.sUbicacion.Substring(0, 10);
                y = y.Replace(",", ".");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR COMUNICANDO CON EL GPS\n" + ex.Message);
            }

            if (tarjeta.sValido == 1)
            {
                lblAviso.Text = "";
                lblNombre.Text = "Nombre: " + tarjeta.sNombre;
                //lblApellido.Text = "Apellido: " + tarjeta.sApellido;
                lblNroTarjeta.Text = "Nro. de Tarjeta: " + tarjeta.sNroTarjeta.ToString();

                MemoryStream stream = new MemoryStream(tarjeta.sFoto);
                picFoto.Visible = true;
                picFoto.Image = Image.FromStream(stream);
                stream.Dispose();
                stream.Close();
                lblAviso.BackColor = Color.Green;
                lblAviso.Text = "TARJETA VALIDA";
                lblAviso.ForeColor = Color.Black;


            }
            else
            {
                lblNombre.Text = "";
                lblNroTarjeta.Text = "";
                picFoto.Visible = false;
                lblAviso.BackColor = Color.Red;
                lblAviso.Text = "TARJETA NO VALIDA";
                lblAviso.ForeColor = Color.White;
            }
            csRuta ruta = new csRuta();
            ruta.sID = idRuta;
            ruta.sNombre = nombreRecorrido;
            csMTRSerial.insertarFichada(tarjeta.sNroTarjeta, tarjeta.sNombre, tarjeta.sValido, x, y, nombreRecorrido);
            flagCompletado = 0;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:45:01+00:00Added an answer on May 20, 2026 at 12:45 pm
        string crudo = sptSerial.ReadExisting();
    

    You are reading a string from the device, then seem to make a lot of effort to turn that back into binary. This doesn’t work well, you are for one subject to the conversion of bytes to characters as determined by the SerialPort.Encoding property. Which defaults to ASCII, turning any byte value > 0x7f to a question mark.

    Read binary data with the SerialPort.Read() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.