|
DWORD SendThread (PVOID pArg)
{
HWND hWnd, hwndSText;
DWORD cBytes, rc;
BOOL err;
TCHAR szText[TEXTSIZE], szOutputText[TEXTSIZE];
hWnd = (HWND)pArg;
hwndSText = GetDlgItem (hWnd, ID_SENDTEXT);
while (1)
{
rc = WaitForSingleObject (g_hSendEvent, INFINITE);
if (rc == WAIT_OBJECT_0)
{
if (!fContinue)
{
break;
}
// Disable send button while sending
EnableWindow (GetDlgItem (hWnd, ID_SENDBTN), FALSE);
GetWindowText (hwndSText, szText, dim(szText));
lstrcat (szText, TEXT ("\r\n"));
err = WriteFile (hComPort, szText,
lstrlen (szText)*sizeof (TCHAR), &cBytes, 0); /////???????
if (err)
{
// Copy sent text to output window -> recieve text box
wsprintf(szOutputText, TEXT("Send -> "));
lstrcat (szOutputText, szText);
SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0, (LPARAM)szOutputText);
SetWindowText (hwndSText, TEXT ("")); // Clear send text box
}
else
// Else, print error message
{
wsprintf (szText, TEXT ("Send failed err=%d\r\n"),
GetLastError());
SendDlgItemMessage (hWnd, ID_RCVTEXT, EM_REPLACESEL, 0, (LPARAM)szText);
//
}
EnableWindow (GetDlgItem (hWnd, ID_SENDBTN), TRUE);
}
else
{
MessageBox(hWnd, TEXT("Time out"), TEXT("SendThread"), MB_OK);
break;
}
}
return 0;
}
以上是在串口的使用中的发送数据的部分代码 同样的程序串口1运行正常,串口3却在WriteFile()函数调用后返回错误码为1359的错误, 这是什么问题? |
|