C#怎么使用COM端口?

最好有实例项目介绍
2024年11月15日 06:31
有1个网友回答
网友(1):

用SerialPort

SerialPort _Serial = new SerialPort
{
PortName = "COM1",
BaudRate = 9600,
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
WriteTimeout = SerialPort.InfiniteTimeout,
ReadTimeout = SerialPort.InfiniteTimeout,
Handshake = Handshake.None,
ReadBufferSize = 1024
};

_Serial.DataReceived += new SerialDataReceivedEventHandle(Serial_DataReceived);

_Serial.Open();


private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//在这里写接收到数据时的处理
...
}