2

I have a GPRS shield connected to an arduino uno board, i want to use the shield to send sms and do phone calls, from a C# Wpf application, the arduino is connected to the application using the serial port,

In order to do that I've upload the following sketch to the arduino board:

#include <SoftwareSerial.h> 

SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array 
void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.     
}

void loop()
{
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    while(GPRS.available())          // reading data into char array 
    {
      buffer[count++]=GPRS.read();    
      if(count == 64)break;
    }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero 
  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    GPRS.write(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  
}

every thing works perfectly when sending AT commands to the shield using the Serial Monitor, for example to dial a call this is all what i need to do

ATD Command

this works perfectly, but when trying to do the same thing from c# application, nothing happened ! here how i send the AT command from the code :

private readonly SerialPort _serialPort;
public void Callphone(string number)
{
    _serialPort.Open();
    _serialPort.Write("ATD + +" + number +";");
    Thread.Sleep(100);
    _serialPort.Close();
}

PS: sending sms works fine from the serial port, using the same way :

 public void SendSms(string number, string message)
    {
        _serialPort.Open();
        _serialPort.Write("AT+CMGF=1\r");
        Thread.Sleep(SleepTimeStamp);
        _serialPort.Write("AT+CSCA=\"" + MessageCenterNumber + "\"\r");
        Thread.Sleep(SleepTimeStamp);
        _serialPort.Write("AT+CMGS=\"" + number + "\"\r");
        Thread.Sleep(SleepTimeStamp);
        _serialPort.Write(message + "\x1A");

        Thread.Sleep(SleepTimeStamp);
        _serialPort.Close();
    }

Am i missing something ?

  • I dont't know much about C# but I have some ideas. And as noone answered. Let's try! ;-) 1st) I saw that you append \r in the working example. But you did not in Callphone. 2nd) what is the content of your number string? Is is prepended with a +? Then you write ATD + ++<number> to the shield. 3rd) In the working example you send a lot of text compared to the Callphone. Perhaps you have to flush the buffer. – Peter Paul Kiefer Oct 16 '15 at 16:55
  • 1
    Let the arduino send your string to your terminal and verify that it's 100% right. Much like a loopback. (Also, you don't really need an arduino inbetween?) – Paul Oct 16 '15 at 17:26
  • Thank you guys for your time, @Peter Paul Kiefer I've tried all you suggestions 1) adding the \r didn't solve the problem, 2)I've verified on debug mode no extra '+' is sent, I've even tried sending "ATD + +213698629552" directly without using a param, 3) each time the buffer is flushed, and i am also triggering the call only (no sms send code is executed first ), Thanks again and do you have anything else i can try ? – ELH Oct 16 '15 at 20:11
  • 1
    @FuaZe He uses an arduino shield, so I think the arduino is nessecary ;-)! It's a good Idea to echo the sended command, to see if a part of the command would be removed. @SamTheDev When you send the ATD command directly without a parameter, did you forget the ; at the end in your code too or is it just a typo in you comment? Another idea: When you communicated with the shield using the arduino terminal, you send a single AT command at first. Did you do that in your C# program too? I don't know If it is nessecary but it's the only difference I see. – Peter Paul Kiefer Oct 17 '15 at 10:20
  • Using an UART-USB cable/chip you can send commands directly to and from the GSM module. Though you will have to power it with an external supply (which you always should). Doing so will enable you to play around with the different AT commands and responses before you're programming it out (so that the arduino will send those). – Paul Oct 19 '15 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.