You are currently offline, waiting for your internet to reconnect

BUG: You receive an "error reading comm device" error message when you try to read from a COM port that is on a remote computer by using the MSComm control in Visual Basic 6.0

When you try to perform a read operation on a COM port by using the MSComm control in Microsoft Visual Basic 6.0, you receive the following error message:
Run-time error '8020':

Error reading comm device
Note This problem occurs only if the following conditions are true:
  • You have connected to a terminal server by using Remote Desktop Protocol (RDP) 5.2 for port redirection.
  • The terminal server is running Microsoft Windows Server 2003.
The MSComm control uses the "return quickly" feature of the Windows COM port driver. If you use RDP 5.2 for port redirection, the status of the "return quickly" feature is set to pending. This setting affects the functionality of the MSComm control.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

Steps to reproduce the problem

Note Make sure that the COM1 port is enabled on your local computer and on the remote computer. Also, verify that you have RDP 5.2 on your local computer. To obtain RDP 5.2, visit the following Microsoft Web site:
  1. Connect a modem to the COM1 port of your local computer.
  2. Restart your local computer.
  3. Install the correct driver for your modem.
  4. Connect to a remote computer that is running Windows Server 2003 through Microsoft Terminal Services by using the RDP 5.2 protocol. To do this, follow these steps:
    1. Click Start, click Run, type mstsc, and then click OK. The Remote Desktop Connection dialog box appears.
    2. In the Computer box, type the Internet Protocol (IP) address of the terminal server that is running Windows Server 2003 and that you want to connect to, and then click Options.
    3. Click the Local Resources tab.
    4. In the Local devices section, make sure that the Serial ports check box is selected, and then click Connect. The Remote Desktop Connection Security Warning dialog box appears.
    5. Click OK. The Log On to Windows dialog box appears.
    6. In the User name box, type your user name.
    7. In the Password box, type your password, and then click OK to connect to the terminal server.
  5. On drive C of the terminal server, create a text file. Name the text file Testfile.txt.
  6. Type Hello World in the Testfile.txt file.
  7. Save the Testfile.txt file, and then close the file.
  8. Start Visual Basic 6.0 on the terminal server.
  9. On the File menu, click New Project. The New Project dialog box appears.
  10. Click Standard EXE, and then click OK. By default, a form that is named Form1 is created.
  11. On the Project menu, click References. The References – Project1 dialog box appears.
  12. Under Available References, click to select the Microsoft Scripting Runtime library, and then click OK.
  13. On the Project menu, click Components. The Components dialog box appears.
  14. Click the Controls tab.
  15. On the Controls tab, click to select the Microsoft Comm Control 6.0 control, and then click OK.
  16. Add an MSComm control and a command button to the Form1 form. By default, the MSComm1 MSComm control and the Command1 command button are added to the form.
  17. On the View menu, click Code to view the code window.
  18. In the code window, add the following code.
    Option ExplicitConst HANDSHAKING_NONE = 0Const INPUTMODE_TEXT = 0Private Sub Command1_Click()Dim FilePath As StringDim FileSystem As FileSystemObjectDim oFile As Object'Make sure that you have the Testfile.txt file on drive C of your computer.FilePath = "C:\Testfile.txt"'Create a new FileSystemObject object, and then open the Testfile.txt file for reading.Set FileSystem = New FileSystemObjectSet oFile = FileSystem.OpenTextFile(FilePath, ForReading)'Specify the communication port for the MSComm control.MSComm1.CommPort = 1Call ReadWrite(oFile, MSComm1)End SubSub ReadWrite(File As Object, MyPort As MSComm)'This procedure performs the following tasks:'1.Configures and opens the MyPort port.'2.Reads the contents of the File object, and then stores the data in a buffer that is named OutBuffer.'3.Writes the data from the OutBuffer buffer to the MyPort port.'4.Reads the data from the MyPort port to a buffer that is named InBuffer.    Dim OutBuffer As Variant    Dim InBuffer As Variant        MyPort.Settings = "57600,N,8,1"     ' Configure the port.    MyPort.Handshaking = HANDSHAKING_NONE    MyPort.EOFEnable = False    MyPort.RThreshold = 0    MyPort.SThreshold = 0    MyPort.InputMode = INPUTMODE_TEXT       ' Specify the buffer size.    MyPort.InBufferSize = 1024       ' Open the port.    MyPort.PortOpen = True        ' Read the buffer and transmit each line over the COM port.    Do        'Read each line of data from the file.       OutBuffer = File.ReadLine                ' Configure the port to read the whole buffer.        MyPort.InputLen = 0                ' Write the data, and then read it.        MyPort.Output = OutBuffer        InBuffer = MyPort.Input      Loop While (File.AtEndOfStream = False) ' Close the port.    MyPort.PortOpen = FalseEnd Sub
  19. On the Run menu, click Start. The Form1 form appears.
  20. Click Command1. You receive the error message that is mentioned in the "Symptoms" section.
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
838291 Some applications cannot access the serial port in Windows Server 2003
318784 MSComm.Input returns comReadError (8020) with some serial ports
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Article ID: 841700 - Last Review: 11/16/2007 09:13:27 - Revision: 1.4

  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • kbwizard kbserial kbcommport kbbug kberrmsg kbwindowsforms KB841700