嗅探串行端口-.net

我有这个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应用程序访问该端口。我该怎么办?

internet收集的

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

如何从该串行端口嗅探数据? [教育目的]

anita999 回答:嗅探串行端口-.net

您不能两次打开串行端口。

如果要查看总线上的内容(嗅探),则可以使用虚拟端口和端口转发,有关完整示例,请参见here

万一您无法满足自己的需求或您有足够的决心重新发明轮子,万无一失,可以用您自己的代码(.NET或其他)替换链接中讨论的任何工具。

本文链接:https://www.f2er.com/3126119.html

大家都在问