READFILE API读串口数据前面几十条正常后面就乱了

weixin_37971462 2017-11-28 06:17:56
网上找了很多 就是没看到 C#的readfile 异步读取,自己搞的又出问题,
自己写的读取的方法
public byte[] Read(int NumBytes, ref int BytesRead)
{
byte[] BufBytes;
byte[] BufOutBytes=null;
BufBytes = new byte[NumBytes];
if (HandleReadFile != -1)
{
KERNEL32.OVERLAPPED ovlCommPort = new KERNEL32.OVERLAPPED();
KERNEL32.PurgeComm(HandleReadFile, PURGE_TXCLEAR);
if (!KERNEL32.ReadFile(HandleReadFile, BufBytes, NumBytes, ref BytesRead, ref ovlCommPort))
{
if (!KERNEL32.GetOverlappedResult(HandleReadFile, ref ovlCommPort, out BytesRead, false))
{
}
Array.Copy(BufBytes, BufOutBytes, BufBytes.Length);
UpdateEpcView();
}
}
return BufOutBytes;
}
...全文
209 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_37971462 2017-11-29
  • 打赏
  • 举报
回复
引用 1 楼 daixf_csdn 的回复:
读串口为什么不用serialPort,而用readfile?
需求如此,serialPort方法我用的没问题。
圣殿骑士18 2017-11-28
  • 打赏
  • 举报
回复
读串口为什么不用serialPort,而用readfile?

110,539

社区成员

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

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

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