Solved

Comm Control settings for SMS Application

Posted on 2004-04-10
4
655 Views
Last Modified: 2012-06-27
Hello,
      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,
Zahid
0
Comment
Question by:zahidrahim
  • 2
4 Comments
 

Accepted Solution

by:
f_rodriguez earned 50 total points
Comment Utility
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
        DoEvents
        If comms.InBufferCount > 0 Then
            tChar = comms.Input
            tData = tData & tChar
        End If
    Loop
           
    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
   
ErrHandler:
    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
            DoEvents
            If .InBufferCount > 0 Then tData = tData & .Input
        Loop
    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.

Regards
Fabricio Rodriguez
South Africa
0
 

Expert Comment

by:f_rodriguez
Comment Utility
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)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Coaxial cable bending There are several factors that govern the selection of coaxial cable for your Machine to Machine (M2M) application: the location of cable runs, either indoor or outdoor, inside or outside an enclosure, maximum bending and the…
This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now