请高手帮我注释一下C#代码
publicvoidport_DataReceived(objectsender,SerialDataReceivedEventArgse){try{if(e.Event...
public void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
if (e.EventType == SerialData.Chars)
receiveNow.Set();
}
catch (Exception ex)
{
throw ex;
}
}
public string ReadResponse(SerialPort port,int timeout)
{
string buffer = string.Empty;
try
{
do
{
if (receiveNow.WaitOne(timeout, false))
{
string t = port.ReadExisting();
buffer += t;
}
else
{
if (buffer.Length > 0)
throw new ApplicationException("Response received is incomplete.");
else
throw new ApplicationException("No data received from phone.");
}
}
while (!buffer.EndsWith("\r\nOK\r\n") && !buffer.EndsWith("\r\n> ") && !buffer.EndsWith("\r\nERROR\r\n"));
}
catch (Exception ex)
{
throw ex;
}
return buffer;
} 展开
{
try
{
if (e.EventType == SerialData.Chars)
receiveNow.Set();
}
catch (Exception ex)
{
throw ex;
}
}
public string ReadResponse(SerialPort port,int timeout)
{
string buffer = string.Empty;
try
{
do
{
if (receiveNow.WaitOne(timeout, false))
{
string t = port.ReadExisting();
buffer += t;
}
else
{
if (buffer.Length > 0)
throw new ApplicationException("Response received is incomplete.");
else
throw new ApplicationException("No data received from phone.");
}
}
while (!buffer.EndsWith("\r\nOK\r\n") && !buffer.EndsWith("\r\n> ") && !buffer.EndsWith("\r\nERROR\r\n"));
}
catch (Exception ex)
{
throw ex;
}
return buffer;
} 展开
展开全部
这个不需要高手。我解释一下,因为不知道你的上下文环境,不一定准确,但大目的不会错:
1、public void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
端口数据接收的方法。如果端口的接收值,符合某种类型(EventType),置接收状态,可能是开始接收等。
if (e.EventType == SerialData.Chars)
receiveNow.Set();
2、public string ReadResponse(SerialPort port,int timeout)
从端口中接收的数据的方法。在充许的端口超时范围内(timeout),接收数据到buffer,直到接收到中止传送的命令。然后抛出接收完成或未接收到的异常( ApplicationException)。
1、public void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
端口数据接收的方法。如果端口的接收值,符合某种类型(EventType),置接收状态,可能是开始接收等。
if (e.EventType == SerialData.Chars)
receiveNow.Set();
2、public string ReadResponse(SerialPort port,int timeout)
从端口中接收的数据的方法。在充许的端口超时范围内(timeout),接收数据到buffer,直到接收到中止传送的命令。然后抛出接收完成或未接收到的异常( ApplicationException)。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询