problem with getting inbox from cell phone

dreamdelerium

Active member
Joined
Mar 7, 2008
Messages
36
Programming Experience
1-3
hi all,
im trying to read from a gsm modem's inbox using AT commands. when i run this code, the only response i get is "OK" but i should be getting the message from the inbox. my code is bellow:

VB.NET:
    Private Sub viewInBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim comSerial As New System.IO.Ports.SerialPort


        Try

            With comSerial
                .PortName = "COM5"
                .BaudRate = "9600"
                .StopBits = IO.Ports.StopBits.One
                .DataBits = 8
                .Parity = IO.Ports.Parity.None
                .ReadBufferSize = 10000
                .ReadTimeout = 1000
                .WriteBufferSize = 10000
                .WriteTimeout = 10000
                .RtsEnable = True

                .Open()
                .DiscardOutBuffer()
                'for reading sms
                .DtrEnable = True


                .Write("AT" + vbCr)     'execute command on buffer
                .Write("AT+CMGF=1" + vbCr)
                .Write("AT+CMGL=ALL" + vbCr)

                Dim Incoming As String = .ReadExisting()

                MsgBox(Incoming)
                
                .Close()

            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try 

    End Sub

my only guess would be that its only writting out the last part of the string. if so, how would i concat all the string parts into one? if thats not the problem, what is?
 
Hello.

Do you have the possibility to execute the commands within the hyperterminal? It's the best way to check what comes back from the device if you sent a command.

Bobby

P.s.: ReadExisting is not the best way to go...'cause it only reads the bytes which are NOW in the buffer (I know, I also fell for that name ^^). ReadLine or Read would be the better way in my opinion.
 
problem with hyper terminal

ive tried using hyperterminal but it doesnt seem to work (or im doing it wrong). im using vista and have downloaded several hyper terminal programs. when i connect to the comport it says its connected but wont let me type in anything. would the fact that the modem connects to the usb port be a problem?
 
Partly...if you have a driver installed which maps your USB-Port to a COM-Port, then it's not (and you must have this, 'cause you're talking with COM5).

I can't really help you with the problem and Vista...I'm not using that OS. But you could try to read all the bytes which are incoming from the port...

VB.NET:
Threading.Thread.Sleep(250)
Dim buffer(RS232Port.ReadBufferSize) as Byte
RS232Port.Read(buffer, 0, buffer.length

Maybe there's something which can give you a clue.

Bobby
 
Declare the SerialPort variable WithEvents and use the DataReceived event, it will tell you whenever data is available to read.
 
Back
Top