Member 11957222 Ответов: 1

Отправка sms с помощью команды at in VB.NET ошибка 2010 года


sending SMS using at command in vb.net 2010 error

я использую samsung j2 mobile

Что я уже пробовал:

пожалуйста, проверьте код, где я делаю ошибку

Imports System.Management
Imports System.Threading
Public Class Form1
    Dim rcvdata As String = ""
    Public Function ModemsConnected() As String
        Dim modems As String = ""
        Try
            Dim searcher As New ManagementObjectSearcher( _
                "root\CIMV2", _
                "SELECT * FROM Win32_POTSModem")

            For Each queryObj As ManagementObject In searcher.Get()
                If queryObj("Status") = "OK" Then
                    modems = modems & (queryObj("AttachedTo") & " - " & queryObj("Description") & "***")
                End If
            Next
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            Return ""
        End Try
        Return modems

    End Function

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        Label1.Text = Trim(Mid(ComboBox1.Text, 1, 5))
    End Sub
    Private Sub serialport_datareceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim datain As String = ""
        Dim numbytes As Integer = SerialPort1.BytesToRead
        For i As Integer = 1 To numbytes
            datain &= Chr(SerialPort1.ReadChar)
        Next
        test(datain)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ports() As String
        ports = Split(ModemsConnected(), "***")
        For i As Integer = 0 To ports.Length - 2
            ComboBox1.Items.Add(ports(i))
        Next
    End Sub
    Private Sub test(ByVal indata As String)
        rcvdata &= indata
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With SerialPort1
            .PortName = Label1.Text
            .BaudRate = 19200
            .Parity = IO.Ports.Parity.None
            .DataBits = 8
            .StopBits = IO.Ports.StopBits.One
            .Handshake = IO.Ports.Handshake.RequestToSend
            .RtsEnable = True
            .ReceivedBytesThreshold = 1
            .NewLine = vbCrLf
            .ReadTimeout = 300
            .WriteTimeout = 300
            .RtsEnable = True
            .NewLine = vbCrLf
            .Open()
        End With
        If SerialPort1.IsOpen = True Then
            Label3.Text = "Connected"
        Else
            Label3.Text = "Got some error"
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            With SerialPort1
                .Write("AT+CMGF=1" & vbCrLf)
                Threading.Thread.Sleep(200)

                .Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf) 'TextBox1.text
                Threading.Thread.Sleep(200)

                .Write("TEST MESSAGE" & Chr(26))
                Threading.Thread.Sleep(200)


                MsgBox(rcvdata.ToString)


            End With
            If rcvdata.ToString.Contains(">") Then
                MsgBox("Message sent")
            Else
                MsgBox("Message not sent")
            End If

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        SerialPort1.Close()
    End Sub
End Class

Richard Deeming

Если вы хотите, чтобы кто-то помог вам решить проблему, то вам нужно показать нам полную информацию об ошибке. Вы не можете просто разместить свой код и ожидать, что мы догадаемся!