用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)
{
//在这里写接收到数据时的处理
...
}