COM serial port

-1

I'm trying to run a code every time, where it takes the value sent by the Arduino COM port, prints it in a textbox, and then generates an insert in the mysql database.

It just read what was sent by the COM port and does not execute the insert. Help me.

 private void timer1_Tick_1(object sender, EventArgs e)
    {
        serialPort1.Open();
        string entrada = serialPort1.ReadLine();
        serialPort1.Close();
        txtIDTag.Text = entrada;

        if (txtIDTag.Text == "Gol")
        {
            string sql = "insert into tcc (Carro,Placa,Fabricante,Ano,Cor,Status,Data) value ('" + txtIDTag.Text + "','SCD - 4365','VW','2010','PRETO','NOVO', NOW())";

            comando.CommandText = sql;

            conexao.Open();

            comando.ExecuteNonQuery();

            conexao.Close();

            MessageBox.Show("Dados cadastrados com sucesso.");

            txtIDTag.Text = "";
        }}

I tried to get the IF that he executed.

    
asked by anonymous 03.04.2017 / 15:26

1 answer

1

Probably because the return of the serial port is done in byte, at least in Java, so try to find something to concatenate the information. Because the return passes as follows

Byte G - > Byte O - > Byte L

So if you compare only G maybe it works.

    
05.04.2017 / 04:54