Comm Control settings for SMS Application

Posted on 2004-04-10
Last Modified: 2012-06-27
      My mob Siemens SL45i does support only PDU mode and it is sending sms messages from Hyperterminal fine with 19200,n,8,1 settings but now i want to create a VB Application and needed of Comm Control Settings like InBufferSize,OutBufferSize,RThreshold,SThreshold,InputLen,EofEnable,ParityReplace,NullDiscrd,RTSEnable,DTREnable, and Handshaking ,
  Can some one help me in making VB Application through i think Comm Control. waiting for reply very badly,
Question by:zahidrahim
  • 2

Accepted Solution

f_rodriguez earned 50 total points
ID: 10842133
Hey there. I've worked with GSM modems through Visual Basic 6 quite a bit. I worte a module in VB6 that uses the MS Comm Control to send and receive SMS's using a GSM modem connected to the PC's serial port. Here is the module which you can include in your VB project:

Option Explicit

Public Function RemoveInternationalDiallingCode(ByVal tTelNumber As String) As String
    RemoveInternationalDiallingCode = "0" & Mid(tTelNumber, 4)
End Function

Public Function GetSMSNum(ByVal tSMSNotification As String) As String
    Dim lCRPos As Long
    lCRPos = InStrRev(tSMSNotification, vbCr)
    If lCRPos > 0 Then GetSMSNum = Mid(tSMSNotification, lCRPos - 2, 2)
    If Left(GetSMSNum, 1) = "," Then GetSMSNum = Right(GetSMSNum, 1)
End Function

