请教串口读数问题?
public string conver(){
string rus = "";
XmlDocument xml = new XmlDocument();
xml.Load("C:\\txcs.xml");
XmlNode root = xml.SelectSingleNode("//纳伏表");
string com1 = root.FirstChild.InnerText;
string rate1 = root.LastChild.InnerText;
SerialPort sm = new SerialPort();
sm = com(com1, rate1);
sm.Open();
if (sm.IsOpen == false)
MessageBox.Show("纳伏表串口未打开!!!");
sm.WriteLine("CONF:VOLT:DC 100,DEF,(@2)");
sm.WriteLine("CONF:VOLT:DC 100,DEF,(@1)");
sm.WriteLine("SYSTem:REMote");//读一个数据设置
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
sm.WriteLine("READ?");
byte[] ru;
int Count;
Count = sm.BytesToRead;
ru = new Byte[Count];
sm.Read(ru, 0, Count);
for (int j = 0; j < Count; j++)
{
rus =rus+ru[j];
}
}
sm.Close();
return rus;
}
用上面程序读取串口中的值时,发现串口缓冲器中一直没有值, sm.BytesToRead一直为零,但是用串口调试软件发送READ?后,可以从缓冲器中读取值,请问我上面那里出了问题,缓冲器中没有值?