yy1125322
驱动牛犊
驱动牛犊
  • 注册日期2002-03-06
  • 最后登录2004-10-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1108回复:0

D12通信???

楼主#
更多 发布于:2002-10-16 20:29
为了发出方波我打算先发一个高Sleep()一定时间后,再发一个低然后再Sleep(),如此反复,可是只见一个高就不变了(见程序1)。后来用连续发多个高和多个低才算弄出了波形,请教为什么程序1不行,以前好像好用过。
程序1
{
。。。
do {    //发高电压
           bResult = WriteFile(hFile,
threadParam->pcIoBuffer,
threadParam->uiLength,
&nBytes,
NULL);
   
if (bResult != TRUE)
{
threadParam->bInThread = FALSE;  //结束线程
            }
else
         //延时
         {
Sleep(threadParam->cycle);
}

          //发低电压
bResult = WriteFile(hFile,
threadParam->TempBuffer,
threadParam->uiLength,
&nBytes,
NULL);

if (bResult != TRUE)
{
           threadParam->bInThread = FALSE;  //结束线程
}
           //延时
          else
{   Sleep(threadParam->cycle);
}
}while(threadParam->bInThread != FALSE);
。。。
}
程序2
{
。。。
int cycle = threadParam->cycle;
do
{for(int m=1;m<=cycle/2;m++)
    { bResult = WriteFile(hFile,
threadParam->pcIoBuffer,
threadParam->uiLength,
&nBytes,
NULL);

   if (bResult != TRUE)
     {
    threadParam->bInThread = FALSE;  //结束线程
      }
    }
    for(int n=1;n<=cycle/2;n++)
   {  
     bResult = WriteFile(hFile,
threadParam->TempBuffer,
threadParam->uiLength,
&nBytes,
NULL);
   if (bResult != TRUE)
 {
   threadParam->bInThread = FALSE;  //结束线程
 }
 }
 } while(threadParam->bInThread == TRUE);
。。。
}
游客

返回顶部