C# 串口接收超时

来源:百度知道 编辑:UC知道 时间:2024/06/10 20:20:45
用C#写了个串口通信程序,调试的时候无法接受,显示“操作已超时”。
接收部分程序如下:
try
{
//clear the text box
textBox.Text = "";
//read serial port and displayed the data in text box
textBox.Text = sp.ReadLine();
}
catch(System.Exception ex)
{
baudRatelLabel.Text = ex.Message;
}
各位大侠,请问是怎么回事?小妹在此谢过了。。。。
串口是MSCommLib.dll

串口类是什么类?

库是:MSCommLib.dll?吗

sp是什么类型的?是你自己做的类?你在ReadLine内部是如果调用MsComm的

根据自己的应用了.
@MSComm.CommPort = PrinterComm[terminalNumber];
@MSComm.Settings = "19200,N,8,1";//设置通信口参数
@MSComm.InBufferSize = short.MaxValue / 2;//设置MSComm2接收缓冲区为32字节
@MSComm.OutBufferSize = 800;//设置MSComm2发送缓冲区为2字节
@MSComm.InputMode = MSCommLib.InputModeConstants.comInputModeBinary;//设置接收数据模式为二进制形式
@MSComm.EOFEnable = true;
@MSComm.SThreshold = 0;//设置Output 一次从发送缓冲读取字节数为1
@MSComm.InBufferCount = 0;//清除接收缓冲区
@MSComm.OutBufferCount = 0;//清除发送缓冲区
@MSComm.RThreshold = 1;//设置接收1个字节产生OnComm事件
@MSComm.DTREnable = true;//??
@MSComm.Handshaking = MSCommLib.HandshakeConstants.comNone;
//@MSComm.InBufferSize = 1024;