使用以下示例...:
你需要这个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)
| 归档时间: |
|
| 查看次数: |
446 次 |
| 最近记录: |