LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Send SMS using AT command in LabWindows?

I managed to call..using the ATD command but now I am having problems in sending a SMS message..

 

In hyperterminal the commands are the following:

 

AT+CMGF=1 \r

AT+CMGW="0040766562692" \r

The GSM / GPRS modem will then return a prompt "> " and you can start typing the SMS text message.

>Have a nice day.

When finished, press Ctrl+z of the keyboard.

 

Here is what I tried to do...but nothing happens:

 

int commandSendSMS()


      char bW1[100];

      Fmt(bW1,"%s","AT+CMGF=1\r");
   ComWrt(4, bW1, 10);
  
   Fmt(bW1,"%s","AT+CMGW=\"0040766562692\"\r");
   ComWrt(4, bW1, 25);
 
   Fmt(bW1,"%s","Have a nice day.\032" );  

   ComWrt(4, bW1, 18);
 
      return 0;
}

 

I use \032 to replace <ctrl+z> is that correct?

What am I doing wrong...please help!

 

 

0 Kudos
Message 1 of 10
(5,727 Views)

Just a guess: you possibly are missing to wait for the return prompt from the modem. This prompt can imply that the modem has executed some command / initialization and is ready to send the sms.

How much time do you wait in hyperterminal for the prompt to appear? Try adding a similar Delay.

 

BTW I don't understand why you are using Fmt command instead of some simple strcpy...

And also, you can use strlen command embedded in ComWrt to avoid manual count of letters, since you have no null characters in the string to send: ComWrt (4, bW1, strlen (bW1));

This will avoid sending some unwanted extra character (your count for the first string is correct, while the following instructions both send 1 byte more than the string).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(5,720 Views)

Dear Roberto,

 

I tried and put the delay, but didn`t work.

In hyperterminal after the CTRL+Z command the modem result is:

+CMGW: 1  

 

OK

- 1 is the ref number assigned to the text message...and then i have to send the text message with :

AT+CMSS=1

 

I tried to use this and it worked, but i don`t know how to see the ref number (the result +CMGW: 1) because the result can differ on every execution.

 

How can I read every result from the modem after sending AT commands?

 

Thanks,

  Annes

0 Kudos
Message 3 of 10
(5,674 Views)

Ok, the situation seems to be a bit more clear now. Here what I would do, using GetInQLen and ComRd to test answers from the modem:

 

   char   bW1[64], msg[512];

 

   // Send first part of the commands

   strcpy (bW1, "AT+CMGF=1\r");
   ComWrt (4, bW1, strlen (bW1));
   Delay (0.1);
   strcpy (bW1, "AT+CMGW=\"0040766562692\"\r");
   ComWrt (4, bW1, strlen (bW1));
   Delay (0.1);

 

   // Test for answer from the modem

   ComRd (4, msg, GetInQLen (4));

   if (!strlen (msg) || strcmp (msg, "> ")) {

      MessagePopup ("Error", "No answer from the modem or incorrect answer!");

      goto Error;

   }
  
   // Send SMS text to the modem

   strcpy (bW1, "Have a nice day.\032" );  

   ComWrt (4, bW1, strlen (bW1));

   Delay (0.1);

 

   // Test for answer from the modem

   ComRd (4, msg, GetInQLen (4));

   if (!strlen (msg) || strncmp (msg, "+CMGW", 5)) {

      MessagePopup ("Error", "No answer from the modem or incorrrect answer!");

      goto Error;

   }

 

   // Find ref number and issue the command to actually send the message

   Scan (msg, "%s[dtzz]%d", &x);   // substitute 'zz' with ASCII code for ':'

   sprintf (bW1, "AT+CMSS=%d\r", x);

   ComWrt (4, bW1, strlen (bW1));

 

I wrote this code from memory: please double check and complete it before running it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 10
(5,660 Views)

I used this:

 

int AT()
{
 
 char bufferWrite[20]  ;
 char mesaj[512];
// Fmt(bufferWrite,"%s","AT\r");
  strcpy(bufferWrite,"AT\r");
 ComWrt(number_port, bufferWrite, strlen(bufferWrite));
 
  Delay(10.5);
  
  ComRd(number_port,mesaj,GetInQLen(number_port)); // OK
  printf("%s\n",mesaj);
 
 
  getchar();
 return 0;
}

