从Visual Basic中的串行端口读取

时间:2019-02-25 05:00:17

标签: vb.net serial-port

我想使用VB.NET从串行端口读取。我使用VB写入COM3,然后在下一行从COM3中读取。但是,当我从com端口读取并写入控制台时,看不到任何东西。

Module Module1

Sub Main()

    Dim returnStr As String = ""
    Dim com As IO.Ports.SerialPort = Nothing
    Try
        com = My.Computer.Ports.OpenSerialPort("COM3")
        com.ReadTimeout = 10000

        com.WriteLine("test1")
        Dim Incoming As String = com.ReadLine()

        Console.WriteLine(Incoming)
    Catch ex As TimeoutException
        returnStr = "Error: Serial Port read timed out."
    Finally
        If com IsNot Nothing Then com.Close()
    End Try

    Console.ReadLine()


End Sub

End Module

0 个答案:

没有答案