首次发送时串口挂断

时间:2016-12-27 15:37:31

标签: vb.net serial-port

我遇到SerialPort问题;当我试着写它时,它就会挂断。

Private Function Conectar(ByVal PortName As String, ByVal PortBps As UInteger) As Boolean
        If Not Me.SmsSerialPort.IsOpen Then
            Try
                Me.PrintLog(String.Format("Port {0} at {1} BPS", PortName, PortBps.ToString))
                Me.SmsSerialPort.PortName = PortName
                Me.SmsSerialPort.BaudRate = CInt(PortBps)
                Me.SmsSerialPort.Parity = Parity.None
                Me.SmsSerialPort.Handshake = Handshake.None
                Me.SmsSerialPort.WriteTimeout = 500
                Me.SmsSerialPort.Open()
                Me.SmsSerialPort.RtsEnable = True
                Me.LastValidCom = PortName
            Catch ex As Exception
                Me.PrintLog("Error: " + ex.Message, True)
                Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
                Dim result As Boolean = False
                Return result
            End Try
        End If
        Me.PrintLog("Starting modem", True)

        'The following line was added to test the COM comunication directly without using SendAtCommand function but doesn't work either.
        Me.SmsSerialPort.Write("AT" & vbCrLf)

        If Not Me.SendAtCommand("AT" & vbCrLf & "AT" & vbCrLf & "ATV1", 3, True) Then
            Me.OkRecibido = False
            Return False
        End If
End Function

我使用相同的端口和另外两个应用程序,一个是由我设计的,另一个是由Microsoft设计的,两个都可以在同一个端口上运行。

有一种方法可以知道还在等什么? 有没有什么方法可以更深入地调试Visual Studio向我显示的绿线和箭头?

0 个答案:

没有答案