C#中以下命令的等价物是什么? comm.Settings =“2400,N,8,1”
答案 0 :(得分:5)
使用以下示例......:
您需要using
:
using System.IO.Ports;
在您的代码中......
SerialPort comPort = new SerialPort("port", 2400, Parity.None, 8, StopBits.One);
// This is one of 7 possible method overloads.
您还可以使用这些属性更改SerialPort实例的设置。
comPort.PortName = "port"; //PortName (string)
comPort.DataBits = 8; //DataBits (int) 5..8
comPort.BaudRate = 2400; //BaudRate (int)
// Default is 9600, can be up to the maximum permitted by the hardware.
comPort.StopBits = StopBits.One; //StopBits
// (StopBits.One, StopBits.None, StopBits.None, StopBits.Two, StopBits.OnePointFive)
comPort.Parity = Parity.None; //Parity
// (Parity.Odd, Parity.Even, Parity.None, Parity.Mark, Parity.Space)
答案 1 :(得分:1)
对于SerialPort类,Baudrate = 2400,Parity = None,DataBits = 8,StopBits = One。只有波特率具有非默认设置。