串口输出一直为0

sidney2008 2009-09-02 12:18:22
如题,WriteFile(m_hCom,sendBuf,dwLength,&length,&osWrite);以后length的值一直为0,这不就表示一个数据都没发出去?writefile之前调用的ClearCommError(m_hCom,&dwErrorFlags,&ComStat);dwErrorFlags的值也一直为0,我不懂这0表示什么,在线等高手解答。
...全文
519 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝隆 2009-09-04
  • 打赏
  • 举报
回复
学习
一条晚起的虫 2009-09-04
  • 打赏
  • 举报
回复
//你用的是异步方式,函数不等操作完成就返回了,所以length == 0
feilinhe 2009-09-02
  • 打赏
  • 举报
回复
看MSDN的解释:
lpNumberOfBytesWritten [out, optional]
A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter. WriteFile sets this value to zero before doing any work or error checking. Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results.

This parameter can be NULL only when the lpOverlapped parameter is not NULL.

For more information, see the Remarks section.

Ghost90 2009-09-02
  • 打赏
  • 举报
回复
异步发送

if(!WriteFile(m_hCom,sendBuf,dwLength,&length,&osWrite))
{
if(GetLastError()==ERROR_IO_PENDING)
GetOverlappedResult(m_hCom,&m_osWrite,&length,TRUE);
}

2,643

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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