[英]WriteFile to a serial port always times out and the number of bytes written is zero
[英]WriteFile to Parallel port hangs
我正在編寫一個Activex控件,該控件將訪問並行端口並向其中寫入字節。 我能夠成功打開端口,但是當我寫它時,它掛在WriteFile函數上。 我在這里想念什么嗎? 我正在使用Windows 7
HANDLE portHwd = CreateFile( _T("\\\\.\\LPT1" ),
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (portHwd)
{
char outBuffer[] = _T("This is a test\r\n");
int sz_buffer = strlen(outBuffer);
DWORD bytes_written;
if (!WriteFile( portHwd,
outBuffer,
sz_buffer ,
&bytes_written,
NULL))
{
CloseHandle(portHwd);
GetLastError();
return 1;
}
CloseHandle(portHwd);
}
如果端口的輸出緩沖區已滿,則WriteFile將掛起,直到有空間完成您的請求。 端口上是否有東西並正在讀取內容?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.