Sending SMS from VB through Nokia 6310i with serial data cable

Ok, i have read a questions / answers about what to type for the at commands and using MSCOMM object to talk to the nokias modem..

I can manually send an sms using hyper terminal no probs.. and XP can query the Nokia Modem and give me good results...


I drop the MSCOMM object in a form and then do the simple code as follows:

MSComm1.CommPort = 1
'MSComm1.InputLen = 0
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.Output = "AT" & vbCrLf

'------------- at this point i wait for the modem to report back "OK"
'-                BUT it never does..  nothing happens at this point.
    Debug.Print MSComm1.CommEvent & vbCrLf      '------- ALWAYS returns 0 (zero)
loop Until InStr(buffer$, "OK" & vbCrLf)

'----------- This part i typed in manually in hyperterminal and it works fine...  but my prog never gets this far as above is in a loop.
MSComm1.Output = "AT+CMGF=1" & Chr$(13)
'MSComm1.Output = "AT+CNMI=3,3,2" & Chr(13)
MSComm1.Output = "AT+CMGS=" & "+447834871851" & Chr$(13)
MSComm1.Output = "HeartBeat from WWW1: Server Ok" & Chr$(26)
'MSComm1.PortOpen = False
Label1.Caption = MSComm1.Input

Does anyone know off the top of their head if there is something i am doing wrong?

Thanks in advance
Who is Participating?
SergeiKoConnect With a Mentor Commented:
Hello, Cybordax.

Try to handle responses from mode as events.

From MSDN:
Event-driven communications is a very powerful method for handling serial port interactions. In many situations you want to be notified the moment an event takes place, such as when a character arrives or a change occurs in the Carrier Detect (CD) or Request To Send (RTS) lines. In such cases, use the MSComm control's OnComm event to trap and handle these communications events. The OnComm event also detects and handles communications errors. For a list of all possible events and communications errors, see the CommEvent property.

Pay attention to
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
Private Static Sub MSComm1_OnComm() function.

Hope the sample below will help you.

Option Explicit

Private Sub Command1_Click()
    Call Disconnect
    Call Connect
    Call Send("AT")
    Call Send("ati")
    Call Send("ati3")
End Sub

Function Connect()
    If MSComm1.PortOpen = False Then
        MSComm1.CommPort = 3
        MSComm1.Settings = "115200,N,8,1" ' 115200 baud, no parity, 8 data, and 1 stop bit.
        MSComm1.InputLen = 0
        MSComm1.RThreshold = 1
        MSComm1.SThreshold = 1
        MSComm1.PortOpen = True
    End If
End Function

Function Disconnect()
    If (MSComm1.PortOpen = True) Then
        MSComm1.PortOpen = False
    End If
End Function

Function Send(str As String)
    MSComm1.Output = str & vbCrLf
End Function

Private Static Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
       ' Events
        Case comEvReceive   ' Received RThreshold # of characters
            Dim buffer As String
            buffer = MSComm1.Input
            If buffer <> "" Then
                Debug.Print ">> " & buffer
            End If
    End Select
End Sub

CybordaxAuthor Commented:
I will give that a go and get back to you...

Got back LATE from work tonight, so i WILL let you know the following day...

Thanks for the response dude...

CybordaxAuthor Commented:
Ok, i tried what you had suggested, and still no joy, mate...

I nothing displayes in the debug window...

I can confirm the data cable is recognised by 6310i as it says data accessory connected.
i can confirm PC can see the phone and recognise it on COM1 as Hyper terminal lets me connect, send sms etc...

but VB does not like it....

I did exact coding you typed in...  and changed the send calls to send an sms etc....

i am confused!  lol

Any more help you could provide would be most greatly appreciated!

Thanks in advance
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

imarshadConnect With a Mentor Commented:
>>MSComm1.Output = "AT+CMGF=1" & Chr$(13)
>>'MSComm1.Output = "AT+CNMI=3,3,2" & Chr(13)
>>MSComm1.Output = "AT+CMGS=" & "+447834871851" & Chr$(13)
>>MSComm1.Output = "HeartBeat from WWW1: Server Ok" & Chr$(26)
>>'MSComm1.PortOpen = False
>>Label1.Caption = MSComm1.Input

If this is the code you are using to send the SMS then it will not do the job for you..... You must insert some delay before sending the Modem the next command.....
Here is one way i.e by using Sleep......

MSComm1.Output = "AT+CMGF=1" & Chr$(13)
sleep 500           '0.5 seconds or 500 milliseconds
MSComm1.Output = "AT+CMGS=" & "+447834871851" & Chr$(13)
sleep 500
MSComm1.Output = "HeartBeat from WWW1: Server Ok" & Chr$(26)
sleep 500
Label1.Caption = MSComm1.Input

also try to change the value to 1000 (ms) if it is not working.......and declare sleep as

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
CybordaxAuthor Commented:
Ok, my friend, i will give that a go and get back to you.....

I have to be doing something REALLY stupid....  i did not imagine it to be this....  annoying to set up simple connection to a nokia modem....

Thanks again for your help so far...

Take care dude
Hello, again.

I have some thoughts:
 - try to set RThreshold = 1 and SThreshold = 1 in the setup component properties;
 - be sure you use your port number CommPort = 1 in your case;
 - in Settings you should use the same data rate as modem: 9600 or 115200 or ... . You can get modem's data rate with
   command AT+IPR? and set with command AT+IPR=115200 (to 115200 for example),
   or better choose the same data rate you choose with hyperterminal;
 - try to debug to be sure, that AT command was sent to modem.

Hope this help.

And keep patience when you are trying. If at first you don't succeed, think and try again. :-)

CybordaxAuthor Commented:
Sorry, I have been v busy for a few days at work....

I will try what you advised, but i know i have set the same baud rate etc as hyperterminal....

I will get back to you

Thanks again
I think the suggestions by SegeiKo and imarshad can solve this problem. But the asker never got back to the Question meaning either he got it working or wasnot hoping for an answer....... If you donot want to Split then still it should be Paq'ed rather then deleted.....

CybordaxAuthor Commented:
Hello to all..

Mucho apologies for not getting back, but since the post of the question, have been too busy to continue with my little project....

I still did not get it to work.... very confusing....

The responses by SegeiKo and imarshad  were much appreciated ....  did not get much of a chance to implement and expirement with the suggestions though....

I could split the answers, but I still do not know, and wont be able to find out if their suggestions had worked...  not for a while anyway....  what is  Paq'ed  all about?
PAQ --------> Previously Asked Questions

If a question is PAQ then all the comments that have been made by the Experts are retained. But if a question is deleted then all the comments are deleted and the Question is also deleted. Since there was some useful knowledge in the posts so I wont like to let the Question be deleted.

Leaving it open for a few more days.... but do not make them too much :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.