[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

How to use VB.Net 2005 to send SMS via serial connect to GSM modem

Here is my code
========================================
Private WithEvents port As SerialPort

Public Sub New()
    port = New SerialPort("COM1")

    port.Parity = Parity.None
    port.StopBits = StopBits.One
    port.DataBits = 8
    port.Handshake = Handshake.None
    Try
        ' Open the serial port
        port.Open()
    Catch ex As Exception
        RaiseEvent SMSError(SMSStatus.PortOpenError)
    End Try
End Sub

Public Sub Send(ByVal toTel as String, ByVal msg As String)
    SendString("AT+CMGS=""" + toTel + """" + vbCrLf)
    SendString(msg + Chr(26) + Chr(90))
End Sub

Private Sub SendString(ByVal str As String)
    Debug.WriteLine(str)
    Debug.WriteLine(port.IsOpen.ToString())
    Try
        port.Write(str)
    Catch ex As System.Exception
        RaiseEvent SMSError(SMSStatus.SMSSendError)
    End Try
End Sub

Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles port.DataReceived
    Dim recString As String = port.ReadLine()
    Debug.WriteLine("rec: " + recString)
End Sub
========================================

I have two questioins:
1) I try to use a null modem cable and hyper terminal to test the output of my program, I get the output has a different from hyper terminal to hyper terminal config (type the AT command from one hyper terminal and receive from another hyper terminal).  At hyper terminal to hyper terminal config, the Ctrl-Z is show a arrow only, but the output of my program is a arrow followed by a "Z" char.  How to send a correct Ctrl-Z out?

2) The DataReceived event n trigger even I try to type something at hyper terminal that at the other end of null modem cable

Thanks in advance!!!
0
ipdicky
Asked:
ipdicky
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
ipdickyAuthor Commented:
Thank you very much!!! I try it and the reseult is positive.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now