vue-java-tutorials/CSharp/SerialPort/Base-1-Create/Program.cs

35 lines
903 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO.Ports;
namespace Base_1_Create
{
internal class Program
{
private static void Main(string[] args)
{
var serialPort = new SerialPort
{
// 串口名称
PortName = "COM1",
// 值越大传输越快默认9600
BaudRate = 9600,
// 数据位
DataBits = 8,
// 默认是 1
StopBits = StopBits.One,
// 校验位,校验位 1 的个数
Parity = Parity.Odd,
// 读取时缓冲区字节数
ReadBufferSize = 4096
};
// 打开串口
serialPort.Open();
if (serialPort.IsOpen) Console.WriteLine("串口打开");
// 关闭串口
// serialPort.Close();
}
}
}