我想将串口的writeFile函数包含到一个函数中并多次调用该函数。我写了以下代码。但是函数返回false。我找不到任何错误。
bool WriteBuffer (char *lpBuf,DWORD dwToWrite){
// DWORD dwBytesWritten;
// DWORD dwToWrite;
printf("%s", lpBuf);
if(!WriteFile(hSerial, lpBuf, sizeof(lpBuf) ,&dwBytesWritten, NULL))
{
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lastError,
1024,
NULL);
CloseHandle(hSerial);
hSerial=NULL;
printf("ERROR in WRITE FILE \n");
return false;
//Handle Error Condition
}
printf("You wrote'%s'",lpBuf);
return true;
}