C#相当于VB 6串口SETTINGS功能

bbo*_*sak 2 c# vb6

在C#中,以下命令的等价物是什么?comm.Settings ="2400,N,8,1"

oco*_*odo 5

使用以下示例...:

你需要这个using:

using System.IO.Ports;
Run Code Online (Sandbox Code Playgroud)

在你的代码中......

SerialPort comPort = new SerialPort("port", 2400, Parity.None, 8, StopBits.One); 
// This is one of 7 possible method overloads.
Run Code Online (Sandbox Code Playgroud)

您还可以使用这些属性更改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)
Run Code Online (Sandbox Code Playgroud)