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

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

问题描述

我有两个 Arduino,允许使用串行监视器通过串行端口交换消息.

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);
}

RtsEnableDtrEnable 都已启用

推荐答案

好吧,使用 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天全站免登陆