none
GSM SMS VB 2017 RRS feed

  • Question

  • Can anyone tell me why this code does not work ?

    ##################################################

    Imports System
    Imports System.IO.Ports
    Imports System.Threading
    
     Public Class Form1
         Private ReadOnly Read_CSQ As String
    
         Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
             Try
                 Dim ports As String() = SerialPort.GetPortNames
                 Dim port As String
                 Dim Read_CSQ As String
    
                 For Each port In ports
                     ComboBox1.Items.Add(port)
                 Next port
                 ComboBox1.SelectedIndex = 0
    
             Catch ex As Exception
                 MsgBox(ex.Message)
             End Try
    
         End Sub
    
         Private Sub cmdconnect_Click(sender As Object, e As EventArgs) Handles cmdconnect.Click
    
    
             Try
                 With SerialPort1
                     .PortName = ComboBox1.Text
                     .BaudRate = 9600
                     .Parity = Parity.None
                     .StopBits = StopBits.One
                     .DataBits = 8
                     .Handshake = Handshake.RequestToSend
                     .DtrEnable = True
                     .RtsEnable = True
                     .NewLine = vbCrLf
                     .Open()
    
                 End With
    
                 If SerialPort1.IsOpen Then
    
                     Label1.Text = "Connected"
                 Else
                     Label1.Text = "Not Connected"
                 End If
             Catch ex As Exception
    
             End Try
         End Sub
    
         Private Sub cmdsend_Click(sender As Object, e As EventArgs) Handles cmdsend.Click
             Try
                 If SerialPort1.IsOpen Then
                     With SerialPort1
                         .Write("AT" & vbCrLf)
                         Threading.Thread.Sleep(100)
                         .Write("AT+CMGF=1" & vbCrLf)
                         Threading.Thread.Sleep(100)
                         .Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
                         .Write(TextBox2.Text & Chr(26))
                         Threading.Thread.Sleep(100)
                         MsgBox("Sent")
                     End With
                 Else
                     MsgBox("Error on Port")
    
                 End If
             Catch ex As Exception
    
             End Try
         End Sub
         Private Sub CSQ_Click(sender As Object, e As EventArgs) Handles CSQ.Click
    
             Try
                 If SerialPort1.IsOpen Then
                     With SerialPort1
                         .Write("AT+CSQ" & vbCrLf)
                         Threading.Thread.Sleep(100)
                         SerialPort1.ReadTo(CSQ_Textbox.Text)
                     End With
                 End If
             Catch ex As Exception
    
             End Try
         End Sub
     End Class


    ##################################

    I have tested all the hardware using the m2m tester and all functions are working so no hardware or software issues from the GSM device I'm communicating with !

    Any help would be great

    James

    


    Thursday, November 2, 2017 2:33 PM

All replies

  • First off never use an empty try-catch, please adjust and try again.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 2, 2017 2:53 PM
    Moderator
  • Can anyone tell me why this code does not work ?


    ##################################

    I have tested all the hardware using the m2m tester and all functions are working so no hardware or software issues from the GSM device I'm communicating with !

    Any help would be great

    James

    


    What does not working mean? 

    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    Thursday, November 2, 2017 6:02 PM
  • Hi uk-gsm,

    What error did you encounter when you use the code above? Please provide more detailed info here.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 3, 2017 5:23 AM
    Moderator
  • Hi,

    Thanks for question, there is no error, that's scary bit just don't receive sms when sent, yet when using the m2m tester online that works ?

    Regards

    james

    Friday, November 3, 2017 6:54 AM
  • HI,

    Thanks for the question, not working as in the code is ok but the message does not get received at the recipients end. yet when using the m2m online software it does receive the message ?

    Regards

    james

    Friday, November 3, 2017 6:58 AM
  • Hi,

    Thanks for question, there is no error, that's scary bit just don't receive sms when sent, yet when using the m2m tester online that works ?

    Regards

    james

    Did you alter your code so that if an error happens you can read the exception message as at this point if an error happens you will not know as stated prior in regards to an empty catch.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, November 3, 2017 12:33 PM
    Moderator
  • Just really want some kind of debugging system to test this code because I have now downloaded several examples of sending SMS with VB and they all follow the same way I have programmed it, frustrating, should stick to Flowcode which I know works !

    Saturday, November 4, 2017 1:26 PM
  • Hi uk-gsm,

    I try your code and find the data have been sent, it works fine. can you tell me that what is the data receiver?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 10, 2017 8:35 AM
    Moderator
  • Hi Cherry,

    The receiver is a usb to usart cp2104 this communicates to a sim800L module. I have used many of these units using a developer software by Matrix and it works great, but the simple VB does not work !

    Thanks

    james

    Saturday, November 11, 2017 4:26 PM
  • Hi Cherry,

    The receiver is a usb to usart cp2104 this communicates to a sim800L module. I have used many of these units using a developer software by Matrix and it works great, but the simple VB does not work !

    Thanks

    james

    Hi uk-gsm,

    You said that the code does not work above, it means that you don't received any data? I find one example that about using serialport to send data, you can refer to.

     Dim myPort As Array
        Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            myPort = IO.Ports.SerialPort.GetPortNames()
            ComboBox1.Items.AddRange(myPort)
            ComboBox3.Items.AddRange(myPort)
            Button2.Enabled = False
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            SerialPort1.PortName = ComboBox1.Text
            SerialPort1.BaudRate = ComboBox2.Text
            SerialPort2.PortName = ComboBox3.Text
            SerialPort2.BaudRate = ComboBox2.Text
            SerialPort1.Open()
            SerialPort2.Open()
            Button1.Enabled = False
            Button2.Enabled = True
            Button4.Enabled = True
        End Sub
        '------------------------------------------------
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            SerialPort1.Write(RichTextBox1.Text & vbCr) 'concatenate with \n
        End Sub
        Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
            SerialPort1.Close()
            Button1.Enabled = True
            Button2.Enabled = False
            Button4.Enabled = False
        End Sub
        Private Sub SerialPort2_DataReceived(sender As System.Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort2.DataReceived
            ReceivedText(SerialPort2.ReadExisting())
        End Sub
        Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting
            If Me.RichTextBox2.InvokeRequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.Invoke(x, New Object() {(text)})
            Else
                Me.RichTextBox2.Text &= [text] 'append text
            End If
        End Sub

    Best regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 20, 2017 9:49 AM
    Moderator