0

I wrote this code (using the Code::Blocks IDE) in which I want to send a message for a GSM to my mobile. It includes some AT commands.

The problem is that I have this error in the printf with the AT command "at+cmgf=1". I think that my code is correct. Is there a problem with UTF or the ASCII?

#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitions


int open_port(void)
{
    int fd; // File description for the serial port

    fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);

    if(fd == -1) // If open is unsucessful
    {
        printf("open_port: Unable to open /dev/ttyAMA0. \n");
    }
    else
    {
        fcntl(fd, F_SETFL, 0);
        printf("port is open.\n");
    }

    return(fd);
 } //open_port

int configure_port(int fd) // Configure the port
{
    struct termios port_settings; // Structure to store the port settings in

    cfsetispeed(&port_settings, B9600); // Set baud rates
    cfsetospeed(&port_settings, B9600);

    port_settings.c_cflag &= ~PARENB;   // Set no parity, stop bits, data bits
    port_settings.c_cflag &= ~CSTOPB;
    port_settings.c_cflag &= ~CSIZE;
    port_settings.c_cflag |= CS8;

    tcsetattr(fd, TCSANOW, &port_settings); // Apply the settings to the port
    return(fd);
}

void init_gsm()
{
    printf("at+cmgf=1\r\n");
    printf("at+cmgs=\"60*****\"\r\n");
    printf("Hello\r\n%c", 26);
}

int main(void)
{
    int fd = open_port();
    configure_port(fd);
    //query_modem(fd);
    init_gsm();
    return(0);
} //main
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dali1985
  • 3,263
  • 13
  • 49
  • 68
  • 1
    The code posted does not have that error, could you post the **exact** code from the editor? – Jesse Good May 20 '13 at 12:12
  • The code as posted does not contain ***any*** of the common stray characters (using regular expression `\x{00A0}|\x{00AB}|\x{00BB}|\x{2003}|\x{2009}|\x{200B}|\x{200C}|\x{FEFF}|\x{2013}|\x{2014}|\x{2029}|\x{201C}|\x{201D}|\x{2060}|\x{2212}|\x{00E4}|\x{FFFC}|\x{FFFD}|\x{2217}|\x{200C}|\x{202B}|\x{202A}|\x{FF1A}|\x{21B5}` - that is for NO-BREAK SPACE, ZERO WIDTH SPACE, ZERO WIDTH NON-JOINER, ZERO WIDTH NO-BREAK SPACE, EN DASH, EM DASH, LEFT DOUBLE QUOTATION MARK, RIGHT DOUBLE QUOTATION MARK, MINUS SIGN, LATIN SMALL LETTER A WITH DIAERESIS, OBJECT REPLACEMENT CHARACTER, REPLACEMENT CHARACTER, etc) – Peter Mortensen May 03 '23 at 18:31
  • A hex dump is likely to reveal that all bytes are less than 128. – Peter Mortensen May 03 '23 at 18:33
  • Stray errors are ***very*** common errors when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen May 03 '23 at 18:46

1 Answers1

1

The problem with stray '\302' is that the code contains a non-break-space instead of a normal space somewhere.

However fixing that, I see two additional problems which I address here.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165