vb.net - 串口读取包括vb.net中已经写入的内容

标签 vb.net sms serial-port at-command

因此,我尝试使用 AT 命令与 gsm 调制解调器通信,我尝试进行基本测试,通过发送命令 AT 并接收 OK 来确保调制解调器正常。问题是我收到“AT Blank Line OK”,有什么方法可以让我发送 AT 时只读取 OK 吗?

Imports System.IO.Ports

Public Class GUI
Dim Device As New System.IO.Ports.SerialPort()
Private Sub GUI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)         Handles MyBase.Load
    Port.Text = "Select Port"
    For Each item As String In IO.Ports.SerialPort.GetPortNames
        Port.Items.Add(item)
    Next
    Device.BaudRate = 9600
    Device.Parity = Parity.None
    Device.StopBits = StopBits.One
    Device.DataBits = 8
    Device.Handshake = Handshake.RequestToSend
    Device.DtrEnable = True
    Device.RtsEnable = True
    Device.NewLine = vbCrLf
    Device.WriteTimeout = 5000
End Sub

Private Sub Port_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Port.SelectedIndexChanged
    Device.PortName = Port.SelectedItem.ToString
End Sub

Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click
    Try
        Device.Open()
        Dim msg As String
        msg = Message.Text
        Device.DiscardInBuffer()
        Device.DiscardOutBuffer()
        Device.Write("AT" & vbCrLf)
        MsgBox(Device.ReadExisting())
    Catch ex As Exception
        MsgBox("Error!")
    End Try
    Device.Close()
End Sub
End Class

最佳答案

听起来调制解调器已设置为回显命令。要关闭此功能,请先尝试发送 E0

More info here

关于vb.net - 串口读取包括vb.net中已经写入的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12205531/

相关文章:

Android连接BLE模块并通过串口发送数据

vb.net - vbscript 和 vb.net 有什么区别?

.net - 使用 ExpertPdf HtmlToPdf Converter 将 html 转换为 pdf

c# - 在对鼠标点击或按钮按下使用react时,是否可以使用代码模板/设计模式?

android - Uri.withAppendedPath 方法

javascript - 可能的?使用 JavaScript 访问客户端串行端口的自包含 html 页面?

vb.net - 当在验证事件处理程序中将 Enabled 设置为 true 时,Tabindex 会被忽略

android - 安装应用程序后的短信

android - 如何在android中发送关于我的位置地址的短信

c - 无法从串口获取数据结构