C#怎么使用COM端口?
答案:1 悬赏:40 手机版
解决时间 2021-03-29 13:21
- 提问者网友:謫仙
- 2021-03-28 12:48
C#怎么使用COM端口?
最佳答案
- 五星知识达人网友:煞尾
- 2021-03-28 14:16
用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)
{
//在这里写接收到数据时的处理
...
}
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)
{
//在这里写接收到数据时的处理
...
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