F11和F5执行的结果不一样?我写一个方法,直接F5,出来的结果和F11出来的结果不一样,方法是返回一字符串。F5返回的字符串只有一小部份,而F11返回是全部》

解决方案 »

  1.   

    public string ExeATCommand ( string p_ATCommand )
            {
                string result = string.Empty; // 返回结果内容
                int SendCommandCount = 0; // 重试次数
                if (p_ATCommand != string.Empty && s_port.IsOpen == true)
                {                s_port.Write(p_ATCommand); // 输出命令到串口
                    System.Threading.Thread.Sleep(retryTimeOut); // 延迟指定时间
                    while (SendCommandCount <= retryCount)
                    {
                        // 没有达到重试次数时,始终执行
                        System.Threading.Thread.Sleep(retryTimeOut); // 延迟指定时间
                        result += s_port.ReadExisting(); // 读取结果
                        if (result.Length > 0 && result.Length > p_ATCommand.Length)
                        {
                            result = result.Replace(p_ATCommand + "\r\r\n", string.Empty); // 去掉发送过来的命令,关心结果
                            break;
                        }
                        SendCommandCount++;                }
                }
                
                return result;
            }
      

  2.   

    串口数据读取?如果是的话,就是你的时间延迟问题。你是在什么环境下,vs2003 or vs2005?
      

  3.   

    如果你用的是2005带的com话,数据来的有事件触发。在相应的事件中做处理要合理些。