阅读:1108回复:0
D12通信???
为了发出方波我打算先发一个高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); 。。。 } |
|