相关疑难解决方法(0)

.net核心的RS232库

我们正在开发.Net Core中的应用程序,其中一个需要访问串行端口.

当我了解System.IO.Ports将不会在.Net Core中实现时,我正在寻找一个提供该功能的nuget库,但无法与.net内核兼容(VS Code显示错误消息) ).

那里有替代品吗?

更新:我发现正在考虑将官方SerialPort API移植到.Net Core(请参阅https://github.com/dotnet/corefx/issues/984)

serial-port ports nuget .net-core visual-studio-code

12
推荐指数
2
解决办法
6586
查看次数

.NET core 3.0 System.IO.Ports SerialPort 在 RPI 上始终使用 5-10% CPU

当我尝试从 RaspberryPi 上的 Linux 中的串行端口 (uart) 读取数据时,在循环中我总是获得 5-10% 的 CPU 负载。由于串行端口应该是阻塞的,所以这不应该使用那么多的CPU负载,还是我错了?

我尝试了两个代码:

简单的代码

var port = new SerialPort("/dev/ttyUSB0", 57600);
port.Open();
while (true)
{
    if (port.BytesToRead > 0)
    {
    while (port.BytesToRead > 0)
        Console.Write($"{port.ReadByte().ToString("X2")} ");
    Console.WriteLine("");
    }
    Thread.Sleep(100);
}
Run Code Online (Sandbox Code Playgroud)

高级代码

static int blockLimit = 100;
static void Main(string[] args)
{
    var port = new SerialPort("/dev/ttyUSB0", 57600);
    port.Open();
    byte[] buffer = new byte[blockLimit];
    Action kickoffRead = null;
    kickoffRead = delegate
    {
        port.BaseStream.BeginRead(buffer, 0, buffer.Length, delegate (IAsyncResult ar)
        {
        try
        {
            int actualLength …
Run Code Online (Sandbox Code Playgroud)

c# linux serial-port raspberry-pi .net-core

5
推荐指数
1
解决办法
3971
查看次数