ipdicky
asked on
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.PortOpe nError)
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.IsOpe n.ToString ())
Try
port.Write(str)
Catch ex As System.Exception
RaiseEvent SMSError(SMSStatus.SMSSend Error)
End Try
End Sub
Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialData ReceivedEv entArgs) 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!!!
==========================
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.PortOpe
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.IsOpe
Try
port.Write(str)
Catch ex As System.Exception
RaiseEvent SMSError(SMSStatus.SMSSend
End Try
End Sub
Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialData
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!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER