【发布时间】:2021-10-25 05:44:04
【问题描述】:
我目前正在尝试构建一个 Windows 窗体应用程序,该应用程序通过串行 com 从 arduino 获取传感器数据。
在 arduino IDE 中检查时,数据会正确写入串行端口。 但我不知道如何通过 c# 读取数据。
class Program
{
static SerialPort SP;
static void Main(string[] args)
{
SP = new SerialPort();
SP.PortName = "COM7";
SP.BaudRate = 9600;
SP.Handshake = System.IO.Ports.Handshake.RequestToSend;
SP.Open();
while (true)
{
Console.WriteLine(DateTime.Now.ToString() + " : " + SP.ReadLine());
}
}
}
我的猜测是端口设置不正确,但我不知道我错过了什么。
目标只是从 arduino 接收字符串,我不一定需要向 arduino 发送任何数据。
编辑:我正在使用 arduino micro
【问题讨论】:
-
添加一些当前行为的更多细节,究竟是什么不以哪种方式工作?你收到什么了吗?接受小冲突,.....
-
我什么也没收到,用于测试 arduino 每 0.5 秒在串口上打印一个新数字 端口上没有读取这些数字,但在打开串口时都按预期显示arduino IDE。