C#串口接收的数据放入到DataSet里面,却出现错误,怎么修改,求帮助
// Obtain the number of bytes waiting in the port's buffer获得的字节数放在串口的缓冲区
int bytes = comport.BytesToRead;
// Create a byte array buffer to hold the incoming data创建一个字节数组缓冲来保存传入的数据
byte[] buffer = new byte[bytes];
// Read the data from the port and store it in our buffer从串口读取数据并将其存储在缓冲中
comport.Read(buffer, 0, bytes);
for (int i = 0; i < buffer.Length; i++)
{
buf.Add(buffer[i]);
}
MemoryStream str = new MemoryStream(buf.ToArray());
DataSet.ReadXml(str);这里出现错误,说给定编码中的字符无效。
怎么修改,求帮助