none
【求助】串口通信问题 RRS feed

  • 问题

  • 我用一个TEXT BOX,按钮按了以后,发送到LABEL里面显示,但是不知道为什么,在调试的过程中,每次按下发送按钮,就会出现错误(端口未打开),但在程序中已经又打开端口的命令了啊,请各位帮忙看看,谢谢。

    Public Class Form1
        'Public SerialPort1 As New System.IO.Ports.SerialPort
       
        Private Sub Form1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim SerialPort1 As New System.IO.Ports.SerialPort
            '设置COM端口属性
            SerialPort1.PortName = "COM2"
            SerialPort1.BaudRate = 9600
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.DataBits = 8
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.Handshake = IO.Ports.Handshake.None
            SerialPort1.RtsEnable = True
    
            SerialPort1.Open()
    
        End Sub
    
        Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
            Dim SerialPort1 As New System.IO.Ports.SerialPort
            Dim Line As String
            'SerialPort1.PortName = "COM2"
            ' SerialPort1.Open()
            If SerialPort1.IsOpen = True Then
                SerialPort1.Write(SendBox.Text)
            End If
            Line = SerialPort1.ReadLine
            ReceiveLabel.Text = Line
        End Sub
    End Class

    另外,我注意到,我的SERIAL PORT控件里面,没有大家所提到的DATA RECEIVE事件,我用的是VS 2010,不知是哪里不一样还是怎么的?

    2012年12月17日 8:01

答案

全部回复