I am Sending an byte from C# winform Application to Arduino And Recieving it back on Winform Application and display it on Text box.
Arduino code
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
int numBytes =1;
void loop()
{
if (Serial.available() > 0)
{
byte data = Serial.read();
Serial.print(data);
delay(1000);
}
}
C# code
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write(new byte[] { 0x52 }, 0, 1);
}
This is serial port receiving function
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//read data
byte data = (byte)serialPort1.ReadByte();
this.Invoke(new EventHandler(delegate
{
richTextBox1.Text += data;
}));
}
I am sending byte 0x052
I want that byte displayed on text box but this will appear in textbox 5650
.
I do not know what I am doing wrong. I actually want to send 3 byte and received 3 byte from both Arduino and C#.I tried many answers from stack overflow but failed to make proper and correct communication between C# and Arduino.