Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iHandle As IntPtr
iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If (iHandle.ToInt32 = -1) Then
MsgBox("can not open port")
Else
MsgBox("Open Succes!")
Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs) '写数据
End If
End Sub