Click here to Skip to main content
14,491,885 members
Rate this:
Please Sign up or sign in to vote.
See more:
sending SMS using at command in 2010 error

i m using samsung j2 mobile

What I have tried:

please check the code where I m doing mistake

Imports System.Management
Imports System.Threading
Public Class Form1
    Dim rcvdata As String = ""
    Public Function ModemsConnected() As String
        Dim modems As String = ""
            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
        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)
    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
    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
        End With
        If SerialPort1.IsOpen = True Then
            Label3.Text = "Connected"
            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
            With SerialPort1
                .Write("AT+CMGF=1" & vbCrLf)

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

                .Write("TEST MESSAGE" & Chr(26))


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

        Catch ex As Exception
        End Try
    End Sub
End Class
Updated 25-Jan-19 6:20am
Richard Deeming 25-Jan-19 11:59am
If you want someone to help you solve an error, then you need to show us the full details of the error. You can't just post your code and expect us to guess!

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100