PDA

View Full Version : send incomming msg (SMS) to VB



PoTeToJB
- 19th March 2006, 18:42
hello, every one..

My problem is to read incomming msg (SMS) and send the data to VB6 and MS access .. i use Sony Erricsson T610. i want build database.. for the system i need use pic or i can directly send the msg to VB..

can someone help me..

i need your help..

---> i need use pic or not.
---> i want know how to send msg data to VB and MS Access.
---> want now how to build database and link to MS access.

thank for help..

kamet
- 24th March 2006, 04:41
You don't need to use a PIC to interface your cell to your PC, you just need a data cable and program the computer to listen on its serial port for AT commands and responses which the cell phone uses to communicate. When a cell phone receives a SMS, it can be set to alert an external device (such as your computer) by sending a serial message called an AT command. You then program your computer to send the correct commands to access the bank in which the message was stored in.

here's an example of what the communication would look like:

(from cell phone): +CMTI: "ME",27
(from computer): at+cmgr=27
(from cell phone): +CMGR: "REC UNREAD","+15551234567","John Doe","05/10/18,23:21:45-20"
Hello World


the break down:
when a cell phone receives an SMS, it sends an AT response of "CMTI ME, 27". The ME means it was stored in memory in storage bank number 27. Your computer must then access this bank by sending "AT+CMGR=27", the cell phone then responds with the message. You can test all of this out without even programming anything, just connect your cell phone to your serial port and then open up a serial terminal emulator (such as Hyperterm for Windows).

You can interface your cell phone to a PIC using serial communication. It is possible to directly interface the pins to the cell phone since they are both of TTL voltage RS-232 (the cell phone actually uses 3v while the PIC uses 5v, but I haven't had any problems).

I hope that helps you get started.

PoTeToJB
- 27th March 2006, 10:10
hello

thank kamet..

i only have USB data cable.u thing i can use it or i must use serial cable...

i have the at commnad but i down know how to send the command using vb. can u help me.

kamet
- 27th March 2006, 18:02
I'm sorry but I don't know how to interface it by USB directly, however, you may want to search for a "virtual serial port driver" for your USB. The driver will trick your application into believing your USB port is a serial port and behave like one. The driver should handle the in-betweens of serial information exchange of the USB port and your VB program.

Again, I've never done this, its just a suggestion, the easier route would be to buy an actual serial data cable, but if you cannot, then maybe a USB to serial converter cable.

Here's a link to help you with basicsetup of serial communication with VB: http://www.pages.drexel.edu/~bns23/tutorial.html

Good luck.

PoTeToJB
- 27th March 2006, 21:37
thank
kamet

ok i find the serial data cable.

now i try to send the at command using vb.. that my program.
but i have problem i dont know why the msg cant display in text.. i thing have some problem.

this program dont error bit just not display the output

can u check the program for me.
i realy new in vb6

Private Sub Command1_Click()
Dim sms As String
Dim buffer$

MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.Handshaking = comNone

MSComm1.PortOpen = True

'echo off
MSComm1.Output = "ATE0" & Chr$(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
buffer$ = ""

'Report Mobile Equipment Error ( enable )
MSComm1.Output = "AT+CMEE=1" & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
buffer$ = ""

'Received read message
MSComm1.Output = "AT+CMGR=1" & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "+CMGR: 1,,159")
buffer$ = ""

sms = MSComm1.Input
Text1.Text = sms

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")

MSComm1.PortOpen = False

'if use hyperterminal the command output like below
'AT CMGR = 1
'+CMGR: 1,,159
'07910621000010F5240B910621671663F1000060104222334 423A0C2E030088232834E19C8049A06
'9 BC2AAF3B87482905569D5E8CC06750A625A0F0AB7C32037B90 E62D7D761103B3C4F83C46190B8EE
'9E87D7207A1A5E9683CEE97619E41E8741F2F43A4D0785C5F 3FA18949E97C96190FBBC0E83DCE230
'485 C77CFCB20F739CC9E97C9A0B0FB3C07A5C5F575BB0C729FCB6 A50985E6783D2F3B03B0D72A75D
'E8301A1446875D

End Sub


if i use hyperterminal the output like this

'if use hyperterminal the command output like below
'AT CMGR = 1
'+CMGR: 1,,159
'07910621000010F5240B910621671663F1000060104222334 423A0C2E030088232834E19C8049A06
'9BC2AAF3B87482905569D5E8CC06750A625A0F0AB7C32037B 90E62D7D761103B3C4F83C46190B8EE '9E87D7207A1A5E9683CEE97619E41E8741F2F43A4D0785C5F 3FA18949E97C96190FBBC0E83DCE230
'485C77CFCB20F739CC9E97C9A0B0FB3C07A5C5F575BB0C729 FCB6A50985E6783D2F3B03B0D72A75D
'E8301A1446875D

thank

kamet
- 28th March 2006, 20:17
Does it not display anything at all or is it displaying "garbage" response? Where in your code does it display the response? The garbage response you see in your hyperterminal is because the cell phone is by default in PDU format. Some sony ericssons have a TEXT mode and a PDU mode, you must look for the AT command to switch it to TEXT mode first (unless you want to write software for it in PDU mode, which you'll have to do some hex conversion).

It appears that you only loop until you receive an "OK" and then you move onto the next output. You have to write a response to screen to show that each output was sucessfully received by the celll phone as an "OK" so that you know what is going on.

Make sure your serial output is working first, the easiest way would be to command the cell phone to dial a phone number. This is easier because it does not require the phone to respond by serial "OK" (because you don't know if your output is working yet, so input is still questionable), it will show the phone dialing the number from the cell's display screen. I believe the command to dial a number is ATD1234567890 (the number 1234567890 would be replaced by whatever number you choose)

Good luck.

PoTeToJB
- 28th March 2006, 20:32
thank

i dont know sony ericsson have text mode. i think only PDU mode..

i have PDU conveter in vb.

i try text mode now..

PoTeToJB
- 1st April 2006, 17:41
hello
kamet...

1)
i try call out the phone using ATD0127674067.. but still cant..
i thing the problem is my phone modem stay in Off-line Command Mode.. i read the at command datasheet the say i must change to on-line data mode. but i dont know how to go online command mode..

can u help me...

2)
i can read my msg using hiperterminal.

AT
OK
AT+CGMF=1 (change to text mode)
OK
AT+CGMR=1
............................................
...........................................
.............................................
the msg in TEXT mode..

the msg have time send, no phone, the msg..
how to separate the msg.

3)i sent the command for read the msg from cell phone using VB but have problem..
i run the vb and push the " READ "(for read the msg).i recieve the msg but if i push back the READ button the new output cannot out.. u thing my modem cell phone have problem or not.

4)
i connet the phone to computer and open and run the hyperterminal.

i try what u say if the cell phone recieve the msg, the output is +CMTI:"ME",(storage bank number). but in my hyperterminal cant change. dont read anything.

this your idea

(from cell phone): +CMTI: "ME",27
(from computer): at+cmgr=27
(from cell phone): +CMGR: "REC UNREAD","+15551234567","John Doe","05/10/18,23:21:45-20"
Hello World

kamet
- 4th April 2006, 21:06
Try this setup to initially change your cell's default setting.



to set up, try this:

at+cmgf=1 (set to text mode)
at+cnmi=2,1,0,0,0 (set to hear sms delivery response on terminal)
at+cpms="me","me","me" (set mem storage to phone mem read/write)




to read the sms, try this:

+CMTI: "ME",27 (replace "27" with your message bank number)


I don't understand what you mean when you say the new message doesnt output. Are you talking about a new sms being sent won't read or are you saying that trying to read another message won't appear? You have to remember to change the memory bank that you are reading from.


Also, take a look at this part of your code:

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")

Do you realize that when you receive your message, the cell phone does not reply "OK" ? It only response with "OK" when you issue a command TO the cell phone, not the other way around. It is possible that your program reads the message and then hangs because it is waiting for an "OK" reply which it never will receive. Just an observation, I might be incorrect as to what you are trying to do with your code.

Good luck.

PoTeToJB
- 6th April 2006, 21:58
thankQ
kamet

i set the phone like this
at+cmgf=1
at+cnmi=2,1,2,0,0
at+cpms="me","sm","me"

how to save this setting. because after i disconnet the the phone dont save the setting.i must set the phone back if i want read recieve msg.

thank for help me

kamet
- 8th April 2006, 04:33
PoTeToJB, I don't think you can save the settings when you disconnect the phone. If somebody knows how to, I would like to know that as well because I can't save it myself. I always initialize the connection with those settings everytime to ensure that they are properly set.

charudatt
- 14th April 2006, 20:37
i have a SIMCOM Modem and I give a command AT&W which writes my current setting to the modem. Hope it works and helps.


Well I am looking for some help in rx SMS using VB6. I have successfully rx the SMS using a PIC Micro and PBP. But don't know how to Rx it in VB.

I understood the CMGR command but I don't know How I can skip a set of 51 character to escape the SMS details and copy just the message.

Any Help ?

Thanks in advance.

PoTeToJB
- 15th April 2006, 14:12
hello
charudatt

i use this code for read the msg and serperate the msg...

Private Sub Command1_Click()
Dim buffer$
DIM newMsg As String, MSG As String

MSComm1.Output = "AT+CMGF=1" + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""
MSComm1.Output = "AT+CMGR=1" + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text2.Text & vbCr & buffer$
Text2.Text = buffer$
buffer$ = ""


newMsg = Text2.Text
newMsg = Right(newMsg, Len(newMsg) - 51) 'SKIP 51 character

MSG = Left(newMsg, 100) 'NO 100 DEPEND YOUR MSG LENGTH,IF DONT KNOW U CAN PUT MORE THAN 100

newMsg = newMsg & "MESSAGE =" & MSG & vbCrLf

MSComm1.PortOpen = False
End Sub



Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "57600,n,8,1"
MSComm1.PortOpen = True
MSComm1.Handshaking = comNone

End Sub

i hope help u abit.
but i still problem for read incomming msg.. i still study now

