C#串口接收的数据放入到DataSet里面,却出现错误,怎么修改,求帮助

wang4288782 2012-09-05 05:18:57
// 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);这里出现错误,说给定编码中的字符无效。

怎么修改,求帮助
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
愚知 2012-09-05
  • 打赏
  • 举报
回复
str 要转码!
string Newstr = System.TEXT.Encoding.utf8.getstring(str)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