Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Lazarus, FreePascal, Kylix, etc. (https://www.clubdelphi.com/foros/forumdisplay.php?f=14)
-   -   Ayuda para enviar SMS con TSdpoSerial (https://www.clubdelphi.com/foros/showthread.php?t=74331)

martinartaza 13-06-2011 01:36:10

Ayuda para enviar SMS con TSdpoSerial
 
Hola que tal, querido foro, estoy tratando de enviar un SMS usando el componente TSdpoSerial (en lazarus, no se si viene para delphi). En fin, conecto correctamente mi celular Motorola V360, me aparece en windows como un Moden conectado al puerto Com3, entro al hyperterminal y escribo la siguiente secuencia de comandos:

AT(enter)
Me responde OK

O sea todo bien, ahora preparo para mandar SMS, todo desde hyperterminal.

AT+CMGS="381XXXXXX"(enter)
Me aparece >
>(pongo el mensaje) y enter
>(mando la convinación ctrl+Z)

Y desde hyperterminal, me sale ok y en instante mi celular manda el mensaje.

Ahora en delphi, programa un aplicación, para poner el codigo de area, el numero y el mensaje. y en el evento onclick del un boton enviar, pongo el siguiente código (que es donde necesito ayuda).

Código Delphi [-]
procedure TForm1.BEnviarClick(Sender: TObject);
var
strnumero:string;
begin
  SdpCel.Active:= True;
  strnumero:= EArea.text + ENumero.text;
  //agregar al final ctrl+z (ascii 26)
  SdpCel.WriteData('AT+CMGS="' + strnumero +'"' + #13);
  SdpCel.WriteData(MMensaje.Text + #13);
  SdpCel.WriteData(#26);
end;

En el evento onreaddata pongo lo siguiente, y me sale un tonelada de errores.

Código Delphi [-]
procedure TForm1.SdpCelRxData(Sender: TObject);
var rec: string;
begin
  rec:= SdpCel.ReadData;
   if (rec = 'OK') then ShowMessage('Mensaje enviado correctamente')
   else ShowMessage('Error: ' + rec);
end;

Deberia aparecerme un ">" pero no lo hace, tampoco me aparece OK.

Bueno el tema es que no se que estoy haciendo mal, tal vez deba enviar en un solo saque algo así.

Código Delphi [-]
procedure TForm1.BEnviarClick(Sender: TObject);
var
strnumero:string;
begin
  SdpCel.Active:= True;
  strnumero:= EArea.text + ENumero.text;
  //agregar al final ctrl+z (ascii 26)
  SdpCel.WriteData('AT+CMGS="' + strnumero +'"' + #13 + MMensaje.Text + #13 + #26);
end;

Bueno, desde ya muchas gracias y al que le interese esta es una manera que la aplicación mande mensaje espero que le sirva a alguien.

Nota: Eh buscado en el foro y no encontré al respecto, con este componente.

duilioisola 13-06-2011 20:36:51

Quizás tengas que esperar un ">" después de cada línea que envías.

Código Delphi [-]
procedure TForm1.BEnviarClick(Sender: TObject);
var
  strnumero:string;
  rec: string;
begin
  SdpCel.Active:= True;
  strnumero:= EArea.text + ENumero.text;
  //agregar al final ctrl+z (ascii 26)

  SdpCel.WriteData('AT+CMGS="' + strnumero +'"' + #13);
  // Si recibio el comando con el nro. de telefono debe responder ">". 
  rec:= SdpCel.ReadData;
  if (rec <> '>') then
     raise exception "ERROR enviando primera linea. "+rec

  SdpCel.WriteData(MMensaje.Text + #13);
  // Si recibio el texto del mensaje debe responder ">". 
  rec:= SdpCel.ReadData;
  if (rec <> '>') then
     raise exception "ERROR enviando segunda linea. "+rec

  SdpCel.WriteData(#26);
  // Aqui no se si se espera un ">" o un "Ok"
  rec:= SdpCel.ReadData;
  if (rec <> '>') then
     raise exception "ERROR enviando tercera linea. "+rec

  rec:= SdpCel.ReadData;
  if (UpperCase(rec) = 'OK') then 
     ShowMessage('Mensaje enviado correctamente')
end;

martinartaza 14-06-2011 14:45:30

Si llegue a esa conclución.
 
Si duilioisola, debo esperar el ">" pero además hay darle tiempo con un sleep(1000), ayer quise probarlo, pero no tenia crédito, hoy a la tarde lo pruebo.

Muchas gracias.


La franja horaria es GMT +2. Ahora son las 20:39:10.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi