Home > Blockchain >  Why does the Arduino delay receiving data from Visual Basic.NET?
Why does the Arduino delay receiving data from Visual Basic.NET?

Time:12-04

This is the Arduino code for the receiver

void loop() {
  
  int dir = Serial.read();
  if (dir == 'A') {
    Motors();
  }

  if (dir == 'B') {
    Zero();
  }

}

and this Visual Basic.NET Code

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Button1.Enabled = True Then
            SerialPort1.Open()
            SerialPort1.Write("A")
            SerialPort1.Write(txtAngle1Mr.Text   Chr(13))
            SerialPort1.Close()
        End If
    End Sub

okay when I click on the button , my program write "A" ON SERIAL And if write "A" ON SERIAL Arduino Will Run "Motors" Function

Arduino is Delaying to receive data from Visual Basic.NET and run "Motors" Function

Arduino runs "Motors" Function. but he's Delaying

why Arduino is Delaying ? and how can I solve this ?

CodePudding user response:

I solved problem

In VisualBasic.NET I was sending one value by just 1 code.

SerialPort1.Write(TextBox1.Text   Chr(13))

and in Arduino I was receving the data by just one code

int example 1 = Serial.parseInt();

the problem is

in arduino I was receving more than value and I just send one value! I was receiving data that I did not send!

in VisualBasic I wrote this

SerialPort1.Write(TextBox1.Text   Chr(13))

in Arduino I wrote this

int example1 = Serial.parseInt();
int example2 = Serial.parseInt();
int example3 = Serial.parseInt();
int example4 = Serial.parseInt();

look. I was sending one value and the arduino was trying to receive more than one value

This is why the Arduino was late in receiving data

I hope you understand me

Thank you all

  • Related