Link to home
Start Free TrialLog in
Avatar of omarmf
omarmf

asked on

GSM Send SMS

Dear Sir

i tested the code in the link

https://www.experts-exchange.com/questions/20948621/Developing-an-API-to-send-SMS-through-the-PC.html

everything works except

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

So Please advice

OmarMF
Avatar of imarshad
imarshad
Flag of Pakistan image

What error do you get ?
Does it return "ERROR" or "OK" or "" in SendSMS variable? You can insert a breakpoint and/or print the value returned from the Function......

If it is "OK" and still message is not delivered(you donot receive it at intended No.) then you need to check your value in tSMSNum variable maybe the format is not correct.......

If it is "Error" then check the tSMSNum value as well as the Message.......

If it is "" then check your modem settings.......

and in which mode are you working ?
Text Mode ----> AT+CMGF=1  'Default mode.......
PDU Mode-----> AT+CMGF=0

Imran
Avatar of omarmf
omarmf

ASKER

the function is:

SendSMS1(comModem, "0507751116", "Hello There")

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

the returned message by the modem is:

 AT+CMGS="0507751116"
hello there
>

ERROR
.............................................................................................
the returned message by the modem is:

 AT+CMGS="0507751116"
hello there
>

ERROR

.............................................................................................

This one actually should have been something like this......

AT+CMGS="0507751116"

>hello there

OK

Probable reasons for such behaviour is that your modem is operating maybe in PDU Mode.......Try to convert it into Text mode by issuing the following command.......

TransmitAndReceiveData(comms, "AT+CMGF=1" & vbCr)

But the main problem is that Modem is not given enough time to react after the AT+CMGS="0507751116" command......
i.e you need to wait for some time after issuing this command while in the TransmitAndReceive function that you are using the modem is not given that space........

You can use the following alteration.....In this technique you will need to call 2 functions......

Public Function TransmitAndReceiveData1(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, ">") = 0
            DoEvents
            If .InBufferCount > 0 Then tData = tData & .Input
        Loop
    End With
           
    TransmitAndReceiveData1 = tData
End Function


Now you will use the following SendSMS function

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

I am at home now so I couldnot test the code.....Please do tell if some error occurs........

Imran
Avatar of omarmf

ASKER

nice  i did exactly what you recomend because i expect this reson

i modify (TransmitAndReceiveData)

Public Function TransmitAndReceiveData(comms As MSComm, ByVal tData As String) As String
    Dim lTime As Long
   
    Const TIMEOUT = 100000
   
    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 And InStr(tData, ">") = 0
            DoEvents
            If .InBufferCount > 0 Then tData = tData & .Input
        Loop
    End With
           
    TransmitAndReceiveData = tData
End Function

then i devide send into:

 MsgBox TransmitAndReceiveData(comModem, "AT+CMGS=""+971507751116""")
result:
AT+CMGS="0507751116"

>

 MsgBox TransmitAndReceiveData(comModem, "Hello .. " & Chr(26))

ERROR

i got ok using hyper terminal put no message was received

put now i tryeid to call the number of the sim in the modem. the modem is not ringing ... it should ring right ??

it is giving that it is swiched of or out of caverage,  please suggest some thing

thank you
>>put now i tryeid to call the number of the sim in the modem. the modem is not ringing ... it should ring right ??
Yes it should ring.......provided that it has been given power......SO if the SIM is in the Modem and the Modem is given power then there should be a ring and you can check this with hyper terminal where you will see

RING

RING

RING
.
.
.

Coming back to your problem......

I dont think your code will transmit the SMS either.....Just try my code with the following line commented......In the function TransmitAndReceiveData1

' tData = tData & vbCr                           'in my code........You donot need to embedd a Carriage Return at the end

This is maybe causing the error......

Imarn

Avatar of omarmf

ASKER

So first i should solve rin ring :)

the power is on ... the simcard is there and the test AT returning ok i even can read the messages from the SIM put when i cal
it is giving that it is swiched of or out of caverage,  the modem is wavecom fastrack M1203A-ON.

it may need something to work or it is spoild

please advice

Omar
Avatar of omarmf

ASKER

By the way do have the complete list of at command for this modem ??

thank you in advance

Omar
>>By the way do have the complete list of at command for this modem ??

It suports all standard AT commands....
Try this page.....
http://www.wavecom.com/Products_V2/product.php?prs_id=31&prg_id=13

Imran
Avatar of omarmf

ASKER

ok and where i can find all AT commands

thank you

omar
ASKER CERTIFIED SOLUTION
Avatar of imarshad
imarshad
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omarmf

ASKER

i will check the modem and refere to my problem with new quistion

thanks Imran