- the modem must return ok but he returns:

à{~h┬¡ïh♦

 

I attached all my code...in a text file

 

 

 

0 Kudos
Message 5 of 10
(5,640 Views)

Hi Annees, sorry for this late response, I missed your message somehow...

 

By looking at your code I have found nothing really raising a warning to me. I was a little puzzled by your InputQueueSize = 0 in OpenComConfig but according to the documentation the driver should translate it into a 512 byte buffer. In the same command, it is not necessary at all to enter the device name, so I would pass an empty string in that parameter to avoid any possible conflict with the driver.

 

Just to be sure, you are using the same port and cable both with Hyperterminal and with CVI, right? Also, 10 secs should be enough for any modem to respond: did you choose this value based on your tests with Hyperterminal? Can the modem be slower in responding?

 

If the response is not correct this may depend either in the serial channel being disturbed or on no response received from the modem and you are printing garbage left in the buffer while declaring it. Try accomodating all parameters to a known value before using them and printing some more data to follow command execution. That is:

 

   int    r;

  char bufferWrite[20];
  char mesaj[512] = { 0 };


  strcpy (bufferWrite, "AT\r");
  ComWrt (number_port, bufferWrite, strlen (bufferWrite));
 
  Delay (10.5);
  

  r = GetInQLen(number_port);

  ComRd (number_port, mesaj, r); // OK
  DebugPrintf ("%d: %s\n", r, r > 0 ? mesaj : "-");

 

Finally, can you issue some command to the modem that you can monitor without need to see its response? Say some command the turns on/off the lights in the front panel of the modem or something similar. This may permit to detect wether there is a problem in sending commands or receiving answers.

 

These are very general suggestions that are common while dealing with external devices: they can help you in narrowing down the problems so that you can find the correct solution.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 10
(5,598 Views)

I use the same cable and port with Hyperterminal and with CVI.

The modem respondes to a command in less than 10 seconds. As an example when I run the ATDxxxxxxxxx; command to call a phone number he responds (calls the number) in 6 - 8 seconds.

I already tried to accomodate the values to a known value..I accomodated them to value 0. 

 

After I send the command AT \r , GetOutQLen() returns 3 but GetInQLen() returns 0 when in fact it should return 2 because the modem result must be OK.

0 Kudos
Message 7 of 10
(5,591 Views)

> After I send the command AT \r , GetOutQLen() returns 3

Does GetOutQLen ever returns to 0? You can test it by adding a small loop that terminates on this event. If the loop never ends you may have to add some element to the communication (e.g. handhaking, which is disabled by default and you have explicitly confirmed as disabled in configurePort () function). You can search in Hyperterminal and / or windows modem configuration to check whether it is using handshaking or not.

 

> GetInQLen() returns 0 when in fact it should return 2 because the modem result must be OK.

It could possibly return 3 since the modem itself may add a CR at the and of his messages. In every case it must answer something (provided the preceding step goes to end)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 10
(5,585 Views)

GetOutQLen() returns 0. 

 

I gave my code to a friend who runned it on his computer with a Siemens C35. The code worked. I don`t know why on the FASTRACK SUPREME 20 that I have it doesn`t!..

 

I just want to be able to read the result of the modem.

 

I will attach my code again maybe someone can help!

 

I also have some problems with the Hyperterminal.

At the beginning it worked fine and now doesn`t work anymore.

I can`t see what I write or read the answers. I tried to put the eco lines but still doesn`t work. 

 

Still when I run in Labwindows the ATD command and call a phone number it works.

 

0 Kudos
Message 9 of 10
(5,523 Views)

Well, if you have problems in HyperTerminal you may have misspelled some command: take another look at the documentation for AT commands your modem can handle.

 

Maybe you could try some testing on commandw that execute correctly. Which are the responses in your AT () function? You say that you are able to phone a number: does the modem answer something when you execute these commands in HT? Are you able to read modem answers when doing it in CVI?

 

As a last resort, can your friend test the software with your modem?

 

 

BTW I suggest you to use DebugPrintf instead or printf: the debug output window keeps its contents when the program has terminated, while standard I/O window doesn't. Additionally, DebugPrintf commands are automatically not executed in release compiled application, so you don't need to revise your program to comment out those lines before compiling.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 10
(5,503 Views)