简体   繁体   English

WriteFile到并行端口挂起

[英]WriteFile to Parallel port hangs

I am writing an activex control that will access the parallel port and write the bytes to it. 我正在编写一个Activex控件,该控件将访问并行端口并向其中写入字节。 I am able to open the port succesfully but when i write it hangs at WriteFile function. 我能够成功打开端口,但是当我写它时,它挂在WriteFile函数上。 Did i miss anything here? 我在这里想念什么吗? I am using Windows 7 我正在使用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);
      }

If the port's output buffer is full then WriteFile will hang until there is room to complete your request. 如果端口的输出缓冲区已满,则WriteFile将挂起,直到有空间完成您的请求。 Is there something attached to the port and reading from it? 端口上是否有东西并正在读取内容?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM