gfernandes
gfernandes

Reputation: 1166

Sending ctrl-z to serial port in C (GSM SMS)

I have written a code to send data to serial port /dev/ttyACM0. Basically this is used with the GSM modem to send an SMS. The AT command to set the sms in memory and send it are

First I need to write the following in serial port "AT+CMGW=16\r"

Then write the following pdu converted message 069110090000F111000A9210299232900000AA03C8F40F and then send ctrl-z

I have issues with sending ctrl-z

say message = "069110090000F111000A9210299232900000AA03C8F40F" I have tried

strcat(message,"\x1A"); //Does not work
strcat(message,"\032"); //Does not work

I have even tried my hand at a function which adds a char to char*

void append(char *s,char c)
{
   int len = strlen(s);
   s[len] = c;
   s[len+1] = '\0';
}

append(message, '\032'); //Does not work
append(message, '\x1A'); //Does not work

I need to read the receive buffer of the port to check for the count Example +CMGW:4

And then write AT+CMSS=3\r to send the message.

Typing the above AT commands on minicom sends the SMS. But in C code I just cannot type ctrl-z.

Does anyone know how to go about it?

Any help is appreciated Thank you

Upvotes: 1

Views: 4811

Answers (1)

gfernandes
gfernandes

Reputation: 1166

Well, It was my mistake. I generalized the size of the data sent to the serial port. I think since the sent size defined was larger, the values following the ctrl-z hex value 0x1A were garbage values. So my command could not save the sms in memory as it did not know the values following 0x1A meant. To solve this I used strlen to send the real size of the char * sent to the serial port.

Upvotes: 1

Related Questions