Public Function ReadSMS(comms As MSComm, ByVal tSMSNum As String, tMessage As String, tSender As String, tDate As String, tTime As String, bRead As Boolean) As Boolean
    Dim tChar As String * 1
    Dim i As Long
    Dim tRead As String
    Dim lQuoteNum As Long
    Dim tDateTime As String
    Dim tData As String
    Const TIMEOUT = 10000
    On Error GoTo ErrHandler
    tData = "AT+CMGR=" & tSMSNum & vbCr
    comms.InBufferCount = 0
    comms.Output = tData
    tData = ""
    i = timeGetTime
    Do While timeGetTime - i <= TIMEOUT And InStr(tData, "OK" & vbCrLf) = 0 And InStr(tData, "ERROR" & vbCrLf) = 0
        If comms.InBufferCount > 0 Then
            tChar = comms.Input
            tData = tData & tChar
        End If
    If InStr(tData, "ERROR") = 0 And tData <> "" Then
        For i = 1 To Len(tData)
            tChar = Mid(tData, i, 1)
            If tChar = """" Then lQuoteNum = lQuoteNum + 1
            If lQuoteNum = 1 And tChar <> """" Then tRead = tRead & tChar
            If lQuoteNum = 3 And tChar <> """" Then tSender = tSender & tChar
            If lQuoteNum = 5 And tChar <> """" Then tDateTime = tDateTime & tChar
            If lQuoteNum = 6 And tChar <> """" Then tMessage = tMessage & tChar
        Next i
        bRead = (tRead = "REC READ")
        tDate = Left(tDateTime, 8)
        tTime = Mid(tDateTime, 10, 8)
        tMessage = Mid(tMessage, 3)
        tMessage = Mid(tMessage, 1, InStr(tMessage, vbCr) - 1)
        ReadSMS = True
    End If
    Exit Function
    ReadSMS = False
End Function

Public Function DeleteAllSMSes(comms As MSComm) As Boolean
    Dim i As Long
    For i = 1 To 15
        DeleteAllSMSes = InStr(TransmitAndReceiveData(comms, "AT+CMGD=" & i & vbCr), "OK")
    Next i
End Function

Public Function DeleteSMS(comms As MSComm, ByVal lSMSNum As Long) As Boolean
    DeleteSMS = InStr(TransmitAndReceiveData(comms, "AT+CMGD=" & lSMSNum & vbCr), "OK")
End Function

Public Function SendSMS(comms As MSComm, ByVal tSMSNum As String, ByVal tMessage As String) As Boolean
    SendSMS = InStr(TransmitAndReceiveData(comms, "AT+CMGS=" & """" & tSMSNum & """" & vbCr & tMessage & Chr(26)), "OK")
End Function

Public Function TestModem(comms As MSComm) As String
    TestModem = TransmitAndReceiveData(comms, "AT")
End Function

Public Function ManufacturerInfo(comms As MSComm) As String
    ManufacturerInfo = TransmitAndReceiveData(comms, "AT+CGMI")
End Function

Public Function ModelInfo(comms As MSComm) As String
    ModelInfo = TransmitAndReceiveData(comms, "AT+CGMM")
End Function

Public Function FirmwareInfo(comms As MSComm) As String
    FirmwareInfo = TransmitAndReceiveData(comms, "AT+CGMR")
End Function

Public Function IMEIInfo(comms As MSComm) As String
    IMEIInfo = TransmitAndReceiveData(comms, "AT+CGSN")
End Function

Public Function IMSIInfo(comms As MSComm) As String
    IMSIInfo = TransmitAndReceiveData(comms, "AT+CIMI")
End Function

Public Function EF_CCIDInfo(comms As MSComm) As String
    EF_CCIDInfo = TransmitAndReceiveData(comms, "AT+CCID")
End Function

Public Function NetworkRegStatus(comms As MSComm) As String
    NetworkRegStatus = TransmitAndReceiveData(comms, "AT+CREG?")
End Function

Public Function AvailablePLMNs(comms As MSComm) As String
    AvailablePLMNs = TransmitAndReceiveData(comms, "AT+COPS?")
End Function

Public Function NetworkFieldStrength(comms As MSComm) As String
    NetworkFieldStrength = TransmitAndReceiveData(comms, "AT+CSQ")
End Function

Public Function MainCellMainParams(comms As MSComm) As String
    MainCellMainParams = TransmitAndReceiveData(comms, "AT+CCED=0")
End Function

Public Function TransmitAndReceiveData(comms As MSComm, ByVal tData As String) As String
    Dim lTime As Long
    Const TIMEOUT = 10000
    tData = tData & vbCr
    With comms
        .InBufferCount = 0
        .Output = tData
        tData = ""
        lTime = timeGetTime
        tData = ""
        Do While timeGetTime - lTime <= TIMEOUT And InStr(tData, "OK") = 0 And InStr(tData, "ERROR" & vbCrLf) = 0
            If .InBufferCount > 0 Then tData = tData & .Input
    End With
    TransmitAndReceiveData = tData
End Function

You use the ReadSMS function to read an SMS and SendSMS to send one. Note that you have to pass it an MSComm Control as the first argument. I think it is pretty self explanatory, but let me know if you need any further assistance.

Fabricio Rodriguez
South Africa

Expert Comment

ID: 10842191
Oops, forgot to mention what the MSComm Control propeties should be. Generally, GSM modems are set to 9600 bps as default, but they can normally be increased. You can connect it to any free serial port on your pc. If you are using a laptop that doesn't have a serial port, you can purchase a USB-to-Serial convertor. This will emulate a serial port. Just be careful because some convertors assign a different port number everytime you plug it in. The rest of the parameter are usually as follows:

Parity: none
Data bits: 8
Stop bits: 1

The handshaking is normally set to "none", but if that fails, try setting it to hardware (also known as RTS/CTS in VB)

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WLC and port fast. 1 68
Configure QoS on Archer c9 running WR-DDT 2 66
Setting up new wifi in new office 3 44
DNS with WiFi Network 5 55
Hopefully this article will help someone who's had the same issues I had. I have a Dell Wireless 1390 WLAN Mini-Card and Windows 7, and for the past couple of days I was beyond frustrated because my wireless laptop was not able to access the Inte…
This article is a step by step guide on how to create a basic PTP link using Ubiquiti airOS devices. This guide can be used on the following Ubiquiti AirMAX devices. Nanostation, Bullets, AirBridge, Nanobeam, NanoBridge to name a few. Please review …
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now