创建两个虚拟串口
socat -d -d -d PTY,b115200,raw,echo=0,crnl,link=/home/user/ttyS110 PTY,b115200,raw,echo=0,crnl,link=/home/user/ttyS111
cat /home/user/ttyS110 echo "hello" > /home/user/ttyS111 有效!
尝试打开:
using System;
using System.IO.Ports;
namespace qqq
{
class MainClass
{
public static void Main (string[] args)
{
SerialPort fSerialPort = new SerialPort();
fSerialPort.PortName = "/home/user/ttyS111";
fSerialPort.BaudRate = 115200;
fSerialPort.Parity = Parity.None;
fSerialPort.DataBits = 8;
fSerialPort.StopBits = StopBits.One;
fSerialPort.ReadTimeout = 500;
fSerialPort.WriteTimeout = 500;
try
{
fSerialPort.Open();
Console.WriteLine("Open port");
}
catch (Exception e)
{
Console.WriteLine("Open port ERROR! " + e.Message);
}
}
}
}
捕获异常“无效参数”。
如何从 c# (Mono) 打开虚拟端口?