在C#应用程序不发送的串行数据 [英] Not sending Serial data in C# application

查看:156
本文介绍了在C#应用程序不发送的串行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Arduinos,使用串行监视器通过串行端口允许信息交换。

I have two Arduinos that allow messages exchange via Serial Port using Serial Monitor.

如果我在两侧使用串行监视器一切工作正常。如果我用我的C#应用​​程序没有任何反应。我试图从串行监视器用于发送C#应用程序和它的作品而不是相反。

If I use Serial Monitor in both sides everything works fine. If I use my C# application nothing happens. I tried to send from Serial Monitor for C# App and it works but not the reverse.

// ...
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 DtrEnable 都启用

推荐答案

那么,与 Console.Write(msgBox.Text); 我意识到这只是一个愚蠢的问题,我是不是送的 msgBox.Text 我想要的。它应该是:

Well, with Console.Write(msgBox.Text); I realized it was just a silly problem, I was not sending 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);
}

这篇关于在C#应用程序不发送的串行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