2009-05-28 20 views
5

Deseo enviar SMS mediante la aplicación de Windows. Ejecuté el código pero recibí un error. Esto esCómo enviar SMS a través de la aplicación de Windows

AT 

OK AT+CMGF=1 

OK AT+CSCA="+9460921985" 

OK AT+CMGS="+9660775564" 

    this is new message 

+CMS ERROR: 500 

Estoy usando este código.

Public Class Form2 
    Dim number As String = "+9660775564" 
    ''# Dim message As String = TextBox1.Text 
    Dim serialport As New IO.Ports.SerialPort 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Try With serialport 
     .PortName = "COM5" ''# "COM24" 
     .BaudRate = "9600" 
     .Parity = IO.Ports.Parity.None 
     .DataBits = 8 
     .StopBits = IO.Ports.StopBits.One 
     .Handshake = IO.Ports.Handshake.RequestToSend 
     .DtrEnable = True .RtsEnable = True 
    End With 

    serialport.Open() 
    ''# checks phone status 
    serialport.WriteLine("AT" & vbCrLf) 
    ''# Configures message as SMS 
    serialport.WriteLine("AT+CMGF=1" & vbCrLf) 
    ''# Sets message center number 
    ''# serialport.WriteLine("AT+CSCA=""+447785016005""" & vbCrLf) 
    serialport.WriteLine("AT+CSCA=""+9460921985""" & vbCrLf) 
    ''# Sets destination number 
    serialport.WriteLine("AT+CMGS=""" & number & """" & vbCrLf) 
    ''# Specifies message and sends Ctrl+z 
    serialport.WriteLine(TextBox1.Text & Chr(26)) 
    ''# Displays buffer containing output messages 
    System.Threading.Thread.Sleep(2000) ''# CurrentThread.Sleep(2000) 
    MsgBox(serialport.ReadExisting) 
    serialport.Close() 
    MessageBox.Show("OK") 

    Catch ex As Exception 
    MessageBox.Show(ex.Message) 
    End Try 
End Sub 

Gracias de antemano por su ayuda.

+0

¿Qué está conectado a su puerto serie? – cjk

+0

Espero que sea un teléfono :) – samjudson

Respuesta

2

No tengo experiencia en escribir SMS, pero parece que está llamando a serialPort.WriteLine y agregando vbCrLf al final de la línea.

En segundo lugar, ¿está seguro de que es vbCrLf lo que desea? Algunas cosas que he visto simplemente se refieren a 'Retorno de carro' - que sería vbCr.

+0

Buen lugar, WriteLine agregará automáticamente el terminador de línea correcto para el medio ambiente – cjk

1

Me tropecé con Microsoft SMS Sender hace un tiempo y puede que te ayude. Sin embargo, nunca lo usé ...

0

+ CMS ERROR 500 se expande (normalmente) como un "Error desconocido". Desde el módem GSM de AT documentación comando:


If sending fails, for example, if a message is too long, the result code depends on the current setting of the AT^SM20 command:

If the AT^SM20 equals 1 (factory default) any failure to send a message is responded with "OK". Users should be aware, that despite the "OK" response, the message will not be sent to the subscriber.

If the AT^SM20 equals 0 any failure to send a message is responded with "ERROR". • If sending fails due to timeout, then AT^SM20 =1 causes "+CMS ERROR: Unknown error" to be returned;
AT^SM20 =0 causes "+CMS ERROR: timer expired" to be returned.


Posiblemente que pueda estar teniendo problemas de tiempo de espera/conexión. Tal vez compruebe que su módem/teléfono se haya registrado correctamente con el servicio, es decir, verifique la respuesta a AT + COPS. y AT + CREG? comandos.

Cuestiones relacionadas