简体   繁体   English

读取的串行端口包括在vb.net中写入的内容

[英]Serial port read includes what has been written in vb.net

So I am trying to talk to a gsm modem using AT commands, I'm trying to do a basic test to make sure the modem is ok by sending the command AT and receiving OK. 因此,我试图与使用AT命令的gsm调制解调器进行通信,我正在尝试进行基本测试,以通过发送命令AT并接收OK来确保调制解调器正常。 The issue is that I'm receiving "AT Blank Line OK", is there any way so when I send AT, I only read 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

Sounds like the modem is set to Echo commands. 听起来好像调制解调器已设置为Echo命令。 To turn this off try sending E0 first. 要关闭此功能,请尝试先发送E0

More info here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM