Do not send serial data in C # application

I have two Arduinos that allow serial messaging using Serial Monitor.

If I use Serial Monitor on both sides, everything works fine. If I use my C # application, nothing happens. I tried sending from Serial Monitor for a C # application and it works, but not vice versa.

// ...
comPort1.Open();
// ...
private void comPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    this.Invoke(new EventHandler(processData));
}
private void processData(object sender, EventArgs e)
{
    string inData = comPort1.ReadExisting();
    msgBoxLog.AppendText(inData);
}
// ...
private void sendButton_Click(object sender, EventArgs e)
{
    string my_str = "my string";
    msgBoxLog.AppendText(msgBox.Text + my_str);
    comPort1.Write(msgBox.Text);
}

RtsEnable and DtrEnable are both included

0
source share
1 answer

Well, with Console.Write(msgBox.Text);I realized that it was just a dumb problem, I did not send msgBox.Text as I wanted. It should be:

private void sendButton_Click(object sender, EventArgs e)
{
    string my_str = "my string";
    comPort1.Write(msgBox.Text); //Console.Write(msgBox.Text);
    msgBoxLog.AppendText(msgBox.Text + my_str);
}
0

Source: https://habr.com/ru/post/1776056/


All Articles