我有这个Arduino代码只是为了测试:
int num=0;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(num);
num+=1;
delay(800);
}
现在,它会打印一个整数并将其值加1。当我打开 Serial Monitor 时,它每800毫秒就会打印一次。
我的 Arduino 连接到 PORT-6
现在,如果我尝试访问该端口,则表明该端口正在使用中,我正在尝试从.NET
应用程序访问该端口。我该怎么办?
c#代码进行了一些修改:
using System;
using System.IO.Ports;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static SerialPort _serialPort;
public static void Main()
{
_serialPort = new SerialPort();
_serialPort.PortName = "COM6";//Set your board COM
_serialPort.BaudRate = 9600;
_serialPort.Open();
while (true)
{
string a = _serialPort.ReadExisting();
Console.WriteLine(a);
}
}
}
}
如何从该串行端口嗅探数据? [教育目的]