charudatt
- 15th April 2006, 16:46
Thank you. But my idea is to read a incoming SMS using VB. This includes the following steps.

(from cell phone): +CMTI: "ME",27
(from computer): at+cmgr=27
(from cell phone): +CMGR: "REC UNREAD","+15551234567","John Doe","05/10/18,23:21:45-20"
Hello World

This is simple using PIC BASIC Pro but I am not sure how to do this in VB6
OK step one has definate characters to trap as I am going to keep my SMS's below 10
Step 2 Is simple as I can just issue a command using VB.
Step 3 is a bit challengeing as I am interested in only "Hello World"

Any help. Are there any free ActiveX/OCX for receiving SMS for VB6

regards
Charudatt

an after thought : should i be trapping a carriage return as the EOM (End Of Message) marker ?

PoTeToJB
- 19th April 2006, 14:22
hello
charudatt

u say simple using PIC BASIC Pro for read incomming msg.
can u share it..
i want send and read incomming msg.. using pic

charudatt
- 21st April 2006, 19:08
OK I shall share it. Give me a day, shall format the text and share it with you. Right now its just small routines.

regards
Charudatt

charudatt
- 23rd April 2006, 07:10
Hi , Hello,

I have shared my SMS relay control code with all in the Code Example section.
http://www.picbasic.co.uk/forum/showthread.php?p=19977#post19977

regards

PoTeToJB
- 24th April 2006, 06:59
Hi, hello..
thankQ
last night i success read sms using Vb..
u want the code..

charudatt
- 24th April 2006, 07:10
Yes I would love to go thru it.

regards.

PoTeToJB
- 24th April 2006, 11:16
this my code.
hope help u


Option Explicit

Dim buffer$

Dim aText As String
Dim bText As Long
Dim cText As String
Dim dText As Long
Dim Location As String

Dim AKAUN As String, TARIKH As String, newMsg As String
Dim MASA As String, KWJ As String

Private Sub CmdRead_Click()
Dim Counter As String
Counter = 0

Do
Text9.Text = Counter
Counter = Counter + 1

'Wait incomming sms
Text3.Text = Text3.Text & vbCr & "Wait Message" + Chr(34) + Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "+CMTI: ""ME""")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""

buffer$ = buffer$ & MSComm1.Input
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""

aText = Text1.Text
bText = InStr(aText, "+CMTI: ""ME""")

newMsg = Text1.Text
newMsg = Right(newMsg, Len(newMsg) - bText)

newMsg = Right(newMsg, Len(newMsg) - 11)

Location = Left(newMsg, 2)

'Location mesage storage
Text4.Text = Location

Text3.Text = Text3.Text & vbCr & "Read Message" + Chr(34) + Chr$(13)

'Read sms
MSComm1.Output = "AT+CMGR=" + Location + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
Text2.Text = buffer$
buffer$ = ""

'Set for Separate Message
Text3.Text = Text3.Text & vbCr & "Separate Message" + Chr(34) + Chr$(13)

cText = Text2.Text
dText = InStr(cText, """REC UNREAD""")

newMsg = Text2.Text
newMsg = Right(newMsg, Len(newMsg) - dText)

newMsg = Right(newMsg, Len(newMsg) - 14)

AKAUN = Left(newMsg, 11)
newMsg = Right(newMsg, Len(newMsg) - 17)

TARIKH = Left(newMsg, 8)
newMsg = Right(newMsg, Len(newMsg) - 9)

MASA = Left(newMsg, 8)
newMsg = Right(newMsg, Len(newMsg) - 12)

KWJ = Left(newMsg, 11)

Text5.Text = AKAUN 'phone no
Text6.Text = TARIKH 'Date send
Text7.Text = MASA 'Time send
Text8.Text = KWJ 'message

Text3.Text = Text3.Text & vbCr & "Delete Message" + Chr(34) + Chr$(13)

MSComm1.Output = "AT+CMGD=" + Location + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""
Text3.Text = Text3.Text & vbCr & "" + Chr(34) + Chr$(13)
Text1.Text = ""
Text2.Text = ""

Counter = Counter - 1 'Set for loop forever

Loop Until Counter > 3

MSComm1.PortOpen = False
End Sub

Private Sub CmdSetting_Click()

'Set interation of comunication
Text3.Text = Text3.Text & vbCr & "Start Setting" + Chr(34) + Chr$(13)

MSComm1.Output = "AT+CNMI=2,1,2,0,0" + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""

'Set message storage
Text3.Text = Text3.Text & vbCr & " Setting " + Chr(34) + Chr$(13)

MSComm1.Output = "AT+CPMS=""ME"",""SM"",""ME""" + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""

'Set SMS format to Text
MSComm1.Output = "AT+CMGF=1" + Chr(13)

Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""

Text3.Text = Text3.Text & vbCr & "End Setting" + Chr(34) + Chr$(13)
Text1.Text = ""

End Sub

Private Sub Form_Load()

MSComm1.CommPort = 1
MSComm1.Settings = "57600,n,8,1"
MSComm1.PortOpen = True
MSComm1.Handshaking = comNone

End Sub