Run-time error '8020':
Error reading comm device
Error reading comm device
- 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.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Option Explicit
Const HANDSHAKING_NONE = 0
Const INPUTMODE_TEXT = 0
Private Sub Command1_Click()
Dim FilePath As String
Dim FileSystem As FileSystemObject
Dim 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 FileSystemObject
Set oFile = FileSystem.OpenTextFile(FilePath, ForReading)
'Specify the communication port for the MSComm control.
MSComm1.CommPort = 1
Call ReadWrite(oFile, MSComm1)
End Sub
Sub 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 = False
End Sub
Keywords: KB841700, kbwindowsforms, kberrmsg, kbbug, kbcommport, kbserial, kbwizard